-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Browser not properly closing #1290
Labels
Comments
@gmetais, thanks for both reporting an issue and submitting a PR with a fix. Long time, no see 😉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @macbre, how are you?
While updating Phantomas, I noticed a behavior that doesn't properly close the headless browser and lets it run in background forever (or until timeout).
How to reproduce:
Run a test on a domain that doesn't exist, for example https://www.sdkjfhsklhdfhjhbj.com
Here is a minimalist script to reproduce:
Phantomas will fail but will not stop running. It will even start analysing the Chrome's error page instead.
To better view what I mean, you can switch the option
headless: "new"
byheadless: false
in lib/browser.js. The browser stays open until it reaches the timeout.Why is it failing?
The
Browser.prototype.close
function will try closing the page withawait this.page.close({ runBeforeUnload: true });
Puppeteer responds
Protocol error (Page.close): Not attached to an active page
.Phantomas goes directly to the catch function and skip the job of calling
this.browser.close()
.Error log:
Notice that the
Browser.close
puppeteer method is not called.How to fix:
My approach would be to duplicate the try/catch in
lib/browser.js
. One try/catch for page.close, then second try/catch for browser.close. Even if page.close() fails, the browser.close would still get called.I'll create a pull request, but don't hesitate to rewrite it if you know a better fix.
Related?
This issue could maybe explain #1288.
The text was updated successfully, but these errors were encountered: