'Using custom profiles with puppeteer

im trying to make puppeteer launch chrome with my existing profiles, when i use this code:

const browser = await puppeteer.launch({
    executablePath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
    headless: false,
    args: [],
    userDataDir: `C:\\Users\\anton\\AppData\\Local\\Google\\Chrome\\User Data\\${profile}`
})

It opens the instances without my profiles: this when its suppose to look like this.

My code:

    const profiles = {
    // "AntohaAlt1": "Profile 5",
    // "AntohaAlt2": "Profile 6",
    // "AntohaAlt3": "Profile 7",
    // "AntohaAlt4": "Profile 8",
    // "AntohaAlt5": "Profile 9",
    "AntohaAlt6": "Profile 11",
    "AntohaAlt7": "Profile 12",
    "AntohaAlt8": "Profile 13",
    "AntohaAlt9": "Profile 14",
    "AntohaAlt10": "Profile 15",
}

const puppeteer = require('puppeteer-core');

Object.values(profiles).forEach(async (profile) => {
    const browser = await puppeteer.launch({
        executablePath: "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe",
        headless: false,
        args: [],
        userDataDir: `C:\\Users\\anton\\AppData\\Local\\Google\\Chrome\\User Data\\${profile}`
    })
    const page = await browser.newPage()
    await page.goto("https://roblox.com");
    await page.waitForTimeout(5000);    
    await browser.close();
})

Dont question why i have so many profiles thanks.

Edit: Before you say anything i already looked at some of the other questions and it didnt work.



Solution 1:[1]

Try changing the const keyword before browser to var or let.

Also, print to the log the actual value of the userDataDir data.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Tal Angel