I have a React application that I'm writing in VS Code. In order to test and debug my work, I go to the the terminal and enter npm start
. This starts the application server and it properly launches chrome under the current logged in user, which has the React Devtools extension installed.
However, I'm also using the Debugger with Chrome extension in VS Code. In order to use those debugger tools, once the application has been started by npm, I need to hit F5 and this launches a new browser window for Chrome. Under this mode, my breakpoints are being hit in VS code, and I can inspect as I need too.
However, the difference is that when I hit F5, VS Code opens a new browser Window that looks like a newly installed instance of Chrome. Since I use Chrome in multiple VMs and architectures, I've setup my Google account so that as I login into my profile on each machine in Chrome, all necessary bookmarks and extensions are loaded into that instance of Chrome.
F5 debugging isn't showing that user profile information, even though a regular launch of Chrome is showing those details, as is the initial launch of the browser when I run npm start
. Is there a way to alter my VS Code configurations so that when debugging in VC Code with the Debugger for Chrome extension, I can access my Chrome profile with all my desired extensions and tools?
Also, here's my launch.json file. I think this is used by the debugger.
{
// 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}",
}
]
}
I think these are defaults and I think, maybe, this is what NPM is using rather than whatever is launching the debugger & browser with F5.
To debug any project in either Chrome or Microsoft Edge, all you need to do is to start a session by pressing F5 or activating the debug icon in the menu bar and selecting “Run and debug”. Alternatively, you can also use the Visual Studio Code command palette and run the “Debug: Open Link” command.
To get started, open the Extensions view (Ctrl+Shift+X). When the extension list appears, type 'chrome' to filter the list and install the Debugger for Chrome extension.
Our Chrome Debugger allows front-end developers to debug their client-side JavaScript code running inside Google Chrome directly from Visual Studio Code. How does it work? # Our debugger works by connecting to Chrome over its Chrome Debugger protocol, where we map files loaded in the browser to the files open in Visual Studio Code.
The first thing you need to do is install the Debugger for Chrome extension. After you’ve installed it, you’re almost ready to go. The next thing you need to do is create a launch file for the Visual Studio Code Debugger. This file contains the debugger’s different configurations for your project.
In the search box, type “Chrome.” You’ll see the “Debugger for Chrome” extension appear at or near the top. Click the tiny green Install button next to that extension.
Visual Studio Code includes a built-in debugger for Edge and Chrome. There are a couple ways to get started with it. Use the Open Link command to debug a URL. Clicking a link in the JavaScript debug terminal.
Add "userDataDir": false
to your launch config, like this:
{
// 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}",
"userDataDir": false
}
]
}
BUT you must first quit all running instances of Chrome, because it's not possible to put a running Chrome user profile into debug mode. This is why the extension creates a new user profile by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With