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

在undetected_chromedriver中禁用弹窗拦截遇问题求助

弹窗拦截禁用失效+chromeOptions prefs参数报错排查方案

可能的原因及解决办法

1. Chrome与undetected_chromedriver版本不兼容

即使更新了undetected_chromedriver到3.5.4,仍需确保它适配当前本地Chrome版本:

  • 运行chrome --version查看本地Chrome版本号;
  • 确认undetected_chromedriver 3.5.4支持该版本(可查其更新日志);
  • 若版本不匹配,可手动指定Chrome路径,或删除.undetected_chromedriver缓存目录,让工具自动下载对应版本的驱动。

2. Prefs参数键名错误

你设置的notifications是通知权限开关,而非弹窗拦截。弹窗拦截对应的正确参数键为popups:

prefs = {"profile.default_content_setting_values.popups": 1}
chrome_options.add_experimental_option("prefs", prefs)

3. undetected_chromedriver初始化方式错误

必须使用undetected_chromedriver自身的初始化方法,而非普通Selenium的webdriver.Chrome:

import undetected_chromedriver as uc

chrome_options = uc.ChromeOptions()
# 添加你的参数配置...
driver = uc.Chrome(options=chrome_options)  # 关键:用uc.Chrome初始化

4. Chrome自动更新导致驱动不匹配

Chrome自动更新后,缓存的旧驱动可能失效:

  • 找到本地.undetected_chromedriver文件夹(通常在用户根目录),删除其中的驱动文件;
  • 重新运行代码,让工具自动下载适配当前Chrome的最新驱动。

5. 网站反爬机制拦截

部分网站会检测自动化浏览器环境,即使配置了弹窗拦截也无法生效:

  • 添加额外反检测参数:
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    chrome_options.add_experimental_option("useAutomationExtension", False)
    
  • 尝试启用子进程模式:
    driver = uc.Chrome(options=chrome_options, use_subprocess=True)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 03:57:23