# Debugging browser apps

Most web developers have become quite comfortable with their browser development tools. However, web development is quite possibly the only platform where code is written in one place, and debugged in another. It is far easier to debug code in the same place where you write it.

The Chrome Debugger extension for VS Code makes this possible. I have included it in the VS Code Can Do That extension pack.

{% tabs %}
{% tab title="Exercise" %}
Add a `launch.config` to the "3-debug-browser" apps project. Add a breakpoint to the `updateColor` method in the `src/app.js` file.&#x20;

Run the project and then attach the VS Code debugger.&#x20;
{% endtab %}

{% tab title="Answer" %}
* Open the Debug View (**Cmd/Ctrl + Shift + D**)
* Open the dropdown list at the top and select "Add Config (3-deug-browser-apps)

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1EcvbbmFhKYKt579s%2Fimage.png?alt=media\&token=93581ef7-55c3-468d-a12c-1ff3eca5de50)

* Select "Chrome" from the prompt

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1Em2IzzlkPEpYdnPm%2Fimage.png?alt=media\&token=90caf317-23dd-4772-a55a-81d3378502a7)

* This will create a new folder in "3-debug-browser-apps" called ".vscode". Inside there will be a file called "launch.json". VS Code will open this file by default.

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1EyFhV7NOskoLFXbi%2Fimage.png?alt=media\&token=052d2f87-cf9b-4d82-a3a1-30103cc2c069)

* Change the name to "Launch Project 3"

```
"name": "Launch Project 3"
```

* Change the "url" value to "localhost:3000"

```
"url": "http://localhost:3000"
```

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1FpxmCfb6zMaNla-W%2Fimage.png?alt=media\&token=e626bd19-4565-476d-ac00-0ab2c87e1fb4)

* Open the integrated terminal and make sure you are in "3-debug-browser-apps"

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1F7xa_6FuFPBp1cQP%2Fimage.png?alt=media\&token=869b9140-2e69-46cf-a35e-a439a63ab5ef)

* Run `npm start`
* A browser instance will launch with the running app
* Return to VS Code
* In the Debug View, make sure "Launch Project 3" is select in the dropdown list and click the green arrow

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1G6mSgpdRRo83ebiE%2Fimage.png?alt=media\&token=be872b23-7acc-4f92-bd8e-afd0bdd3b1be)

* A new instance of Chrome will open
* Open the "src/app.js" file in the "3-debug-browser-apps" project
* Add a breakpoint to line 48
* In the instance of Chrome that was opened by VS Code, change the color and click the button to update it
* VS Code will hit the breakpoint

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1GWXjdy3Q3zu3RB8z%2Fimage.png?alt=media\&token=844c707f-4700-45b2-96de-f9a176eb5aed)

* Return to Chrome and open the Developer Tools (**Cmd/Ctrl + Shift + i**)
* Notice that Chrome also sees the debugger and is broken on the same line

![](https://707761804-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1Glp890EMX4N-ylB9%2Fimage.png?alt=media\&token=a28ebf70-9f76-41a3-9273-fe252b7e3905)
{% endtab %}
{% endtabs %}

