如何让GruntJS在设置标志的情况下启动Chrome
当我运行命令如何让GruntJS在设置标志的情况下启动Chrome,gruntjs,Gruntjs,当我运行命令grunt build时,我希望它能自动启动Chrome,并设置标志--禁用扩展名和--禁用网络安全性。我该怎么做? 我对格伦特不太了解,但这是我同事的一次谈话。希望能有帮助。(当然,“打开”命令是专门针对OSX的,对于windows,您可以指向google chrome.exe,而linux则只是“google chrome”。--user data dir=/tmp/junk允许您以新用户的身份打开浏览器。)这个解决方案适合我在Mac上使用 open: { appN
grunt build
时,我希望它能自动启动Chrome,并设置标志--禁用扩展名
和--禁用网络安全性
。我该怎么做?
我对格伦特不太了解,但这是我同事的一次谈话。希望能有帮助。(当然,“打开”命令是专门针对OSX的,对于windows,您可以指向google chrome.exe,而linux则只是“google chrome”。--user data dir=/tmp/junk允许您以新用户的身份打开浏览器。)这个解决方案适合我在Mac上使用
open: {
appName: "hiddenBrowser", // some unexisted name of app
callback: function(){
var exec = require('child_process').exec;
exec('open -a "Google Chrome Canary" --args --disable-web-security "http://localhost:3000"')
}
}
基于
npm-open
和grunt-contrib-open
的代码,您在appName中写的所有内容都用引号括起来。例如:
{
target: 'http://localhost:3000', // target url to open
appName: 'Google Chrome --args --disable-web-security', // name of the app that opens, ie: open, start, xdg-open
callback: function() {} // called when the app has opened
}
我会打电话给你
open -n "Google Chrome --args --disable-web-security" "http://localhost:3000"
所以我做了一个技巧,在回调中调用了我的浏览器。hmmm,idk我的问题到底是什么,但jsHint在我这样做时会抱怨(它不喜欢“\”)<代码>错误或不必要的转义。
appName:“open-n-a Google\Chrome--args--disable web security”
是否在字符串周围使用双引号而不是单引号?
open -n "Google Chrome --args --disable-web-security" "http://localhost:3000"