我本地有一个 https 服务,访问网址是 https://127.0.0.1:8080/
然后在命令行中直接敲
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --host-rules="MAP xxx.asdf:443 127.0.0.1:8080" --ignore-certificate-errors --incognito https://xxx.asdf://xxx.asdf
是会打开一个隐身窗口,并且打开 https://xxx.asdf,然后内容是我 https://127.0.0.1:8080/ 的那网站
但是如果换成以下代码
const child_process = require('child_process');
child_process.spawn(
`/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome`,
[
`--host-rules="MAP xxx.asdf:443 127.0.0.1:8080"`,
`--ignore-certificate-errors`,
`--incognito`,
`https://xxx.asdf`
]
)
然后通过 node 去运行,会打开一个隐身窗口,但是会提示找不到 https://xxx.asdf 的 ip 地址,即无法访问
初步看来是因为 spawn 运行的和直接在命令行里面敲有点不一样,大家知道怎么改 node 的代码达到跟命令行一样的效果吗?