GoogleChrome / chrome-launcher

Launch Google Chrome with ease from node.
https://www.npmjs.com/package/chrome-launcher
Apache License 2.0
1.25k stars 189 forks source link

How to automate non-default profile dynamically? #172

Open VikramTiwari opened 5 years ago

VikramTiwari commented 5 years ago

If chrome is launched with Profile 1:

await launch({
  userDataDir: <PROFILE_NAME>, // `Profile 1`
})

Can we execute an event on Profile 2?

Maybe a better question is what kind of boundary is this profile boundary? I can launch with Profile 1, then manually switch profiles to Profile 2. If so, is there a way to do the same from code? Maybe something via devtools protocol?

paulirish commented 5 years ago

https://vanilla.aslushnikov.com/?Target.createBrowserContext is kinda similar but not

you currently can't dynamically change what profile is being used by chrome. or launch a new chrome window with a diff profile folder.

the chrome binary must be relaunched.

VikramTiwari commented 5 years ago

Follow up: Can I launch chrome binary with multiple profiles? And then switch between them. Assuming no.

paulirish commented 5 years ago

Can I launch chrome binary with multiple profiles

well.. you can use any user-data-dir. and a single user-data-dir can contain multiple profiles. but there is a default profile. and it will use that one.

and yah.. you can't change it (or open a new window using a diff one) using any automated way. the devtools protocol doesnt deal with stuff like that.

VikramTiwari commented 5 years ago

Ah! That's helpful. Thanks for the details @paulirish.

VikramTiwari commented 5 years ago

Hey @paulirish I was able to create a proof-of-concept that is able to run multiple profiles without relaunching the binary. Please take a look at this issue: https://github.com/GoogleChrome/puppeteer/issues/4966

LeMoussel commented 5 years ago

I am very interested in this POC

VikramTiwari commented 5 years ago

Hey @paulirish Were you able to reproduce this issue on your side as well? Let me know if there's something I am overlooking here.

VikramTiwari commented 4 years ago

Hey @paulirish Could we reopen the issue now that we have a working POC for this? Or should I open a new issue for this?

paulirish commented 4 years ago

POC https://gist.github.com/VikramTiwari/9fe97f990d17ada231dee35eea128480

key bit: --profile-directory='Profile 1'

paulirish commented 4 years ago

@VikramTiwari question on this.... why do you want to use secondary profiles? obviously both Lh and PPTR are happier if you just use the Default profile on separate userDataDirs.. is that too annoying for your usecase?

VikramTiwari commented 4 years ago

That's true. For my use-case however, I am trying to use PPTR on users's existing userDataDir (to get around auth etc). This causes challenge because we can't break user's existing chrome profiles functionality by cloning/moving directories etc. This makes sense?