I am running puppeteer with Chromium (v112) on a collection of websites. On some of the websites, i encounter the following error:
STDERR: Error: Navigation failed because browser has disconnected!
at new LifecycleWatcher (/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js:83:223)
at Frame.goto (/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Frame.js:183:25)
at CDPPage.goto (/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:438:91)
at /puppeteer/iframes.js:44:24
The iframe.js file with puppeteer options is:
const puppeteer = require('puppeteer');
const Xvfb = require('xvfb');
var args = process.argv; // node iframes.js site extn
(async () => {
var xvfb = new Xvfb({
silent: true,
reuse: true,
// xvfb_args: ["-screen", "0", '1280x720x24', "-ac"],
});
xvfb.start((err)=>{if (err) console.error(err)});
const browser = await puppeteer.launch({
headless: false,
ignoreDefaultArgs: ["--disable-extensions","--enable-automation"],
args: [
"--disable-gpu",
"--disable-dev-shm-usage",
"--no-sandbox",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-zygote",
"--single-process",
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process',
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process',
// `--load-extension=/home/ritik/work/pes/extensions/privacy_extn/${args[3]}`,
'--display='+xvfb._display
// '--single-process',
'--window-size=960,1080',
'--disable-features=AudioServiceOutOfProcess'
],
// executablePath: '/usr/bin/google-chrome'
executablePath: '/snap/bin/chromium'
});
const page = await browser.newPage();
await page.setViewport({ width: 960, height: 1080 });
await page.waitForTimeout(2000);
var sites = args[2].split(',');
for (let index=0; index<sites.length; index++){
let site = sites[index];
try{
await page.goto(site, { waitUntil: 'networkidle2', timeout: 60000 });
await page.waitForTimeout(2000);
} catch (error){
console.error(error);
console.log(site);
// continue;
break;
}
}
await browser.close();
xvfb.stop();
})();
The only relevant discussion I could find was this link but it doesn't resolve the error. Some of the sites I get the error on are: 'www.baidu.com', 'www.bilibili.com', 'www.microsoft.com', 'www.apple.com'
I was expecting the code to run normally without any error.