Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

javascript - Google Chrome - how can i programmatically enable chrome://flags some of the modules from disable mode to enabled mode?

How can I automate the setting of chrome flags to enable few modules?

I have application designed which requires on open the chrome://flags few modules enabled, otherwise the whole application does not work, for normal user its nightmare to do such small changes.

Is there any javascript or google app engine or other method to use from server side scripting or some plugin where i can say click this and it will automatically enable the modules inside chrome://flags?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Almost every Chrome flag can be set via the command line. Here is a quite exhaustive list of command line parameters, but also keep in mind that there would be even more in newer versions!

EDIT: Here is the Comprehensive, up-to-date list of Chrome command line switches

So basically you would launch chrome with these command line flags already set. That's the best way to go about it.

You cannot manually set this using Javascript or other behavior. The only way you can set this programmatically (other than command line flags) is to use Capybara (a tool that can open and control browsers, generally used for running automated tests), open Chrome and then manually navigate to "chrome://flags" and click the necessary combo boxes.

EDIT: Watir is also as good as Capybara

Watir is another browser automation framework (similar to Capybara) but is much easier to setup and start with. Here are examples on how you would open a web page and select a combo box, and here are instructions on using it with Chrome. You can write a single ruby file which looks like:

require 'watir-webdriver'
browser = Watir::Browser.new :chrome
browser.goto "chrome://flags"
browser.select_list(:id => <combo box id>).select("Enabled")
...

Persisting the Flags when using WebDriver

Chrome has the --user-data-dir switch which is where all the profile settings are saved. The default directories that Chrome uses (on Windows/Mac/Linux) [is documented here. Generally, WebDriver launches with a temporary --user-data-dir, and later deletes the temporary folder after use. So whatever flags you set will be lost when you run Chrome again! So set --user-data-dir to your user's default profile directory, and then whatever flags you set will be persisted.

Edit 2: Added comprehensive list of chrome command line flags

Edit 3: Added instructions for persisting the flags in Webdriver


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...