-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
feat(prefs): add ability to launch browser with desired preferences #1806
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
CLAs look good, thanks! |
I signed it! |
@skyiea This looks good! Looking forward to landing this. |
@aslushnikov Added tests and updated docs. |
@@ -76,6 +78,13 @@ class Launcher { | |||
|
|||
chromeArguments.push(`--user-data-dir=${options.userDataDir || temporaryUserDataDir}`); | |||
} | |||
if (options.prefs) { | |||
console.assert(!options.headless, `Custom preferences can't be used in headless mode`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bummer. I didn't know preferences are not supported by headless browser. We try hard not to land API that works only in headful browser.
@skyiea can you please share what particular preferences are you interested in? We might be able to plumb them for you through DevTools protocol so that it works in both headful and headless modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised too that it doesn't work in headless browser, given that headless supports custom userDataDir
and, say, localStorage
/cookies
. Might be some of you guys have some insight why Preferences
file is being ignored in headless?
Personally for me it makes no difference, because I'm using puppeteer to test Chrome extension, which means that I don't have a chance to use headless mode anyway (BTW, any insight why so?). Thus I guess many of the users are already using puppeteer in headful mode.
That's not only about my particular case, I guess. As I've said, there is a lot (https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup) of additional settings that are available via preferences. For me it allows to set prefs.download.default_directory
(setDownloadBehavior
doesn't work for me, I guess because I'm downloading via chrome.downloads
API), and in the future I'd like to be able to trigger some experiments (via prefs.experiments_enabled
).
@aslushnikov Any updates on this? |
@skyiea I apologize for the long delay.
It turns out preferences are part of Landing this PR will introduce more inconsistency in headless vs headful modes, which I very much want to avoid. I think you can implement this functionality as a utility method for your needs, or even publish as NPM module. Will this work for you? I'm sorry for misleading you on this feature. |
Closing this as per previous comment. |
In case anyone else who needs this ends up here, I've published a small wrapper to enable custom preferences in puppeteer: https://github.com/berstend/puppeteer-extra Heavily inspired by @skyiea's PR, thanks! 👍 |
The ability to start browser with desired preferences.
Related issue
The easier way to kickoff was to allow to set
prefs
for the cases when there is no preconfigureduserDataDir
/--user-data-dir
and to see the feedback from the maintainers.What's done:
What could be done as a separate feature:
prefs
in conjunction withuserDataDir
/--user-data-dir
@aslushnikov WDYT?