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

如何在Playwright codegen中传递Chromium的--disable-blink-features启动参数?

解决Playwright Codegen传递Chromium启动参数的问题

要在playwright codegen中传递--disable-blink-features=AutomationControlled参数,有两种可靠的方法:

方法1:利用环境变量

在Windows环境中,根据使用的终端类型设置环境变量后再启动codegen:

  • CMD:
set PLAYWRIGHT_CHROMIUM_ARGS=--disable-blink-features=AutomationControlled
npx playwright codegen --browser=chromium
  • PowerShell:
$env:PLAYWRIGHT_CHROMIUM_ARGS="--disable-blink-features=AutomationControlled"
npx playwright codegen --browser=chromium

方法2:通过配置文件指定

  1. 在项目根目录创建或修改playwright.config.js,配置Chromium的启动参数:
module.exports = {
  use: {
    browserName: 'chromium',
    launchOptions: {
      args: ['--disable-blink-features=AutomationControlled'],
      headless: false // 可选,根据录制需求设置是否无头模式
    }
  }
};
  1. 运行codegen时指定该配置文件:
npx playwright codegen --config=playwright.config.js

为什么之前的尝试失败?

  • --args并非playwright codegen的合法命令行选项,直接传递会触发参数错误。
  • 使用--转发参数时,codegen会将后续内容当作目标URL解析,而非浏览器启动参数,导致域名解析失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 00:33:16