是否可以使用Puppeteer加载chrome:// gpu?

时间:2019-02-05 00:32:41

标签: chromium puppeteer

我正在使用Puppeteer拍摄某些页面的屏幕截图。我想检查对GPU / WebGL的支持,但是当我使用 await page.goto("chrome://gpu") 时,出现此错误:

Error: Navigation failed because browser has disconnected!
    at CDPSession.LifecycleWatcher._eventListeners.helper.addEventListener (/app/node_modules/puppeteer/lib/LifecycleWatcher.js:47:107)
    at emitNone (events.js:106:13)
    at CDPSession.emit (events.js:208:7)
    at CDPSession._onClosed (/app/node_modules/puppeteer/lib/Connection.js:215:10)
    at Connection._onClose (/app/node_modules/puppeteer/lib/Connection.js:138:15)
    at WebSocketTransport._ws.addEventListener.event (/app/node_modules/puppeteer/lib/WebSocketTransport.js:45:22)
    at WebSocket.onClose (/app/node_modules/ws/lib/event-target.js:124:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/app/node_modules/ws/lib/websocket.js:180:10)
  -- ASYNC --
    at Frame.<anonymous> (/app/node_modules/puppeteer/lib/helper.js:108:27)
    at Page.goto (/app/node_modules/puppeteer/lib/Page.js:662:49)
    at Page.<anonymous> (/app/node_modules/puppeteer/lib/helper.js:109:23)
    at main (/app/index.js:21:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

如果我改用 await page.evaluate(() => window.location.href = "chrome://gpu") ,则该页面会在控制台中记录一条错误消息,提示说

  

不允许加载本地资源:chrome:// gpu /

有什么方法可以从Puppeteer加载GPU状态页面吗?

1 个答案:

答案 0 :(得分:0)

我无法在Windows 7 x64上使用最新的树梢木偶版复制:

'use strict';

const puppeteer = require('puppeteer');

(async function main() {
  try {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('chrome://gpu');

    const data = await page.evaluate(() =>
      [...document.querySelectorAll('h3')].map(({ innerText }) => innerText)
    );

    console.log(data);

    await browser.close();
  } catch (err) {
    console.error(err);
  }
})();

输出:

[ 'Graphics Feature Status',
  'Driver Bug Workarounds',
  'Problems Detected',
  'Version Information',
  'Driver Information',
  'Compositor Information',
  'GpuMemoryBuffers Status',
  'Display(s) Information',
  'Video Acceleration Information',
  'Diagnostics',
  'Driver Information for Hardware GPU',
  'Graphics Feature Status for Hardware GPU',
  'Driver Bug Workarounds for Hardware GPU',
  'Problems Detected for Hardware GPU',
  'Log Messages' ]