Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug Angular application in VSCode using Edge browser?

I am using Edge extension. Below is configuration in launch.json:

"configurations": [
    {
      "name": "ng serve",
      "type": "edge",
      "request": "launch",
      "url": "http://localhost:4200/",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true
    }]

Here is more detailed steps as per documentation in VS Code:

  1. npm install -g @angular/cli, ng new my-app
  2. Install Edge extension
  3. Reload Project
  4. npm start
  5. Go to the Debug view (Ctrl+Shift+D) and click on gear button to create a launch.json debugger configuration file. Choose Chrome from the Select Environment dropdown. Update configurations with code shown in above launch.json.
  6. Set breakpoint in app.component.ts
  7. Press F5 - it should now hit breakpoint. But getting message on hover of breakpoint - "Unverified breakpoint". The breakpoint is not getting hit.

I tried clearing all breakpoints, restarting vs code(and machine), closing all browser instances, but still getting same behaviour. Debugger is able to launch the angular app in browser but unable to hit the breakpoints.

So, is there is any other configuration to make it work with Edge browser. The current configuration works fine with chrome browser (just replace edge with chrome in launch.json).

like image 771
Chirag Rupani Avatar asked Apr 25 '18 04:04

Chirag Rupani


People also ask

How to debug angular in VS Code?

Debug Angular in VS Code 1 Step 1: Create an Angular application; 2 Step 2: Install Debugger for Chrome (you could install other debuggers you like) 3 Step 3: Configure Debug Environment; 4 Step 4: Start Debugging; More ...

How to enable debugger for Edge extension in Visual Studio Code?

On the VSCode, click the view menu, and select the extension options to check whether you have already installed the Debugger for Edge extension, and already enable it. Then, press Reload to restart VS Code and activate the extension.

How to debug a web application with VSCode debugger?

The key point in both processes is to have webpack dev server and VSCode debugger running at the same time. In your launch.json file add the following configuration: Go to VSCode debugger and run "Angular debugging session" configuration. As a result, new browser window with your application will be opened.

How do I debug front-end JavaScript code in Visual Studio Code?

Visual Studio Code includes a built-in debugger for Microsoft Edge, which can launch the browser or attach to an already running browser. This built-in debugger lets you debug your front-end JavaScript code line-by-line and see console.log () statements directly from Visual Studio Code. For more information, see Browser debugging in VS Code.


2 Answers

This configuration seems to work for me now. It breaks on the breakpoint and shows it as available.

 {
        "name": "Edge",
        "type": "edge",
        "request": "launch",
        "url": "http://localhost:4200/#",
        "webRoot": "${workspaceFolder}",
        "sourceMaps": true,
        "trace": true,
        "userDataDir": "${workspaceRoot}/.vscode/edge"
    }

I guess they made some fixes.

like image 70
gilmishal Avatar answered Nov 15 '22 04:11

gilmishal


The following does hit the breakpoint, but they do show up as unverified in vscode (open circle). I think this might have to do with inline source maps.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "debug chrome",
            "type": "chrome",
            "request": "launch",
            "url": "http://localhost:4200/#",
            "webRoot": "${workspaceFolder}",
            "sourceMapPathOverrides": {
                "webpack:/./*": "${webRoot}/*",
                "webpack:/src/*": "${webRoot}/src/*",
                "webpack:/*": "*",
                "webpack:/./~/*": "${webRoot}/node_modules/*"
            }
        },
        {
            "name": "debug edge",
            "type": "edge",
            "request": "launch",
            "url": "http://localhost:4200/#",
            "webRoot": "${workspaceFolder}",
            "sourceMapPathOverrides": {
                "webpack:/./*": "${webRoot}/*",
                "webpack:/src/*": "${webRoot}/src/*",
                "webpack:/*": "*",
                "webpack:/./~/*": "${webRoot}/node_modules/*"
            },

        },
        {
            "name": "ng test",
            "type": "chrome",
            "request": "launch",
            "url": "http://localhost:9876/debug.html",
            "webRoot": "${workspaceFolder}"
        },
        {
            "name": "ng e2e",
            "type": "node",
            "request": "launch",
            "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
            "protocol": "inspector",
            "args": ["${workspaceFolder}/protractor.conf.js"]
        }
    ]
}
like image 23
Remko Avatar answered Nov 15 '22 04:11

Remko