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

如何在带XVFB的无头模式SeleniumBase中禁用Chrome下载完成提示?

解决SeleniumBase无头模式下禁用Chrome下载完成提示气泡的问题

要禁用Chrome的download_bubble.partial_view_enabled参数,你可以通过给SeleniumBase的SB类传递Chromium启动参数来强制关闭该特性,具体实现如下:

方法1:使用chromium_arg传递强制字段试验参数

Chrome的download_bubble.partial_view_enabled属于字段试验(Field Trial)参数,需通过--force-fieldtrials启动参数强制禁用。将其与已有配置结合:

with SB(
    uc=True,
    headless=True,
    xvfb=True,
    chromium_arg='--disable-notifications --force-fieldtrials=DownloadBubble/PartialViewDisabled/'
) as sb:
    # 你的业务逻辑代码
    ...

方法2:使用chromium_args列表传递多参数

如果需要传递多个独立启动参数,推荐用复数形式的chromium_args(列表格式),可读性更强:

with SB(
    uc=True,
    headless=True,
    xvfb=True,
    chromium_args=[
        '--disable-notifications',
        '--force-fieldtrials=DownloadBubble/PartialViewDisabled/'
    ]
) as sb:
    # 你的业务逻辑代码
    ...

补充:结合Chrome偏好设置增强效果

若仍存在相关提示,可额外添加Chrome偏好设置,禁用下载确认对话框和通知:

with SB(
    uc=True,
    headless=True,
    xvfb=True,
    chromium_args=[
        '--disable-notifications',
        '--force-fieldtrials=DownloadBubble/PartialViewDisabled/'
    ],
    experimental_options={
        "prefs": {
            "download.prompt_for_download": False,
            "download.directory_upgrade": True,
            "profile.default_content_setting_values.notifications": 2  # 2代表禁用通知
        }
    }
) as sb:
    # 你的业务逻辑代码
    ...

原理说明:--force-fieldtrials=DownloadBubble/PartialViewDisabled/会强制Chrome将下载气泡的部分视图功能设为禁用状态,直接覆盖默认的partial_view_enabled=True配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 01:22:40