木偶师在尝试截取任何网页的屏幕截图时总是超时



这是我的代码:

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://google.com/');
  await page.screenshot({path: 'example.png'});
  await browser.close();
})();

无论我尝试截图哪个网站,我总是收到以下错误:

(node:9548) UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded

我正在运行节点版本 8.16.0。我不知道为什么我总是得到这个超时。任何帮助,不胜感激。

编辑:

当我在关闭无头模式的情况下运行它时,它似乎确实有效,但我需要它作为无头浏览器运行。

尝试增加导航超时:

await page.goto('https://google.com/', { waitUntil: 'load', timeout: 50000 });

并添加try/catch

try {
 await page.goto('https://google.com/', { waitUntil: 'load', timeout: 50000 });
} catch(e) {
  console.log('Error--->', e);
}

最新更新