chrome-launcher icon indicating copy to clipboard operation
chrome-launcher copied to clipboard

How to automate non-default profile dynamically?

Open VikramTiwari opened this issue 5 years ago • 11 comments

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?

VikramTiwari avatar Sep 17 '19 18:09 VikramTiwari

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.

paulirish avatar Sep 17 '19 23:09 paulirish

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

VikramTiwari avatar Sep 18 '19 00:09 VikramTiwari

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.

paulirish avatar Sep 18 '19 04:09 paulirish

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

VikramTiwari avatar Sep 18 '19 17:09 VikramTiwari

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

VikramTiwari avatar Sep 23 '19 19:09 VikramTiwari

I am very interested in this POC

LeMoussel avatar Sep 24 '19 07:09 LeMoussel

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 avatar Oct 02 '19 18:10 VikramTiwari

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?

VikramTiwari avatar Nov 18 '19 23:11 VikramTiwari

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

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

paulirish avatar Nov 19 '19 00:11 paulirish

@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?

paulirish avatar Mar 06 '20 17:03 paulirish

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?

VikramTiwari avatar Mar 06 '20 17:03 VikramTiwari