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 the browser itself open so i dont have to login in each tab on every loop
so the browser remains open , tabs open and close
here is my simplified code , pleas ignore syntax erros
var global_browser = false ;
async function init_puppeteer( settings ) {
if(global_browser === false )
global_browser = await puppeteer.launch({headless: false , args:['--no-sandbox']});
for(var i = 0 ; i < settings.length ; i++ )
{
var setting = settings[i];
open_tab($setting);
}
}
async function open_tab( setting ){
const page = await global_browser.newPage();
// do stuff
page.close();
}
setInterval(function (){
init_puppeteer(settings)
}, 50000 );
here is the problem , sometimes browser crashes or it get closed for whatever reason but the global_browser
remains an object /instance of puppeteer ... of curse it wont work when i try open a tab with that instance , and i get something like
(node:5720) UnhandledPromiseRejectionWarning: Error: WebSocket is not open: readyState 3 (CLOSED)
here is my question , how can i check and make sure i have a working/open instance of puppeteer in global_browser
? so i can create a new instance and replace it if the previous one is closed
page.close();
in youropen_tab()
function. I think that's why it closes the browser. – Aby