question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling of browser crash

See original GitHub issue

It’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:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
Jaccccccccccccccccccccccccccccckcommented, May 9, 2018

class PuppeteerService {

constructor (){
    let createBrowser = async () => {
        console.log('Launching browser...');
        this.browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
        this.browser.on("disconnected", createBrowser);
        console.log('Init...Done');
    }

    (async () => {
        await createBrowser();
    })();
}

} 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.

7reactions
drmrbrewercommented, Jan 4, 2018

@aslushnikov so is the following a reasonable way of recovering from a crash?

this.browser = await puppeteer.launch(launchOptions);
var self = this;
browser.on('disconnected', async () => {
    self.browser = await puppeteer.launch(launchOptions);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

9 Ways to Get Chrome to Stop Crashing - Nira
Additionally, web browsers don't simply display static content. Chrome browser is more or less an operating system in itself, capable of running all...
Read more >
Handling exceptions and browser crashes in Selenium
Handling exceptions and browser crashes in Selenium · Part 1 — Run a Python Selenium web scraper on AWS Fargate · Part 2...
Read more >
Troubleshoot Chrome crashes - Google Support
Crashing issues with Chrome or a ChromeOS device can be caused a number of things. Here are some potential issues you might encounter:...
Read more >
Why Browser Crashes and How to Fix More effectively?
Here we can take Maxthon5 browser as an example, sharing some helpful tips from Maxthon engineers about browser crash. The blog today will...
Read more >
Preparing for support calls for browser crashes - Microsoft Learn
To solve a process crash, we always require the same data. If an application's code encounters an exception that is not handled, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found