首页 > 解决方案 > Node.js puppeteer - 如何设置导航超时?

问题描述

我正在使用 node.js 和 puppeteer 来获取一些数据。我打开的一些文件非常大......然后我收到一个错误:

错误:

our error { TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
    at Promise.then (/project/node_modules/puppeteer/lib/NavigatorWatcher.js:74:21)
    at <anonymous> name: 'TimeoutError' }

如何忽略它或设置更高的超时时间?

那是我的脚本:

await page.goto('url'+tableCell04Val, {waitUntil: 'load'});

标签: javascriptnode.jspuppeteer

解决方案


timeout: 0如果您正在加载一个沉重的页面,您可以使用来禁用超时错误。

以你page.goto喜欢的方式使用它:

await page.goto('url'+tableCell04Val, {waitUntil: 'load', timeout: 0});

您可以在此处查看对 Pupeteer 所做的 PR,其中添加了更改,以及文档和实现它的单元测试。


推荐阅读