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
Closing the browser when last page is closed sometimes throws an error #2269
Comments
+1 |
Did a bit of quick debugging, the I can think of ways to fix it - eg wait for a |
Thanks @MJPA for the investigation. The issue comes from the fact that In the following example, I'd expect const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const [page] = await browser.pages();
browser.on('targetdestroyed', async () => console.log('Target destroyed. Pages count: ' + (await browser.pages()).length));
console.log('closing page...');
await page.close();
console.log('page closed.');
await browser.close();
})(); The output:
@JoelEinbinder what do you think? |
Same issue as @MJPA await page.waitForSelector('aside.aside a[href="/checkout"]')
.then(() => {
logMessage('Checkout is available');
})
.catch(err => {
log('Checkout not available');
success = false;
browser.close();
});
// click checkout button
await Promise.all([
page.click('aside.aside a[href="/checkout"]'),
page.waitForNavigation()
]); In this case, always same errors occurred. Maybe this puppeteer error. |
I get the same error with a slightly similar implementation, but through listening to the
I guess this sort of makes sense, since the event is called
The moral of the story seems to be there is no 100% guaranteed method of knowing when a browser is safe to close (without having to catch the exception). Please let me know if I'm missing something. |
Possibly related to #3423? |
I get this after closing all tabs in a browser and then attempting to open a new page |
This would break the code in the above example. The last page closed, brower.pages().length would be 1, the browser would not be closed. Then no more target destroyed events would come and the browser would live forever. I'd say this is user error, although it is subtle. Any calls to If there are no user controlled pages, simply Promise.all all the page closes, then close the browser. There should be no need to listen to the If there are user controlled pages, then listen to the |
+1. I use puppeteer 1.14, with Chrome 73 (I don't use Chromium) async close_browser() {
for (let page of await this.browser.pages()) {
await page.close({
"runBeforeUnload": true
});
}
await this.browser.close();
} |
I added
|
i use promise and worked for me |
We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days. |
We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it! |
Tell us about your environment:
What steps will reproduce the problem?
What is the expected result?
What happens instead?
This does not happen every run but it happens every so often. It's entirely possible I'm doing something bad here!
The text was updated successfully, but these errors were encountered: