简体   繁体   中英

How to suppress the product analytics notification bar within Brave Browser initiated through Selenium and ChromeDriver using Python

I'm able to lauch the Brave Browser using Selenium, ChromeDriver and Python

Code trials:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
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/")

But I'm unable to get rid of the product analytics notification bar almost similar to the Google Chrome notification bar.

barve_product_analytics_notification_bar

Can anyone help me out?

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 while Brave was in the 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. (It still collect telemetry data) .

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
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:)

I have never used the Brave Browser, so thanks for opening this question.

@flydev had pointing out the Brave switches, which I tried to use with selenium.webdriver.common.desired_capabilities.DesiredCapabilities .

Unfortunately this did not work. When I checked Brave Browser's github account I found this item:

As you can see this is a known issue. I will keep looking for a method that uses DesiredCapabilities .

In the meantime, you can pass a Brave profile to the driver, which suppresses the acknowledgement notification.

Here is the code:

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

chrome_options = Options()
chrome_options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--disable-notifications")

chrome_options.add_argument("user-data-dir=/Users/username/Library/Application Support/BraveSoftware/Brave-Browser/Default")

chrome_options.add_argument("profile-directory=Profile 1")

# disable the banner "Chrome is being controlled by automated test software"
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])

driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', options=chrome_options)

driver.get('https://www.google.com')

sleep(60)
driver.close()
driver.quit()

You have to disable these items in the Brave Browser before using the profile.

在此处输入图像描述

Here is the browser with Profile 1 and no acknowledgement notification box.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM