Search code examples
automated-testspuppeteer

How to use chrome profile in puppeteer


I am unable to use specific profile in Puppeteer. It always open the chrome as a new user.

For example: I have 3 profiles for my chrome. Following is the code I am using to open chrome in specific profile:

const browser = await puppeteer.launch({
    headless: false,
    executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
    // args: ['--profile-directory="Profile 1"'],
    userDataDir:"C:\\Users\\USER_NAME\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1"
  });

But it always open the chrome as "Current user" profile.


Solution

  • Try below code:

    const browser = await puppeteer.launch({headless:false, args:[
    '--user-data-dir=/user/data/directory/profile_n']
    });
    

    Full explanation is given here:

    In Puppeteer how to switch to chrome window from default profile to desired profile