'Make Puppeteer use more cores

I'm not very knowledgeable about browser core usage but I've read that it only uses one core.

If I open 4 chromium, will it use 4 cores? It tested it and it does open 4 browsers but I can't tell if they are only using one core for all the browsers or one core for each browser.

const puppeteer = require('puppeteer')

const start = async function() {
    
    async function openBrowser() {
        const browser = await puppeteer.launch({headless: false,defaultViewport: {width: 1920,height: 1080}})
        const page = await browser.newPage()

        //A browser will close after 10 seconds
        setTimeout(()=> {browser.close()}, 10000)
    }
    
    setTimeout(() => openBrowser(), 3000)//Browser will open with 3 second intervals
    setTimeout(() => openBrowser(), 6000)//Browser will open with 3 second intervals
    setTimeout(() => openBrowser(), 9000)//Browser will open with 3 second intervals
    setTimeout(() => openBrowser(), 12000)//Browser will open with 3 second intervals
}

start()

I have 20 task and I want do 4 of them simultaneously.

I want to call 4 browsers at a time and do the task rather than calling 1 browser and doing 4 async function inside that browser to do the task which in theory will only use 1 core.

My code would look like this:

const puppeteer = require('puppeteer')

const start = async function(task) {
        const browser = await puppeteer.launch({headless: false,defaultViewport: {width: 1920,height: 1080}})
        const page = await browser.newPage();

        await page.goto('myURL')
        await page.click(task)        
}

start('task1')
start('task2')
start('task3')
start('task4')

Would someone push me to the right way to go about this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source