im trying to open multiple tabs in a single browser instance , after they\'re done i close the tabs and then re-opening those tabs every x seconds ... but i want to keep th
You can make a very simple function to know if the browser process was killed.
async function wasBrowserKilled(browser){
const procInfo = await browser.process();
return !!procInfo.signalCode; // null if browser is still running
}
We can use this here,
const browserKilled = await wasBrowserKilled(global_browser);
if(global_browser === false || browserKilled)
It will check if the browser was killed, otherwise it will replace it.
This is just one way out of many provided by the API.
This is the code I used to test this out, see how the output changes if I comment out the browser.close() section.
const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser => {
const page = await browser.newPage();
// comment out to keep browser open
await browser.close();
console.log({browserKilled: await wasBrowserKilled(browser)});
});
async function wasBrowserKilled(browser){
const procInfo = await browser.process();
return !!procInfo.signalCode;
}
Log here,
➜ puppeteer-xvfb git:(direct-script) ✗ node temp/interval_tab.js
{ browserKilled: true }
➜ puppeteer-xvfb git:(direct-script) ✗ node temp/interval_tab.js
{ browserKilled: false }
_
This is different than the event. I made this snippet specially to check the process for this specific question where you check and run it if you want.
Note that this will only produce result if the browser is crashed/closed somehow.