0
私はページ上のすべてのノードのスタイルをすべて取得しようとしていますが、CSS.getMatchedStylesForNode
をdevtool-protocolから使いたいですが、そのノードは1つのノードでしか動作しません。ノードの配列をループすると、コンソール(以下のコード)で多くの警告が表示され、何も返されません。私は間違っているの?puppeteerでdevtool-protocolですべてのスタイルを取得する
コンソールに警告:
(node:5724) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 11): Error: Protocol error (CSS.getMatchedStylesForNode): Target closed.
自分のコード
'use strict';
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await page._client.send('DOM.enable');
await page._client.send('CSS.enable');
const doc = await page._client.send('DOM.getDocument');
const nodes = await page._client.send('DOM.querySelectorAll', {
nodeId: doc.root.nodeId,
selector: '*'
});
const styleForSingleNode = await page._client.send('CSS.getMatchedStylesForNode', {nodeId: 3});
const stylesForNodes = nodes.nodeIds.map(async (id) => {
return await page._client.send('CSS.getMatchedStylesForNode', {nodeId: id});
});
console.log(JSON.stringify(stylesForNodes));
console.log(JSON.stringify(styleForSingleNode));
await browser.close();
})();
- 人形遣いバージョン:0.13.0
- プラットフォーム:ウィンドウ10
- ノード:8.9.3
順番に配列を反復してみてください。現在、すべてのノードの接続を同時に開きます。 – wOxxOm