puppeteer: Page timeout due to script loading error/timeout
- Puppeteer version: 1.13 and 1.15
- Platform / OS version: Ubuntu 18.04
- URLs (if applicable): https://www.echt-susteren.nl/ and https://www.noordwijk.nl/
- Node.js version: v8.16.0
I use Puppeteer to check 360 sites for cookies. 358 of them work with a 9s timeout. 2 of them don’t work at all, not even with a 90s timeout.
Script:
const browser = await puppeteer.launch(/*{executablePath: '/usr/bin/chromium-browser'}*/);
const page = await browser.newPage();
try {
await page.goto(url, {timeout: 90000});
}
catch (ex) {
console.log(ex.constructor.name + ': ' + ex.message);
process.exit();
}
Only for those 2 URLs, it keeps crashing with TimeoutError: Navigation Timeout Exceeded: 90000ms exceeded
.
A separately installed chromium (via executablePath
) (73.0.3683.86
) doesn’t change anything.
I can’t see why it times out. Only that it times out. Can’t it connect? Is it loading too much? They work fine in my real (Windows) Chrome browser. The other 358 sites work fine too. Is there a more debug mode? A Network panel?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 34 (2 by maintainers)
In my case the
goto
timeout happens because of a forever-loading blocking resource (js or css). That’ll never trigger the page’sload
ordomcontentloaded
. A bug in Puppeteer IMO, but whatever.My fix (FINALLY!) is to do what Lighthouse does in its
Driver
: aPromise.race()
for a custom ‘timeout’-ish. The shorter version I used:The
sleep()
andpage.goto()
race. If it’s the timeout, the result is clearly a fail (LOAD_FAIL). Otherwise it’s whateverpage.goto()
returns. Like this, it doesn’t throw aTimeoutException
, and the page is still queryable.That was my issue. I don’t know all your semi-related issues.
Is the normal behavior of puppeteer not supposed to be the same as a “normal” browser ? In this case I think this issue should be reopen.
@sorxrob I found the solution. Just add to launch args - --enable-blink-features=HTMLImports
https://magpcss.org/ceforum/viewtopic.php?f=6&t=17412
Actually, chrome has a 1 minute timeout for pending requests, so the following works fine for me:
@kingiw I can’t reproduce your issue. On my machine it just work ok. Have you tried run this with proxy VPN? Maybe you are banned. The log should be longer.
You can try also this https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-stealth to imitate headfull Chrome. The implementation is just:
If I try on https://try-puppeteer.appspot.com/
it errors after a while:
because the entire page times out, instead of the 1 broken resource, so this entire page is unloadable. Not so in the real browser.
https://try-puppeteer.appspot.com/ doesn’t work either, for either URL. Same timeout (but after the default 30s).