question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page timeout due to script loading error/timeout

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:33 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
rudiedirkxcommented, Mar 6, 2020

In my case the goto timeout happens because of a forever-loading blocking resource (js or css). That’ll never trigger the page’s load or domcontentloaded. A bug in Puppeteer IMO, but whatever.

My fix (FINALLY!) is to do what Lighthouse does in its Driver: a Promise.race() for a custom ‘timeout’-ish. The shorter version I used:

const LOAD_FAIL = Math.random();
const sleep = options => new Promise(resolve => {
	options.timer = setTimeout(resolve, options.ms, options.result === undefined ? true : options.result);
});

const sleepOptions = {ms: TIMEOUT - 1000, result: LOAD_FAIL};
const response = await Promise.race([
	sleep(sleepOptions),
	page.goto(url, {timeout: TIMEOUT + 1000}),
]);
clearTimeout(sleepOptions.timer);
const success = response !== LOAD_FAIL;

The sleep() and page.goto() race. If it’s the timeout, the result is clearly a fail (LOAD_FAIL). Otherwise it’s whatever page.goto() returns. Like this, it doesn’t throw a TimeoutException, and the page is still queryable.

That was my issue. I don’t know all your semi-related issues.

2reactions
Paul-DScommented, Nov 13, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Script timeout - WebDriver - MDN Web Docs
The script timeout error is a WebDriver error that occurs when a script the user has provided did not complete before the session's...
Read more >
Can a timeout be initiated for script loading when the server is ...
I'm requesting a file via a script tag that times out after 21 seconds at which point the page tries to build without...
Read more >
11 Ways to Fix the ERR_CONNECTION_TIMED_OUT Error
Solution 9: Check the Maximum Execution Time ... A PHP script's maximum execution time is the maximum amount of time it can execute...
Read more >
Most common causes for Page load Timeout issues ... - Support
1. Webpage with Basic Authentication · 2. Local Web Application · 3. Page not available, Page not found or Server timed out.
Read more >
Page Load Timed-out Amount - New Relic Explorers Hub
I've been getting this timeout error lately on one of my Synthetics scripts. TimeoutError: Page load timed-out (unable to finish all network ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found