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

[Feature request] Ability to set instance prefs and localState in addition to args #1693

Closed
skyiea opened this issue Dec 29, 2017 · 6 comments
Labels

Comments

@skyiea
Copy link

skyiea commented Dec 29, 2017

I want to provide Chrome instance with prefs/localState. Using ChromeDriver's chromeOptions (https://sites.google.com/a/chromium.org/chromedriver/capabilities) I could set something like this:

prefs: {
    download: {
        prompt_for_download: false,
        default_directory: DOWNLOAD_PATH,
    }
},
localState: {
    browser: {
        "enabled_labs_experiments": [
            // All preferences can be found here: https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup
            "enable-native-notifications@2",
        ],
    }
},

Is it possible to do the same with puppeteer? (I saw the workaround for setting download dir through _client, but the question is more general)

Here is related issue: #1577

@skyiea skyiea changed the title Feature request: ability to set instance prefs and localState Feature request: ability to set instance prefs and localState in addition to args Dec 29, 2017
@skyiea skyiea changed the title Feature request: ability to set instance prefs and localState in addition to args [Feature request] Ability to set instance prefs and localState in addition to args Dec 30, 2017
@aslushnikov
Copy link
Contributor

No, there's no such API for now, mostly because there's not much demand for it.
For the preferences, you can write prefs to the userDataDir by yourself similarly to how chromedriver does this. And setting downloads directory is not exposed since we're baking a proper support for downloads.

Out of curiosity, what's your usecase for this?

@skyiea
Copy link
Author

skyiea commented Jan 9, 2018

@aslushnikov Yeah, I thought about starting messing with userDataDir directly, though I'm not sure if Chromium will dynamically sync prefs from the userDataDir if I will modify the latter. I assume ChromeDriver constructs userDataDir before opening the instance. And I don't want to keep persistent userDataDir. So do you think something like this will work?

await browser.launch();
await driver.browser.setPrefs({ ... }); // messing with /userDataDir via `fs`
// will browser automatically apply new prefs here? I guess not :\

ATM I have 2 use-cases, which I'm covering with prefs & localState when I use Protractor / Gemini / Selenium:

  1. Downloads:
  • default path
  • disable prompt
  1. Disable native OSX notifications (shipped in Chrome starting from v59), and use Chromium ones.

So I see prefs / localState as addition to args, which gives me more control over the functionality.
Here is complete list of what can be used: https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup

@aslushnikov
Copy link
Contributor

So do you think something like this will work?

@skyiea no, this won't work: the prefs should be written before the browser is launched.

So I see prefs / localState as addition to args, which gives me more control over the functionality.

This probably deserves a PR: you should be able to pass prefs as an argument to the puppeteer.launch option. Under the hood, the puppeteer.launch creates a temporary userDataDir. It can as well fill it with preferences.

Are you interested in working on this?

@skyiea
Copy link
Author

skyiea commented Jan 9, 2018

@aslushnikov Yeah, will look into this next week.

@berstend
Copy link

@skyiea Did you manage to get localState settings working? It seems like the "local state" file has been deprecated in favor of the Preferences file but adding a browser.enabled_labs_experiments object to it doesn't do anything for me.

PS: I've made this wrapper to set instance prefs as your PR won't be merged into puppeteer.

@skyiea
Copy link
Author

skyiea commented May 16, 2018

@berstend As far as I recall I managed to shift localState by modifying /Profile X/Local State file (there was some cryptic notation, which I understood by analyzing existing props in localState file). I guess you are right, about the deprecation. In the recent Chrome version I can't find the file anymore.

PS: thanks for popping out extras, looks promising! I guess it resolves this feature request, and we can close it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants