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
Execution context was destroyed, most likely because of a navigation #3323
Comments
@THE-GAME-YOU-LOST this sounds bad. Can you share a snippet that would reproduce this? I'm mostly interested what API call produces this error for you. |
@aslushnikov I am doing something like shown in this snippet below: const returnSearchResults = async (page) => {
const pageSource = await page.content();
if (/An error happened/.test(pageSource)) {
return 'fail';
}
else if (/queries have been found/.test(pageSource)) {
return 'success';
}
else if (/Timed out/.test(pageSource)) {
return 'timeout';
}
else if (/Your searches are too fast/.test(pageSource)) {
return 'too_fast';
}
else {
return await returnSearchResults(page);
}
}
const searchStep = async (page) => {
await page.type('#searchbox input', 'Testing');
await page.click('button[name="search"]');
let searchResults = await returnSearchResults(page);
if(searchResults === 'success') {
console.log('success finding results');
} else {
console.log(searchResults);
}
}
(async() => {
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-accelerated-2d-canvas',
'--disable-gpu'
]
});
const page = await browser.newPage();
await page.goto('http://snippet.example.com/', {waitUntil: 'domcontentloaded'});
await searchStep(page).catch(e => {
console.log('step searchStep exception ' + e);
process.exit(1);
});
await page.close();
await browser.close();
})(); As you can see returnSearchResults is constantly called if no result is found. It fails on page.content() if there is a redirect, a expected result can be always one of them but only one redirects, which is the "too_fast" Also sorry if I do bad javascript approach, I am still beginning, thank you! |
@THE-GAME-YOU-LOST I see. The right thing to do would be to await navigation caused by |
Yes, it resolved the problem, thanks! |
@aslushnikov , I'm having the same issue when trying to open a page that has (probably?!) JavaScript redirection. The same code works for every other page that doesn't have JavaScript redirection. If I'm adding I don't know what selector or code causing the redirection. I also can't tell if a redirection happened from the Edit: |
I've just hit the same problem. If I hit a page which has a javascript redirect on it, with a normal page.goto, then I get a "Execution context was destroyed, most likely because of a navigation" error. If I add
then this sorts out the pages with javascript redirects on them. But then pages without javascript redirects offer me a navigation timeout error. It would be useful to have something like a followLocation: true flag on the page.goto options, so this is handled gracefully by Puppeteer. |
@tomgallagher @RebliNk17 do you guys know a URL where you want to land after the |
@aslushnikov , Yes. |
Mine are geolocation redirects so I probably can't usefully add anything. What I am doing now is catching the |
@RebliNk17 @tomgallagher well, yes, looks like we need something like #3627 |
Having the same issue with automatic redirects this is an example url http://ramdileo.com/mercado/ |
I've added the following code to
|
Hi, this is my code, hope it can have a little help to you
|
none of those things above work reliably for me. Either tests are way to slow, or fail with "Execution context was destroyed" Instead I would like to suggest something like:
where watcher.noNavigationOccuredPromise() would resolve if within noNavEvTimeout nothing happened, otherwise, if a navigation was triggered within noNavEvTimeout, watcher.noNavigationOccuredPromise() would do nothing and one of the other 3 would trigger as before, so if a navigation happened, page will be loaded normally. Also only if a navigation happened, it will wait a max of navigationTimeout(). |
alternative, working for me, without the need to change puppeteer:
|
I am getting the same error using Puppeteer "version": "1.13.0". Code sample:
} |
used @janbiedermann 's code. Just pointing out that I've used part of @xctest 's code too. Also applied ES6 patterns, removing var and function. Code: `
` Thank you guys, looks like it's working |
I have also got same problem as Execution context was destroyed, most likely because of a navigation. I have just increase wait time and it fine work . It happend mostly due to slow network. |
@THE-GAME-YOU-LOST dammit I just lost the game, and I've been winning for a solid decade. |
I'm using |
Thanks This Fix My Problem |
What steps will reproduce the problem?
I have a website with unpredictable behaviour when a form is submitted, it can show me a message or it redirects me to a page, so I am currently checking for some messages, either in the redirected page or in main.
What is the expected result?
When redirected still check for an expected message without throwing me error.
What happens instead?
But instead I get an error "Execution context was destroyed, most likely because of a navigation", I tried using waitForNavigation, it worked but only when I had the page redirected. So now I am constantly checking for some possible messages and sometimes I get this error.
The text was updated successfully, but these errors were encountered: