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

如何关闭Playwright中Chrome的“自动化测试”标识?避免网站拦截

移除Playwright Chromium持久化上下文的“自动化测试”标识

要去掉Chrome上的“自动化测试”提示,同时保留非无痕的持久化上下文,只需要在launch_persistent_context()的启动参数里添加--disable-features=AutomationControlled即可。这个参数会禁用Chrome的自动化控制检测机制,既不会显示提示栏,也能降低被网站拦截的风险。

示例代码(Python):

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    # 自定义用户数据目录,实现非无痕模式
    user_data_dir = "./my_chrome_profile"
    context = p.chromium.launch_persistent_context(
        user_data_dir,
        headless=False,
        args=["--disable-features=AutomationControlled"]
    )
    
    page = context.new_page()
    page.goto("https://your-target-site.com")
    # 执行你的操作
    
    context.close()

补充说明:

  • --disable-features=AutomationControlled不仅会隐藏浏览器顶部的“自动化测试”提示,还会修改navigator.webdriver等自动化检测属性,让网站更难识别出这是自动化环境。
  • 你提到launch()方法不会出现这个标识,是因为该方法默认的临时上下文配置中已经做了相关隐藏处理,而持久化上下文为了兼容用户数据的完整性,默认保留了这些提示,需要手动添加参数关闭。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 15:55:17