You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Selenium启动Chrome headless模式 出现Permissions-Policy报错如何解决

Selenium启动Chrome无头模式及报错解决方法

报错本质说明

你遇到的Error with Permissions-Policy header: Unrecognized feature: 'interest-cohort'属于非阻塞性警告,是你访问的目标网站响应头的Permissions-Policy配置不规范导致的,和Selenium的启动逻辑没有直接关联,不会影响代码的正常运行。如果需要消除该警告,添加对应Chrome启动参数关闭相关特性即可。

正确的Chrome无头模式启动配置

Chrome 96及以上版本推荐使用新版无头模式,功能兼容性和普通有头模式完全一致,完整配置代码如下:

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

chromeOptions = Options()
# 新版无头模式参数,低于96版本的Chrome可替换为--headless=chrome
chromeOptions.add_argument("--headless=new")
# 关闭InterestCohort特性,消除对应警告
chromeOptions.add_argument("--disable-features=InterestCohort")
# 可选通用兼容参数,避免不同环境下的运行报错
chromeOptions.add_argument("--no-sandbox")
chromeOptions.add_argument("--disable-dev-shm-usage")
# 可选:只输出错误级别日志,过滤所有警告
chromeOptions.add_argument("--log-level=3")

self.driver = webdriver.Chrome(ChromeDriverManager().install(), options=chromeOptions)

核心参数说明

  • --headless=new:Chrome官方推出的新版无头模式,解决了旧版无头模式下部分Web特性不支持的问题,Chrome 96及以上版本均可使用
  • --disable-features=InterestCohort:关闭Chrome的FLoC广告跟踪特性,直接消除interest-cohort相关警告
  • --log-level=3:将Chrome日志级别设置为仅输出错误信息,自动过滤所有非致命警告提示

内容的提问来源于stack exchange,提问作者bewop

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 20:36:02