Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug HTML and JavaScript together in VSCode (Visual Studio Code)?

I want to run and debug an html page with a javascript file in a mini website when I hit F5.

How do I configure VSCode to open the html page in the browser and then allow me to set breakpoints in the javescript file which will be triggered by my interaction with the app in the browser?

In Visual Studio this would "just work", because it fires up its own web server, IIS Express. In VSCode I'm not sure how I set up launch.json and/or tasks.json to create a simple node.js web server and serve index.html.

I have seen some examples of debugging javascript apps, for example this launch.json:

{     "version": "0.1.0",     "configurations": [         {             "name": "Launch Bjarte's app",             "type": "node",             "program": "app.js",             "stopOnEntry": true,             "args": [],             "cwd": ".",             "runtimeExecutable": null,             "runtimeArguments": [],             "env": {},             "sourceMaps": false         },         {             "name": "Attach",             "type": "node",             "address": "localhost",             "port": 5858,             "sourceMaps": false         }     ] } 

This will run the js file, but I don't understand how I can interact with the app.

like image 880
Bjarte Aune Olsen Avatar asked Jun 26 '15 10:06

Bjarte Aune Olsen


People also ask

How do you debug HTML code in VS Code?

The simplest way to debug a webpage is through the Debug: Open Link command found in the Command Palette (Ctrl+Shift+P). When you run this command, you'll be prompted for a URL to open, and the debugger will be attached. If your default browser is Edge, VS Code will use it to open the page.

How debug JavaScript file in VS Code?

To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file. However, for most debugging scenarios, creating a launch configuration file is beneficial because it allows you to configure and save debugging setup details.

How do I debug JavaScript in HTML?

Start debugging Open the HTML file that references the JavaScript to debug or select the HTML file in the Project tool window. From the context menu of the editor or the selection, choose Debug <HTML_file_name>.


1 Answers

It is now possible to debug Chrome web pages in vscode via Chrome remote debugging with a extension released by Microsoft. Debugger for Chrome

As you can see from that page there are two modes of debugging, Launch and Attach. I only managed to use the Attach mode, probably because i don't have a server running. This extension has all important debug tools functional: local variables, breakpoints, console, call stack.

Another reason to revisit vscode is that it now has IntelliSense support for ECMAScript 6, which displays methods not visible in other "IntelliSense like" solutions I've tried, like SublimeCodeIntel or the latest version of WebStorm.

like image 99
Vlad Macovei Avatar answered Sep 24 '22 04:09

Vlad Macovei