@@ -28,14 +28,15 @@ module.exports = (on, config) => {
2828
2929 console . log ( `✅ 准备使用 Chrome for Testing: ${ chromeBinaryPath } ` ) ;
3030
31- // 注意:在 before:browser:launch 中无法直接设置自定义浏览器路径
32- // 正确的方式是通过命令行参数 --browser 来指定
33- // 这里我们只能设置环境变量,供其他工具使用
31+ // 尝试通过 launchOptions.args 设置自定义浏览器路径
32+ // 这是 Cypress 支持的方式
33+ arguments_ . args . push ( `--browser=${ chromeBinaryPath } ` ) ;
34+
35+ // 同时设置环境变量作为备用方案
3436 process . env . CHROME_BIN = chromeBinaryPath ;
3537 process . env . CHROME_FOR_TESTING_PATH = chromeBinaryPath ;
3638
37- console . log ( `⚠️ 注意:在 before:browser:launch 中无法直接设置自定义浏览器路径` ) ;
38- console . log ( `💡 建议:使用命令行参数 --browser "${ chromeBinaryPath } " 来指定 Chrome for Testing` ) ;
39+ console . log ( `🔧 已通过 launchOptions.args 设置浏览器路径: ${ chromeBinaryPath } ` ) ;
3940 console . log ( `🔧 已设置环境变量 CHROME_BIN: ${ chromeBinaryPath } ` ) ;
4041
4142 console . log ( `🔍 Browser 对象信息:` , {
@@ -47,7 +48,8 @@ module.exports = (on, config) => {
4748
4849 console . log ( `🔍 LaunchOptions 信息:` , {
4950 extensions : arguments_ . extensions . length ,
50- args : arguments_ . args . length
51+ args : arguments_ . args . length ,
52+ extensionPaths : arguments_ . extensions
5153 } ) ;
5254 } catch ( error ) {
5355 console . warn ( `⚠️ Chrome for Testing 准备失败: ${ error . message } ` ) ;
0 commit comments