将Chromedriver用于无头浏览器时出现“权限策略标头错误”

在 Selenium 上,我使用的是 chromedriver 版本 89 和我的 chrome 浏览器版本 89.0。也。当我在无头浏览器上运行代码时,出现错误;将 chrome 转换为无头浏览器以测试结果。这是我的脚本-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from shutil import which 

chrome_options = Options()
chrome_options.add_argument("--headless")

chrome_path = which("chromedriver")

driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
driver.get("https://duckduckgo.com/")

search_input = driver.find_element_by_id("search_form_input_homepage")
search_input.send_keys("My User Agent")

search_input.send_keys(Keys.ENTER)

这是 VSCODE 终端输出,

DevTools listening on ws://127.0.0.1:57195/devtools/browser/7464cfb0-5b3c-497d-a768-6eae3bb5b59b
[0408/112137.788:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source:  (0)
[0408/112138.552:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source:  (0)
[0408/112139.176:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source:  (0)
[0408/112139.483:INFO:CONSOLE(0)] "Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'.", source:  (0)

VSCode 终端输出

回答

这是用于阻止 Google 称为联合学习群组 (FLoC) 的新跟踪技术的新标头。

关于 FLoC

DDG 使用标头来阻止 FLoC 跟踪。

DuckDuckGo 宣布计划阻止谷歌的 FLoC

如果您访问任何阻止 FLoC 的网站,您会在 Chrome 开发工具中收到相同的警告。

要在您自己的网站上阻止 Google 的 FLoC,请添加以下标题:

permissions-policy: interest-cohort=()

  • This post clarifies some of the misinformation about this header. Worth reading before adding the header to your site: https://seirdy.one/2021/04/16/permissions-policy-floc-misinfo.html

以上是将Chromedriver用于无头浏览器时出现“权限策略标头错误”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>