admin管理员组文章数量:1393326
I'm testing Headless Chrome with Puppeteer, so I've reading docs and running this code*:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('', {waitUntil: 'networkidle2'});
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
(*Snippet from Docs-Usage).
I changed "example" because works fine and trying with other sites, but with "github" script returns an timeout exception in the await page.goto()
line:
(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. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7840) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
If I go to github with my regular browser, connects in normal timing, so my internet connection is not an issue.
I've added the next line and code runs fine after two minutes:
page.setDefaultNavigationTimeout(0);
But if I set puppeteer.launch({headless:false})
the code runs perfect in just a few seconds
I'm runing my test under:
- Windows 7 Professional SP1
- Node 8.11.1
- Puppeteer 1.18.0
- Puppeteer Core 1.18.0
I'm testing Headless Chrome with Puppeteer, so I've reading docs and running this code*:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.github.', {waitUntil: 'networkidle2'});
await page.screenshot({ path: 'screenshot.png' });
await browser.close();
})();
(*Snippet from Docs-Usage).
I changed "example." because works fine and trying with other sites, but with "github." script returns an timeout exception in the await page.goto()
line:
(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. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7840) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
If I go to github. with my regular browser, connects in normal timing, so my internet connection is not an issue.
I've added the next line and code runs fine after two minutes:
page.setDefaultNavigationTimeout(0);
But if I set puppeteer.launch({headless:false})
the code runs perfect in just a few seconds
I'm runing my test under:
- Windows 7 Professional SP1
- Node 8.11.1
- Puppeteer 1.18.0
- Puppeteer Core 1.18.0
2 Answers
Reset to default 6I encountered the same issue but solved it by replacing
{waitUntil: 'networkidle2'}
with:
{waitUntil: 'domcontentloaded'}
More information here:
[https://github./puppeteer/puppeteer/issues/2482][1]
Just to add more information, some sites have a lot of content and so the page might not have loaded within the default timeout of 30 seconds. So do away with this, you can totally remove timeout by doing so:
await page.setDefaultNavigationTimeout(0)
So this can look like this:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0);
await page.goto('https://www.example./', {
waitUntil: 'networkidle2'
});
Sometimes servers do not respond to headless requests (puppeteer #2963).
To verify this, I'd try run the code in debug mode:
DEBUG=*session node your-test-file.js
本文标签:
版权声明:本文标题:javascript - Puppeteer throws "UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded" so 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744624421a2616232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论