如何在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:通过配置文件指定
- 在项目根目录创建或修改
playwright.config.js,配置Chromium的启动参数:
module.exports = { use: { browserName: 'chromium', launchOptions: { args: ['--disable-blink-features=AutomationControlled'], headless: false // 可选,根据录制需求设置是否无头模式 } } };
- 运行codegen时指定该配置文件:
npx playwright codegen --config=playwright.config.js
为什么之前的尝试失败?
--args并非playwright codegen的合法命令行选项,直接传递会触发参数错误。- 使用
--转发参数时,codegen会将后续内容当作目标URL解析,而非浏览器启动参数,导致域名解析失败。
内容的提问来源于stack exchange,提问作者Stevoisiak
相关产品推荐
相关产品推荐

