22

I am using the Debugger for Chrome VS Code extension. I am working on a React project using yarn start, which opens at localhost:3000.

I have an already running instance of Chrome where I am logged in using my Google account. However when I hit "Launch Chrome against localhost", the tab opens in a new instance of Chrome where I am not logged in.

enter image description here

How do I force the tab to open in my already-running instance of Chrome instead?

launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:3000",
            "webRoot": "${workspaceFolder}"
        },
    ]
}
2
  • did you find a solution ? I am stuck in same scenario. please post any solution/workaround you found. It would be helpful.
    – Boopathi T
    Commented May 12, 2021 at 10:39
  • I posted this as an answer to my own q but it kept getting downvoted so I removed it. go ahead and see if it works for you (adding "userDataDir": false): briandesousa1.wordpress.com/2018/05/12/…
    – Casey L
    Commented May 12, 2021 at 11:22

2 Answers 2

3

The following guide was helpful, basically you want to use "request": "attach" not "request": "launch".

https://www.freecodecamp.org/news/how-to-set-up-the-debugger-for-chrome-extension-in-visual-studio-code-c0b3e5937c01/

3

The FreeCodeCamp guide cited below has the beginnings of the solution, but is outdated and incomplete.

As of 2023, you need to do two things:

  1. Click the 'Add Configuration' button in VSCode, and create a new one for "Chrome: Attach". The new config in launch.json should now have a request param in VSCode's to be "attach" instead of "launch".
  2. Quit/kill ALL running Chrome instances.
  3. Run the special command to re-open Chrome (including all your existing tabs and other identity) with remote debug enabled, on a particular port. On MacOS, the command is: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
  4. In VSCode, go back to the Run and Debug panel, and click on the menu at top to change from the launch-based config you had before, to the new attach-based config.
  5. Now, click the green 'Start Debugging' button, and you should see the Debug Console open up in the bottom Panel, and populate with the console output

See the VSCode docs on this for more detail, and commands for other platforms. And, make sure that the port param in launch.json matches the port number in the command you use to re-launch Chrome.

Not the answer you're looking for? Browse other questions tagged or ask your own question.