I think it's not possible anymore and I don't really know the real reason behind this, but there is at least two reasons.
The first is that the command-line switch --p3a-upload-enabled
was optional and only available before Brave beta-test
.
And the second, it's certainly related to privacy, GDPR and internal policies as the P3A Brave feature doesn't collect personal information but still collect telemetry data with software quality in mind.
You will get more information about this part on their blog: https://brave.com/privacy-preserving-product-analytics-p3a/
As argument, you can take a look at this commit, more precisely on lines L13, L79-L80 and L212-L221 where they removed the switch --p3a-upload-enabled
.
To get back to your issue, if you are not requried to run chromedriver
profileless, then just set a profile, once the browser is running, you can close the notification bar, the closed state will be saved in the profile and on the next run, the bar will be hidden.
The following code will create a profile when the WebDriver is instanciated:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
# set profile path
options.add_argument("user-data-dir=C:\\BrowserDrivers\\Test_Profile\\")
# optional, will be relative to `user-data-dir` switch value
options.add_argument("--profile-directory=test_data")
options.binary_location = r'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://www.google.com/")
And,
Once the WebDriver run, you will find the following config part in the Preferences file which can be found inside the Profile folder.
{
"brave": {
"p3a": {
"enabled": "false",
"notice_acknowledged": "true"
}
},
"p3a": {
"last_rotation_timestamp": "13285608876785125"
}
}
The solution could be to set theses preferences on WebDriver instanciation:
# try to disable P3A via prefs
# ref: https://github.com/brave/brave-core/blob/master/components/p3a/pref_names.cc
chrome_prefs = {"brave":{"p3a":{"enabled":"false","notice_acknowledged":"true"},"widevine_opted_in":"false"},"p3a":{"last_rotation_timestamp":"13285608876785125"}}
options.experimental_options["prefs"] = chrome_prefs
Unfornutely, I couldn't managed to get it working, despite no error - if you do it, please ping me :)
And if you ask me if we can set the capabilities after the instanciation of the WebDriver, then again I would say nop, as of the current implementation of Selenium, once the WebDriver instance is configured with our intended configuration through DesiredCapabilities class and initialize the WebDriver session to open a Browser, we cannot change the capabilities runtime.