Issue with Puppeteer opening extra tabs
I’m having a weird problem with Puppeteer (version 0.13.0 from npm). When I run it in non-headless mode like this:
puppeteer.launch({ headless: false })
Chrome opens up, but it shows an empty tab first. Then it creates a second tab with the actual page I want.
I’m using this code to make a new page:
const page = await browser.newPage();
Is this normal? I thought it would just open one tab with my page. Anyone know if this is how it’s supposed to work or if it’s a bug in Puppeteer?
It’s kind of annoying because I end up with an extra blank tab every time. Any ideas on how to fix this or if I’m doing something wrong? Thanks for any help!
I’ve encountered this issue as well, and it’s actually by design. Puppeteer creates that initial blank tab as a sort of ‘control’ tab. It’s not a bug, but a feature meant to maintain consistency between headless and non-headless modes.
If it’s really bothering you, there’s a workaround. You can launch Chrome with the ‘–no-startup-window’ flag:
const browser = await puppeteer.launch({
headless: false,
args: ['--no-startup-window']
});
This prevents that initial blank tab from appearing. Just remember, you’ll need to create your first page manually after launch. It’s a bit more work, but it gives you a cleaner start if that’s what you’re after.
Hope this helps! Let me know if you need any more clarification on this.
hey dancingbird, i’ve seen this too. it’s normal behavior for puppeteer in non-headless mode. the first tab is like a placeholder. you could try browser.pages()
to get all pages and close the extra one if it bugs you. but honestly, i just ignore it most of the time. no biggie!
I’ve been working with Puppeteer extensively, and this behavior is indeed expected. The initial blank tab serves as a control tab for Puppeteer’s internal operations. While it might seem unnecessary, it actually helps maintain consistency across different browser configurations.
If you’re set on avoiding this extra tab, you could try using the ‘about:blank’ page for your operations instead of creating a new one. Here’s how:
const pages = await browser.pages();
const page = pages[0];
await page.goto('about:blank');
This approach utilizes the existing blank tab, potentially saving resources and keeping your browser instance cleaner. Just ensure you’re not accidentally closing this tab during your script execution, as it could disrupt Puppeteer’s functionality.