28

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?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 2
    I'm sure there are no (and will never be) built-in means for changing chrome flags from scripts and/or extensions. This is done by design. Otherwise, an ordinary user experience would become a nightmare - just imagine that every sinle piece of code could alter user preferences under hand. I suggest you to provide more details about specific required modules, so others can think on a workaround. For example, you could possibly move part of logic from client to server. – Stan Jun 20 '13 at 10:06
  • Then what is the big difference between Internet Explorer and Google Chrome, if as developer we do not have freedom to make user friendly use cases? –  Jun 20 '13 at 17:56
  • 5
    I believe, anyone will tell you that changing his/her preferences programmatically without a user permission would be user UNfriendly. If a user disabled a plugin, he/she did it on purpose. So, if your script could somehow alter this option, the user will NOT be happy, if not to say more. No matter what browser is it, if the function you requested would be implemented, it would be a security flaw. Let us consider refactoring your application instead. – Stan Jun 20 '13 at 18:20
  • I use this answer: https://superuser.com/questions/489108/in-what-file-are-flags-set-in-google-chrome-being-saved – Alek Oct 07 '21 at 15:45

2 Answers2

21

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

mmoya
  • 1,901
  • 1
  • 21
  • 30
Subhas
  • 14,290
  • 1
  • 29
  • 37
  • The solutions that you mentioned consist of creating a webdriver for testing, kind of emulating a web browser, are you sure that the flags will be turned on, and will be kept turned on later ? – Mehdi Karamosly Jun 20 '13 at 16:12
  • 1
    I mentioned two solutions: 1) Setting flags in command line when launching, or the last option is 2) Webdriver for testing. I would recommend that you use (1) command line flags. – Subhas Jun 21 '13 at 05:55
  • 1
    But in case you're using (2) Webdriver - then you have to set the `--user-data-dir` switch [as given in this example](http://www.verious.com/qa/how-do-i-set-watir-chrome-to-use-a-specific-profile-so-i-can-use-stored-cookies/). Set this to the data directory that Chrome uses by default, [which is documented here](http://www.chromium.org/user-experience/user-data-directory) for all Windows/Mac/Linux platforms. Then any change you make will be persisted in the future. I've updated the solution accordingly – Subhas Jun 21 '13 at 07:39
  • @Subhas, How does Capybara work? Is it a Chrome simulation or is a a full 100% pure Chrome? – Pacerier Jan 30 '17 at 16:48
6

Rooting about in the chrome://flags screen I found something interesting in an included JS file :

/**
 * Invoked when the selection of a multi-value choice is changed to the
 * specified index.
 * @param {HTMLElement} node The node for the experiment being changed.
 * @param {number} index The index of the option that was selected.
 */
function handleSelectChoiceExperiment(node, index) {
  // Tell the C++ FlagsDOMHandler to enable the selected choice.
  chrome.send('enableFlagsExperiment',
              [String(node.internal_name) + '@' + index, 'true']);
  requestFlagsExperimentsData();
}

chrome.send is indeed a valid method,

Here is another snippet form the same file (chrome://flags/flags.js)

/**
 * Asks the C++ FlagsDOMHandler to restart the browser (restoring tabs).
 */
function restartBrowser() {
  chrome.send('restartBrowser');
}

Manually calling chrome.send ('restartBroswer') did indeed restart the browser.

I think this provides all the facilities you need to automate the setting of the flags, you will need to trawl through the chrome://flags source to find the flags you need and then set up the appropriate chrome.send calls.

HBP
  • 15,685
  • 6
  • 28
  • 34
  • `chrome.send` is sandboxed, it can be accessed only from within the `chrome://flags` page. In normal applications can we invoke this? – Subhas Jun 16 '13 at 19:39
  • 6
    Would you like random Web pages to restart your browser? – Koterpillar Jun 16 '13 at 22:32
  • `Not allowed to load local resource: chrome://flags/` (after trying to create an iframe in order to manipulate the flags..) so we probably need to find another path – Mehdi Karamosly Jun 19 '13 at 23:20