Trouble Maintaining User Data Between Chrome and Chrome Canary with Puppeteer

124 Views Asked by At

I am facing an issue while using Puppeteer to maintain and switch user data between Google Chrome and Google Chrome Canary instances. My goal is to automate tasks in both browsers using the same user data.

Here's the problem in detail, using MacOS:

User Data Copy: I have successfully copied the user data directory from my main Chrome profile

/Users/customstandard/Library/Application Support/Google/Chrome/Profile 1

to

/Users/customstandard/Library/Application Support/Google/Chrome Canary/Profile 1

Puppeteer Launch Configuration:

const puppeteer = require('puppeteer-extra')
// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

const url = "https://www.urlwithpaywall.com";
const timeout = 5000;

puppeteer.launch({ 
    headless: false,
    executablePath: '/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary',
    userDataDir: "/Users/customstandard/Library/Application\ Support/Google/Chrome\ Canary/Profile\ 1",
 
}).then(async browser => {
    // Create a new page 
    const page = await browser.newPage();

    // Setting page view 
    await page.setViewport( { width: 1200, height: 1200, deviceScaleFactor: 1 } );

    // Go to the website
    await page.goto( url, { waitUntil: "domcontentloaded", timeout: timeout } );

    // Wait for security check 
    await page.waitForTimeout(timeout);

    // Take screenshot
    await page.screenshot({ path: "screenshot.jpg", fullPage: true });

    await browser.close();
});

Issue: Despite these efforts, it appears that Chrome Canary creates a "Default" subdirectory within the "Profile 1" directory when I execute my Puppeteer script. This behavior results in Puppeteer not using the user data I copied into the "Profile 1" directory. Instead, it seems to default to using the newly created "Default" subdirectory.

When I navigate to chrome://version is shows the following for the profile path:

/Users/customstandard/Library/Application Support/Google/Chrome Canary/Profile 1/Default

Expected Outcome: I expect Puppeteer to use the user data from the "Profile 1" directory in Chrome Canary as I specified in the userDataDir option.

Additional Notes: I've tried various approaches, including renaming the "Default" folder and specifying different paths in the userDataDir option, but the issue persists.

I am trying to follow the directions as defined here: https://www.youtube.com/watch?v=IXRkmqEYGZA&list=LL&index=4&t=11s and the associated code here: https://github.com/JayZeeDesign/Scrape-anything---Web-AI-agent/blob/master/screenshot.js

Versions:

  • puppeteer: 21.6.1,
  • puppeteer-extra: 3.3.6,
  • puppeteer-extra-plugin-stealth: 2.11.2
  • Chrome Canary: 122.0.6218.0
  • Chrome: 120.0.6099.129
  • MacOS: Sanoma 14.2.1 (Build 23C71)

Thank you in advance for your assistance!

1

There are 1 best solutions below

2
Md. Abu Taher On BEST ANSWER

First you have to ensure the chrome/chrome canary executable is not running. Afterwards, you can use the --profile-directory flag to ensure chrome loads the specific profile. This is because by default puppeteer uses Default as the profile name.

const browser = await puppeteer.launch({
    headless: false,
    ignoreHTTPSErrors: true,
    executablePath: "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
    userDataDir: '/Users/<username>/Library/Application Support/Google/Chrome/', // this is where all profiles are stored for chrome
    args: [
        '--profile-directory=Profile 1' //Select your profle here
    ]
  });