如何使 Chrome 始终使用远程调试端口标志启动

How to make Chrome always launch with remote-debugging-port flag

我知道我可以启动 chrome 下面的方式在 9222 端口打开远程调试端口 -

chrome.exe --remote-debugging-port=9222

但我想设置 Chrome 以便每当它被任何其他应用程序启动时,它总是在启用远程调试选项的情况下打开。自定义配置文件有效吗?

我想实现它,因为有一个桌面应用程序会在单击其按钮时启动 chrome。我想控制 chrome 会话。

我找到了解决问题陈述的方法。我将其作为答案发布,因为它可能会帮助其他有类似问题陈述的人。

如果您使用的是 Windows,请转到注册表编辑器并搜索此命令

Computer\HKEY_CLASSES_ROOT\ChromeHTML\shell\open\command

使用以下内容修改密钥 -

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 -- "%1"

如果你想玩 Chrome,如果你总是想在隐身模式下启动 Chrome,请输入 --incognito。

注意:请在玩之前备份您的注册表。

无需编辑注册表,只需右键单击 Chrome 图标并添加...

,即可直接在程序属性中附加标志
--remote-debugging-port=9222 -- "%1" 

...到目标字段的末尾。

对于 mac,我制作了一个简单的应用程序,可以为我启动 chrome 和 --remote-debugging-port。 Mathias Bynens 有一个 wonderful post on how to do this (which is where I got the idea). He even includes a (forked) script 可以为您完成大部分工作,但基础知识非常简单。

  1. 在您的应用程序文件夹中创建一个具有以下结构的目录<new app name>/Contents/MacOS:

    mkdir -p /Applications/Chrome\ Debugger.app/Contents/MacOS
    
  2. 创建脚本文件并使其可执行(其名称需要与顶级文件夹名称匹配):

    cd /Applications/Chrome\ Debugger.app/Contents/MacOS
    touch Chrome\ Debugger
    sudo chmod +x Chrome\ Debugger
    
  3. 使用您选择的编辑器编辑新文件(您到 chrome 的路径可能不同):

    #!/usr/bin/env bash
    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222&
    

仅此而已。如果你想让它更容易找到,你可以添加一个自定义图标(复制你的新图标 > 右键单击​​新应用 > 获取信息 > 单击左上角的当前图标 > 将新图标粘贴到当前图标上),但是没有它,应用程序也能正常工作。

我还不能添加评论,但是 David Mann 的回答对于 MacOS 来说已经过时了。

谢天谢地,只需要一点点改动;将 bash shebang 添加到 Chrome 调试器脚本。

#!/bin/bash
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222&

mac 用户的此更新是在此处找到的:

Nat Khun 还不厌其烦地制作了一个 .dmg,以便为 mac 用户提供 "normal" 安装程序。他的回购可以在这里找到: https://github.com/natkuhn/Chrome-debug/

一定要给他一个star。我做到了!

我正在使用 Dave Shepard 的解决方案 使用 Automator 创建自定义 Chrome 调试应用程序:Chrome Debugging in VSCode

我在这里添加必要的步骤:

  • Open Automator
  • Choose Application when it prompts you for what kind of automation you want to make
  • Find and choose Run Shell Script from the list of actions
  • Put your shell command to launch Chrome with the flag in the field: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
  • Save your automation somewhere with a convenient name you can reference (e.g. Google Chrome Debug Mode) I saved mine to ~/Applications so it would appear in my Alfred list.

That’s it! Just run the automation instead of Chrome directly. As mentioned, you will see two icons in your dock because the automation application isn’t Chrome. I just added my automation application to my dock and removed the normal Chrome entry. If you want the same icon as the normal Chrome shortcut:

  • Open Finder and navigate to /Applications Find Google Chrome in the list of applications and Get Info on it
  • Click the little Chrome icon in the upper left of the window (not the big one at the bottom) and hit cmd+c to copy it to the clipboard
  • Find your automation application and Get Info on it
  • Click the Automator icon in the upper lift and hit cmd+v to paste in the copied Chrome icon