小编fra*_*nco的帖子

Puppeteer 有时会抛出“UnhandledPromiseRejectionWarning:TimeoutError:导航超时超出”

我正在使用 Puppeteer 测试 Headless Chrome,因此我阅读了文档并运行了以下代码*:

const puppeteer = require('puppeteer');

(async() => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.github.com', {waitUntil: 'networkidle2'});
    await page.screenshot({ path: 'screenshot.png' });

    await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)

(*来自Docs-Usage的片段)。

我更改了“example.com”,因为工作正常并尝试与其他站点一起使用,但使用“github.com”脚本会在行中返回超时异常await page.goto()

(node:7840) UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
    at Promise.then (C:\_test\headless\node_modules\puppeteer\lib\LifecycleWatcher.js:142:21)
    at <anonymous>
  -- ASYNC --
    at Frame.<anonymous> (C:\_test\headless\node_modules\puppeteer\lib\helper.js:111:15)
    at Page.goto (C:\_test\headless\node_modules\puppeteer\lib\Page.js:629:49)
    at Page.<anonymous> (C:\_test\headless\node_modules\puppeteer\lib\helper.js:112:23)
    at C:\_test\headless\index.js:7:16
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:7840) UnhandledPromiseRejectionWarning: Unhandled promise rejection. …
Run Code Online (Sandbox Code Playgroud)

javascript node.js puppeteer

2
推荐指数
1
解决办法
5774
查看次数

标签 统计

javascript ×1

node.js ×1

puppeteer ×1