Experimental flags with Chrome webdriver

4336 views
Skip to first unread message

Pascal H

unread,
Jul 3, 2018, 10:25:36 PM7/3/18
to Selenium Users
Hi, I'm trying to enable experimental flags when launching Chrome with web driver :

I did the following :

from selenium.webdriver.chrome.options import Options
myOptions = Options()
myOptions.add_argument("--enable-quic")
myOptions.add_argument("--enable-tcp-fast-open")
driver = webdriver.Chrome(chrome_options=myOptions)

Now, in chrome://version, I have :

Command Line/usr/bin/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --enable-quic --enable-tcp-fast-open --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.8w4LVP/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/home/woo/myTEmp --flag-switches-begin --flag-switches-end


And in chrome://flags, neither QUIC nor Fast Open is enabled.
If I change manually the QUIC and Fast Open option in chrome://flags and click on relaunch, I will now have :
Command Line/usr/bin/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --disk-cache-size=1 --enable-automation --enable-logging --enable-quic --enable-tcp-fast-open --force-fieldtrials=SiteIsolationExtensions/Control --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.8w4LVP/internal --log-level=0 --media-cache-size=1 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/home/woo/myTEmp --flag-switches-begin --enable-quic --enable-tcp-fastopen --flag-switches-end

(And in chrome://flags I do have the QUIC and Fast Open Options)
So it appears to me that to enable experimental flags, they need to be located between the 
"--flag-switches-begin" and "--flag-switches-end".

So, is there any way to tell Selenium to set the options within those 2 flags ?

Regards,
Pascal








Pascal H

unread,
Jul 4, 2018, 4:42:37 AM7/4/18
to Selenium Users
For anyone interested, I found this workaround (pretty complex :p), but didn't find a way to enable this through Selenium functions.

Regards, Pascal

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

## Browser config javascript commands (need to be launched from chrome://flags)
enable_quic_command = "chrome.send('enableExperimentalFeature',['enable-quic' + '@' + 1, 'true'])"
enable_fastopen_command = "chrome.send('enableExperimentalFeature', ['enable-tcp-fast-open', 'true'])"

def chrome_configure_experimental_flags(myDriver):
myDriver.get('chrome://flags') #Load page where configuration javascript commands are allowed
myDriver.execute_script(enable_quic_command) #Enable QUIC
myDriver.execute_script(enable_fastopen_command) #Enable TCP
myDriver.get('chrome://flags') #Re-load so that we can check
time.sleep(2) #Give some time to check the flag


myOptions = Options()
#Set disk and media cache size to disable caching
myOptions.add_argument("--disk-cache-size=1")
myOptions.add_argument("--media-cache-size=1")
#Set our own, to be re-used, profile
profile_folder = '/tmp/' + 'profile_chrome_' + time_string
myOptions.add_argument("user-data-dir=" + profile_folder)

#Create driver
driver = webdriver.Chrome(chrome_options=myOptions)
#Set experimental features
chrome_configure_experimental_flags(driver)
#Close and re-build driver with same options (and so same profile, so experimental flags will be kept)
driver.close()
driver = webdriver.Chrome(chrome_options=myOptions)

Shawn McCarthy

unread,
Jul 4, 2018, 1:39:08 PM7/4/18
to Selenium Users
what kind of different do you see with these two flags ?

Pascal H

unread,
Jul 4, 2018, 1:47:56 PM7/4/18
to Selenium Users
Hi Shawn, 
 
I'm studying transport-layer protocols and their performance when accessing Internet through a satellite.
Thanks to those two flags, Chrome will here use the QUIC protocol and the TFO option of TCP whenever possible.
And then I use Selenium to register some performance metrics with Chrome when accessing different type of services on different servers, with different transport layer protocols.
Regards, 
Pascal
 

René Ernst

unread,
Aug 24, 2019, 11:40:54 PM8/24/19
to Selenium Users
Pascal,

Thanks for this great code. I was struggling with exactly the same, and I would never have been able to work this out myself. I only had to convert your code to Java but that was a piece of cake.

Being unable to set Chrome flags would have been a showstopper for my project, and now everything is working as intended.

Thanks again, great job!

René

Александр Юрков

unread,
Sep 19, 2020, 11:01:28 AM9/19/20
to Selenium Users
Good afternoon, could you please write the code converted to Java code.

воскресенье, 25 августа 2019 г. в 06:40:54 UTC+3, René Ernst:

Александр Юрков

unread,
Sep 19, 2020, 11:01:38 AM9/19/20
to Selenium Users
René Ernst, 

Good afternoon, could you please write the code converted to Java code.

воскресенье, 25 августа 2019 г. в 06:40:54 UTC+3, René Ernst:
Pascal,

ddlionx

unread,
Sep 19, 2020, 11:16:11 AM9/19/20
to seleniu...@googlegroups.com
Try this https://www.jython.org/. ;) 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/28443322-a4f8-4eb9-882f-e7d3e616d97cn%40googlegroups.com.
Message has been deleted

anfas...@gmail.com

unread,
Sep 23, 2020, 2:55:28 AM9/23/20
to Selenium Users
This can be handled using below scripts.

Java:
                       ChromeOptions options = new ChromeOptions();
                        HashMap<String, Object> chromeLocalStatePrefs = new HashMap<String, Object>();
                        List<String> experimentalFlags = new ArrayList<String>();
                        experimentalFlags.add("same-site-by-default-cookies@2");
                        experimentalFlags.add("cookies-without-same-site-must-be-secure@2");
                        chromeLocalStatePrefs.put("browser.enabled_labs_experiments", experimentalFlags);
                        options.setExperimentalOption("localState", chromeLocalStatePrefs);

C#:
                        var chromeOptions = new ChromeOptions();
                        var experimentalFlags = new List<string>();
                        experimentalFlags.Add("same-site-by-default-cookies@2");
                        experimentalFlags.Add("cookies-without-same-site-must-be-secure@2");
                        chromeOptions.AddLocalStatePreference("browser.enabled_labs_experiments", experimentalFlags);

Hope this will help you.

Regards
Anfas

Reply all
Reply to author
Forward
0 new messages