I am running automated tests on a Selenium remote server in Python. The remote Selenium server runs inside of a docker container. I obtain my Selenium driver with the following code:
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Remote(command_executor='http://127.0.0.1/wd/hub', options=options)
driver.get('http://127.0.0.1:8000')
# ...
driver.close()
I would like to pass two Chrome flags (#same-site-by-default-cookies and #cookies-without-same-site-must-be-secure) to the Selenium Chrome instance. After some research, it seems that I would pass these flags to a new Chrome process by running:
/usr/bin/google-chrome-stable --flag-switches-begin --disable-features=CookiesWithoutSameSiteMustBeSecure,SameSiteByDefaultCookies --flag-switches-end
I've tried adding these arguments to the Selenium ChromeOptions
object like so:
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--flag-switches-begin")
options.add_argument("--disable-features=CookiesWithoutSameSiteMustBeSecure,SameSiteByDefaultCookies")
options.add_argument("--flag-switches-end")
# ... snip ...
Unfortunately, this doesn't appear to have any effect on the Selenium Chrome browser instance. How can I reconfigure the Selenium browser with these flags? Do I need to pass these arguments to the docker container somehow?