Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Passing userDataDir to Puppeteer does not access the correct saved logins as regular Chrome #10666

Closed
2 tasks
ianwieds opened this issue Jul 31, 2023 · 3 comments
Labels
bug disable-analyzer Disables the automatic workflow that tries to reproduce bug reports needs-feedback

Comments

@ianwieds
Copy link

ianwieds commented Jul 31, 2023

Minimal, reproducible example

const os = require('os');
const username = os.userInfo().username;
const workingExePath = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome';
const workingDataBaseDir = `/Users/${username}/Library/Application\ Support/Google/Chrome`

const browser = await puppeteer.launch({
  headless: false,
  executablePath: workingExePath, // supply the user-specific path here
  defaultViewport: {
    width: 1280,
    height: 720
  },
  userDataDir: workingDataBaseDir, // supply the user-specific path here

  args: [
    '--mute-audio', // this mutes the entire browser, not just one tab
    '--profile-directory=Default',
  ]
});

const page = await browser.newPage();
await page.goto('https://mail.google.com/mail/u/0/#inbox');

Error string

no error

Bug behavior

  • Flaky
  • PDF

Background

I want to use Puppeteer to control the same profile/session as my regular Chrome browser. Specifically, I would like the websites I have logged in to stay logged in when opening a new Puppeteer instance.

Expectation

Passing userDataDir to Puppeteer does not work as expected.

It should open the same session that I normally have access to when opening a non-Puppeteer-spawned Chrome and have all my saved logins so I don't have to login to websites using Puppeteer.

Reality

I am able to open a Puppeteer Chrome instance and the instance definitely has the bookmarks and profile picture and even the same tabs as a non-Puppeteer-spawned Chrome. The Puppeteer-spawned Chrome instance also has the "Chrome is being controlled by automated test software" message.

However, on the Puppeteer-spawned Chrome, I am not logged in any websites that I am normally on the non-Puppeteer-spawned Chrome browser. So it's like the cookies, storage, or whatever is not working properly or not being used by Puppeteer or something.

To see if I could have any more luck, I manually copied the userDataDir to /Users/${username}/Library/Application\ Support/Google/Chrome_ (just has an underscore at the end) and tried using this new folder with Puppeteer but it still does not work.

Puppeteer configuration file (if used)

No response

Puppeteer version

20.9.0

Node version

16.17.0

Package manager

npm

Package manager version

8.15.0

Operating system

macOS

@ianwieds ianwieds added the bug label Jul 31, 2023
@ianwieds ianwieds changed the title [Bug]: [Bug]: Passing userDataDir to Puppeteer does not work as expected Jul 31, 2023
@ianwieds ianwieds changed the title [Bug]: Passing userDataDir to Puppeteer does not work as expected [Bug]: Passing userDataDir to Puppeteer does not access the correct saved logins as regular Chrome Jul 31, 2023
@github-actions
Copy link

github-actions bot commented Jul 31, 2023

The issue has been labeled as confirmed by the automatic analyser.
Someone from the Puppeteer team will take a look soon!


Analyzer run

@Lightning00Blade Lightning00Blade added needs-feedback disable-analyzer Disables the automatic workflow that tries to reproduce bug reports and removed confirmed labels Aug 1, 2023
@jrandolf
Copy link
Contributor

jrandolf commented Aug 7, 2023

Could you trying ignoring default args and specifying your profile directory?

@OrKoN
Copy link
Collaborator

OrKoN commented Aug 10, 2023

Make sure that the user data dir is correct by running your standalone browser with the same explicit --user-data-dir and other parameters. I am unable to reproduce this behaviour:

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch({
  headless: false,
  defaultViewport: {
    width: 1280,
    height: 720
  },
  userDataDir: '/tmp/data-resused', // supply the user-specific path here
  executablePath: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
});

const page = await browser.newPage();
await page.goto('https://example.com');

Steps

  1. Run the script
  2. Modify local storage
  3. Restart and the data is still in the local storage.

which indicates that Puppeteer-launched browser successfully picks up user data dir from previous runs. It's very likely that your regular Chrome stores things in a different path.

@OrKoN OrKoN closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug disable-analyzer Disables the automatic workflow that tries to reproduce bug reports needs-feedback
Projects
None yet
Development

No branches or pull requests

4 participants