- Basic
- Spec
- launch Chrome browser
- attach Chrome browser
- using browserify
- using webpack
- using typescript and webpack
- Chrome
- Extension: Debugger for Chrome
- Debugger: Chrome
- OS _ âś… MacOS _ âś… Windows * âś… Linux
- Break Point _ ✅ break point _ ✅ condition break point * ❌ function breakpoint
- Step Execution _ ✅ Step Over _ ✅ Step Into _ ✅ Step Out _ ✅ Continue _ ❌ Step Back _ ❌ Move To * ❌ Pause
- Variables _ âś… variables views _ âś… watch variables
- Call Stack * âś… call stack
- Evaluation _ âś… eval expression to show variables _ âś… eval expression to change variables
- Type of Execution _ âś… launch debugging _ âś… remote debugging
- install Chrome browser
- install nodejs
- install some npm package:
npm i
- install Debugger for Chrome extension
- put html/ to your web server. you can use http-server
./node_modules/.bin/http-server html
- Or task
launch web server
- Or task
- module code: html/js/normal_main.js
- menu: "Chrome launch"
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"sourceMaps": true,
"name": "Launch Chrome against localhost",
// your web server url
"url": "http://localhost:8080",
// set your webroot directory
"webRoot": "${workspaceRoot}/html"
}
]
}
- start web server (task
launch web server
) - set breakpoint to html/js/normal_main.js
- start debugger, Chrome browser will open
- menu: "Chrome attach"
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"sourceMaps": true,
"name": "Launch Chrome against localhost",
// your web server url
"url": "http://localhost:8080",
// set your webroot directory
"webRoot": "${workspaceRoot}/html"
}
]
}
Need to add some option when you launch Chrome browser.
# Windows
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
%USERPROFILE%AppData\Local\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222
# Mac
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
# Linux
google-chrome --remote-debugging-port=9222
And start debug.
- module code: js/browserify_bubble_sort.js, js/browserify_main.js
If you use browserify, you can use baberify's --sourceMapsAbsolute for useful. But do not use at production.
npm install -g browserify babelify babel-preset-es2015
browserify --debug js/browserify_main.js -o html/js/browserify_main.js -t [ babelify --presets [ es2015 ] --sourceMapsAbsolute ]
http-server html
start debug
- module code: js/webpack_bubble_sort.js, js/webpack_main.js
npm install -g webpack
const path = require("path");
let exclude = [path.resolve(__dirname, "html")];
console.log(exclude);
module.exports = {
devtool: "source-map",
output: {
path: path.resolve(__dirname, "html", "js"),
filename: "webpack.js",
},
resolve: {
extensions: [".js"],
},
module: {
rules: [{ test: /\.js$/, loader: "source-map-loader", exclude }],
},
devServer: {
contentBase: "html/",
},
};
webpack -d js/webpack_main.js -o html/js/webpack_main.webpack.js
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"sourceMapPathOverrides": {
// add this map
"webpack:///./js/*": "${workspaceRoot}/js/*",
"webpack:///js/*": "${workspaceRoot}/js/*"
},
"sourceMaps": true,
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceRoot}/html"
}
]
}
launch debugger
target code: js/typescript_bubble_sort.ts, js/typescript_main.ts
use awesome-typescript-loader
and source-map-loader
module.
npm install -g webpack awesome-typescript-loader source-map-loader
ts file to compile.
const path = require("path");
let exclude = [path.resolve(__dirname, "html")];
console.log(exclude);
module.exports = {
devtool: "source-map",
output: {
path: path.resolve(__dirname, "html", "js"),
filename: "webpack.js",
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
{ test: /\.ts$/, loader: "awesome-typescript-loader", exclude },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader", exclude },
],
},
devServer: {
contentBase: "html/",
},
};
{
"compilerOptions": {
// must set output dir
"outDir": "./html/js/",
// for node_modules dir
"baseUrl": "./",
"module": "commonjs",
"target": "es2017",
// must set for debug
"sourceMap": true,
"noImplicitAny": false,
"strict": true,
"esModuleInterop": true
},
// set if you'll like to divide .ts and others
"include": ["./js/**/*"]
}
webpack -d js/typescript_main.ts -o html/js/typescript_main.js
add breakpoint to typescript code, and launch debug.