Puppeteer parallel instances opens pages in one browser rather than separate browsers

Viewed 346

I originally wanted to launch a Puppeteer instance for each unique profile I had. I managed to figure this out but a new problem has come up. Basically, in one point of my script I tell the browser to close the tab and reopen a new one. It closes each tab in each individual browser fine but when I use await browser.newPage(); it sends all the new tabs to just one browser (which I'm guessing was the last browser opened) instead of staying in their respective browser.

const puppeteer = require('puppeteer-extra');
const fs = require('fs');

const botRun = async emailInfo => {
    browser = await puppeteer.launch({
        args: [],
        headless: false,
        ignoreHTTPSErrors: true,
        slowMo: 5,
    });
    const page = await browser.newPage();
    await page.waitForTimeout(2500)
    // do stuff with emailInfo
    await page.close(); // works fine - will close tab for each browser 
    await browser.newPage(); // suddenly sends all tabs to 1 browser
};

(async () => {
    const profile = JSON.parse(fs.readFileSync("./settings.json"));    
    await Promise.all(profile.map(({email}) => botRun(email)));
})();

settings.json looks like:

[
  {"email": "email1@gmail.com"},
  {"email": "email2@gmail.com"},
  {"email": "email3@gmail.com"}
]

enter image description here

Is there any workaround for this?

0 Answers
Related