Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer opens an empty tab in non-headless mode

Tags:

When running puppeteer(last version from npm - 0.13.0) and passing args to

puppeteer.launch({ headless: false })

the chrome is opened with an empty page as a first tab and opens the actual page from the script in the second tab.

const page = await browser.newPage(); Is it an expected behavior? Or a bug?

like image 562
dre.dev Avatar asked Dec 10 '17 22:12

dre.dev


2 Answers

Yes that's expected behavior. It works exactly as opening a chrome browser. If you closed that first tab the browser will close just as using the chrome browser. There needs to be at least one tab open for the browser to remain open. If you use await browser.pages() upon launching the browser, that will return all the pages open currently, which should be 1 about:blank page.

like image 119
Bobby Singh Avatar answered Oct 07 '22 10:10

Bobby Singh


The solution is to use the existing tab/page (dont open a new one):

// launch the browser var browser = await puppeteer.launch({ headless: false });  // get existing tab/page (first item in the array) var [page] = await browser.pages();  // load barcode tracking website await page.goto('https://orcascan.com'); 
like image 42
John Doherty Avatar answered Oct 07 '22 10:10

John Doherty