14

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.

nbi
  • 1,276
  • 4
  • 16
  • 26

2 Answers2

22

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

Govinda
  • 582
  • 1
  • 5
  • 14
  • @nbi If this has solved your problem, then requesting you to kindly consider is as an Answer to your question. – Govinda Jun 04 '21 at 22:20
  • This answer works great to persist a profile across runs and doesn't require any UI operations – qwertzguy May 01 '23 at 06:35
1

Nowadays this should work with:

args: ['--profile-directory="Profile 1"'],
userDataDir:"C:\\Users\\USER_NAME\\AppData\\Local\\Google\\Chrome\\User Data"
loxx
  • 119
  • 4