[英]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我可以使用 Selenium、ChromeDriver 和 Python 启动 Brave 浏览器
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.但我无法摆脱与Google Chrome通知栏几乎相似的产品分析通知栏。
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
.首先是命令行开关
--p3a-upload-enabled
是可选的,并且仅在 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.其次,它肯定与隐私、 GDPR和内部政策有关,因为 P3A Brave 功能不会收集个人信息。 (It still collect telemetry data) .
(它仍然收集遥测数据) 。
You will get more information about this part on their blog: https://brave.com/privacy-preserving-product-analytics-p3a/您将在他们的博客上获得有关此部分的更多信息: 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
.作为参数,您可以查看此commit ,更准确地说是在L13 、 L79-L80和L212-L221 行,他们删除了开关
--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.回到您的问题,如果您不需要运行
chromedriver
profileless,则只需设置一个配置文件,一旦浏览器运行,您可以关闭通知栏,关闭的 state 将保存在配置文件中并在下次运行时,该栏将被隐藏。
The following code will create a profile when the WebDriver is instanciated:以下代码将在 WebDriver 实例化时创建配置文件:
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 . WebDriver 运行后,您将在Profile 文件夹中的Preferences文件中找到以下配置部分。
{
"brave": {
"p3a": {
"enabled": "false",
"notice_acknowledged": "true"
}
},
"p3a": {
"last_rotation_timestamp": "13285608876785125"
}
}
The solution could be to set theses preferences on WebDriver instanciation:解决方案可能是在 WebDriver 实例上设置这些首选项:
# 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
. @flydev 指出了 Brave 开关,我尝试将其与
selenium.webdriver.common.desired_capabilities.DesiredCapabilities
一起使用。
Unfortunately this did not work.不幸的是,这不起作用。 When I checked Brave Browser's github account I found this item:
当我检查 Brave Browser 的 github 帐户时,我发现了这个项目:
As you can see this is a known issue.如您所见,这是一个已知问题。 I will keep looking for a method that uses
DesiredCapabilities
.我将继续寻找使用
DesiredCapabilities
的方法。
In the meantime, you can pass a Brave profile to the driver, which suppresses the acknowledgement notification.同时,您可以将 Brave 配置文件传递给驱动程序,从而抑制确认通知。
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.在使用配置文件之前,您必须在 Brave 浏览器中禁用这些项目。
Here is the browser with Profile 1 and no acknowledgement notification box.这是带有配置文件 1 且没有确认通知框的浏览器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.