【问题标题】:How can I launch Chrome with flags from command line more concisely?如何更简洁地从命令行启动带有标志的 Chrome?
【发布时间】:2012-10-20 05:07:25
【问题描述】:

我正在开发一个 WebGL 驱动的应用程序,我想从命令行启动这样的 chrome:

open -a Google\ Chrome --args --disable-web-security

我只是不想每次都输入。有没有办法轻松地将它变成一个单词命令?如果重要的话,我正在使用 mac。

【问题讨论】:

    标签: macos command-line security webgl shortcut


    【解决方案1】:

    只需在 .bashrc 或 .bash_profile 中创建别名

    alias ogc='open -a Google\ Chrome --args --disable-web-security'
    

    然后重新加载你的 shell。

    exec $SHELL
    

    现在,每次您在终端中输入ogc(或任何您想调用的名称)时,它都会运行完整的命令open -a Google\ Chrome --args --disable-web-security

    【讨论】:

    • 当我尝试运行 exec $SHELL 时,我得到 bash: export: –args': not a valid identifier bash: export: –disable-web-security': not a valid identifier
    • 应该是两个破折号。听起来您以某种方式将其添加到 $PATH 中,而您不需要这样做。我在评论中添加的行就是你所需要的。请参阅我的 dotfile 存储库中的示例。 github.com/kevinSuttle/dotfiles/blob/master/zsh/aliases.zsh 只需将它们添加到 .bashrc 或 .bash_profile 的底部
    • 我刚刚用你的提示在 Mojave 暗模式下打开 Chrome Canary 73:open -a Google\ Chrome\ Canary --args --force-dark-mode
    • 如果 chrome 已经打开,则只是将焦点移动到 chrome
    【解决方案2】:

    这对我有用:

    1. 修改 .bash_profile
    2. 写下这个别名:
    别名 cchrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir="/tmp/chrome_dev_session" --disable-web-security'
    1. 运行
    执行 $SHELL
    1. 使用 cchrome 命令打开一个新的 chrome 窗口并禁用网络安全以解决“访问控制允许来源”问题

    【讨论】:

      【解决方案3】:

      使用终端在 MAC 中使用标志启动 Chrome 的最简单方法是:

      '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --disable-features=CrossSiteDocumentBlockingAlways,CrossSiteDocumentBlockingIfIsolating

      上述代码中-- 之后的任何过滤器@ 987654323@ 只是一个示例。

      注意:确保在运行之前关闭所有 Chrome 实例。

      【讨论】:

        【解决方案4】:

        为什么不只运行一个网络服务器?打开终端并输入

        cd folder_with_html_and_assets
        python -m SimpleHTTPServer
        

        现在在浏览器中转到 http://localhost:8000 完成后转到终端并按 Ctrl-C

        这似乎比禁用您的安全性并冒着获得 pwnd 的风险要好得多。

        【讨论】:

        • npm包http-server也很方便。 npm install http-server
        • 没有人得到 pwnd。他在做开发。也许快速搜索适合首先验证您的陈述? stackoverflow.com/questions/3102819/…
        • 也许您应该首先研究一下为什么要添加该限制。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-11
        • 2015-10-09
        • 2014-05-22
        • 1970-01-01
        • 2020-03-04
        • 1970-01-01
        相关资源
        最近更新 更多