Handling of browser crash
See original GitHub issueIt’s not clear to me the relationship between Puppeteer, the browser, and the Chromium instance (process).
It seems from the docs here that puppeteer.launch()
launches a Chromium instance, which is associated with a browser
.
And then for browser.disconnect()
the docs say:
Disconnects Puppeteer from the browser, but leaves the Chromium process running. After calling disconnect, the browser object is considered disposed and cannot be used anymore.
Does the same happen when something causes the browser
to crash? Does the Chromium instance survive, but the browser
is no longer valid, so that you can restore things by reconnecting to the Chromium instance?
In other words, is the following the correct way to recover from a browser
crash, or should we use puppeteer.launch()
again instead? How do we tell if the Chromium instance is still working (so that we can reconnect to it)?
const browser = await puppeteer.launch(launchOptions);
this.browserWSEndpoint = browser.wsEndpoint(); // store for later
var self = this;
browser.on('disconnected', async () => {
self.browser = await puppeteer.connect({browserWSEndpoint: self.browserWSEndpoint});
});
The docs suggest to me that the above is correct for dealing with a browser crash, because here it says that the disconnected
event on the browser
is emitted when the “browser closed or crashed”.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:13 (3 by maintainers)
Top GitHub Comments
class PuppeteerService {
} const puppeteerService = new PuppeteerService();
@aslushnikov this way, I can always get a new browser use puppeteerService.browser. However,if crash, there will be a re-open time while which browser can not use.
@aslushnikov so is the following a reasonable way of recovering from a crash?