18

when debugging in vscode in "launch chrome" mode, raises a nice and clean chrome instance, without any extension installed. It is good, but in some cases I need react-dev-tools extension and have to run regular chrome to get this done. Is it any way to have clean debugging chrome, but with dev tools added?

launch configuration is usual:

{ "type": "chrome", "request": "launch", "name": "Launch Chrome:3000", "url": "http://localhost:3000", "webRoot": "${workspaceRoot}" }

3 Answers 3

21

Try adding this line to your launch configuration, launch.json:

"runtimeArgs": ["--load-extension=${env:userprofile}/AppData/Local/Google/Chrome/User Data/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/3.2.3_0"]

Some limitations

  1. Installation points to local folder based on ID of Chrome extension (enable developer mode to see it) - "fmkadmapgofadopljbjfkapdkoienihi"
  2. Path also points to a specific version (3.2.3_0), which may break on future releases of React dev tools
  3. Chrome gives a warning "Disable developer mode extensions" when an extension is loaded locally

Sources

  1. VS Code Variables
  2. Chrome command line switches
Sign up to request clarification or add additional context in comments.

5 Comments

If you need multiple extensions, use comma separator like so: "runtimeArgs": [ "--load-extension=${env:userprofile}/AppData/Local/Google/Chrome/User Data/Default/Extensions/lmhkpmbekcpmknklioeibfkpmmfibljd/2.15.3_0,${env:userprofile}/AppData/Local/Google/Chrome/User Data/Default/Extensions/fmkadmapgofadopljbjfkapdkoienihi/3.4.2_0" ]
This is ok for Windows. On Mac the location of extensions is: ~/Library/Application\ Support/Google/Chrome/Default/Extensions
What are the paths for chromium on Linux? or What are these paths represent so I can look for them my self?
i got a "failed to load extension: .Manifest file is missing or unreadable" when tryng this with version 4.24.3_0 of redux dev tools.
For MS Edge on MacOS, it should look like this: "runtimeArgs": [ "--load-extension=~/Library/Application Support/Microsoft Edge/Default/Extensions/gpphkfbcpidddadnkolkpfckpihlkkil/5.2.0_0" ]
7

I was able to get the react-devtools tab with following steps.

  1. Install the react-devtools extension in the window opened by VScode (Again)
  2. Reopen devtools (CMD-ALT-i)
  3. Refresh the page.

I know there could be a better way. I think the chrome window opened by VScode must be protected from loading Extensions like in private mode. Answers welcome.

2 Comments

I used this approach on my MacBook. It worked well for me.
This approach was the only thing that worked for me; on a PC with Visual Studio 2019
0

Summary

We are going to run Chrome with a debug flag and then attach VScode debugger into it.

Steps

  1. Add the following to the package.json start script:
    "start": "'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --remote-debugging-port=9222 & react-scripts start",

Basically what it does it runs the Chrome executable with the --remote-debugging-port=9222 flag. (Note that the & operator launches a background process so the script can proceed to the next command)

  1. Add a launch configuration to the launch.json file:
{
   "type": "chrome",
   "request": "attach",
   "name": "Attach",
   "port": 9222
}
  1. Run the development server by running npm start in the terminal.

Caveats

Note that this solution points to a Chrome installation on a MacOS. For other OS modify the location of chrome in step 1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.