Videos
How to Open Google Chrome Flags?
How Can I Disable Chrome Flags?
Do Chrome Flags work on all devices?
You can use Chrome Flags on both mobile and desktop browsers, but not all Chrome Flags are available on every device. Some are desktop or mobile-specific. However, Chrome will separate unavailable Flags and put them into the Unavailable tab.
New method added in Chrome 661 that works for a production build on unrooted devices.
Using
adb, write the flags to/data/local/tmp/chrome-command-line.For example:
~$ adb shell 'echo --unsafely-treat-insecure-origin-as-secure=http://a.test > /data/local/tmp/chrome-command-line'In
chrome://flags, turn onenable-command-line-on-non-rooted-devices.Force stop Chrome (the relaunch now button will not trigger the reading of the flags file, even though the danger snackbar will disagree).
Verify in chrome://version that this worked.
https://www.chromium.org/developers/how-tos/run-chromium-with-flags#TOC-Android
What you're doing is correct, but seems like you're writing the switches to the wrong file for Chrome (and note that the file that you write the switches to may vary based on the OS version [or maybe phone?] ).
I tried this on two different phones, and had to write to two different files! Hopefully one of them will work for you:
Phone 1: Nexus 6 with Android 6.0.1
Simply do the following in adb shell:
echo "chrome --sync-url" > /data/local/tmp/chrome-command-line'
Phone 2: MotoG with Android 4.4.4
This is a bit trickier. It turned out that Chrome actually reads the switches from /data/local/chrome-command-line (not in the tmp subdirectory!). Now the issue is that on an unrooted phone you won't have permission to write to this file! So I had to root my phone* and use su to write to the file:
adb shellsuecho "chrome --sync-url" > /data/local/chrome-command-line
*Rooting an Android phone is actually very easy and takes only a few minutes. There are a number of one click apps for rooting your phone (e.g. KingoRoot). For the case of MotoG, I had to do a few more steps to root, following this)
My choice for Android:
enable-new-contacts-picker
enable-new-photo-picker
disable-pull-to-refresh-effect (disable vertical overscrolling for refresh - I always hated that!)
enable-chrome-duet - love that new design
enable-scroll-anchor-serialization (not sure if it's working on mobile, but on desktop a nice feature)
autoplay-policy (document user activation as requirement for autoplay - but for some reason, it is not always working, I wish that autoplay can be disabled entirely)
download-home-v2 (more UI customization)
stop-in-background (prevents scheduled tasks in background, thus reduces battery usage)
enable-horizontal-tab-switcher (UI customization, I prefer this horizontal tab switching)
upcoming-ui-features (general opt-in for UI flags)
android-site-settings-ui-refresh (more UI customization)
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
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.