-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Page.reload() Destroys execution context on certain websites #10435
Comments
This issue was not reproducible. Please check that your example runs locally and the following:
Once the above checks are satisfied, please edit your issue with the changes and we will |
minimal repro:
|
@jrandolf could you please take a look? |
If you use The underlying problem here is that the @OrKoN I think we can solve this by mutexing the navigation. More precisely, we can do something like this in every navigation function: declare const mutex: Mutex;
let resolve;
const promise = new Promise(res => resolve = res);
void mutex.run(async () => {
// Run navigation code
// Wait for specified event to finish.
resolve();
// Wait for remaining events to finish.
});
return promise; I don't think we have another option since those navigation events cannot be "marked" (hence bucketed). |
I am not sure that would work as we also have networkidle events on the list of supported event that might take a long time to occur (possibly infinitely). If we do that, we basically turn every navigation into a Why are we trying to do something on the destroyed context here? I think we might need to think of some other solution. |
Actually the only event that may require waiting is
Because the reload finishes prematurely (see my above comment), the |
@jrandolf but |
so
|
In CDP it shows that Independent of this though, if you wait for both |
IMO the DOMContentLoaded almost always comes before the load (especially if the page has resources). It might be that Puppeteer inserts async handling when processing it? Do you have a CDP log for this goto/reload part? We can take a look offline together. |
A functional repro: import * as Puppeteer from "puppeteer";
const browser = await Puppeteer.launch({
ignoreHTTPSErrors: true,
headless: false,
devtools: true,
});
const page = await browser.newPage();
await page.goto("https://ilsole24ore.com", {
waitUntil: "load",
});
await page.reload();
const element = await page.evaluate(() => document); |
Bug expectation
We are trying to visit a webpage, reload it and query a selector.
On certain websites, a "Execution context was destroyed" error is thrown as soon as
$
query selector is used after the page reload.Bug behavior
Minimal, reproducible example
Error string
Error: Execution context was destroyed, most likely because of a navigation
Puppeteer configuration
No response
Puppeteer version
20.7.3
Node version
20.3.0
Package manager
npm
Package manager version
9.6.7
Operating system
macOS
The text was updated successfully, but these errors were encountered: