How to attach the VSCode debugger to the Brave browser? - google-chrome

When I open my web application in the Chrome browser I can attach the VSCode debugger to it.
The debugger configuration is:
{
"name": "Attach to Chrome",
"type": "chrome",
"request": "attach",
"port": 9222,
"url": "http://localhost:4200/*",
"webRoot": "${workspaceFolder}",
},
But when I open the web application in the Brave browser I cannot attach the VSCode debugger.
The web application is an Angular one opened at http://localhost:4200/users
I'm running:
Chrome Version 70.0.3538.102 (Build officiel) (64 bits)
Brave Version 0.56.12 Chromium: 70.0.3538.77 (Build officiel) (64 bits)
VSCode Version 1.23.0
on a Lubuntu 16.04 box.
Is the Brave browser not yet ready for debugging ? Or is there some port restriction I should remove ? I have put the shiled down for this web application. But VSCode still does not attach to it.

For MacOS users
I was able to connect to create a configuration in launch.json so that the Brave browser launches on MacOS. I appended the "userData": true property because I was getting an error. I figured that out by looking at this page. https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome
{
"type": "chrome",
"request": "launch",
"name": "Brave",
"runtimeExecutable": "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
"userDataDir": true,
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}

A little late but....
get brave-dev following this
then add to your launch.json a "runtimeExecutable": "/usr/bin/brave" entry and change the path that suits you.
rest of the settings can be default

The DEV version of Brave is not necessary.
In your Brave browser, under "chrome://settings/privacy", enable the "Remote debugging" option.
Restart your browser.
If not done yet, add to your launch.json file this (adjust your path if it is not the same)
"runtimeExecutable": "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe",

As mentioned in the other answers, you need to add a "runtimeExecutable" field in the launch.json file of your project that will point to the executable of Brave Browser.
... but ...
You also need to launch the browser with the following option : --remote-debugging-port=9222
You have 2 ways to do it :
Launching Brave with the option (Windows : Right click the Brave shortcut, and select properties, and in the "target" field, append --remote-debugging-port=9222, MacOS / linux : execute <path to brave>/brave --remote-debugging-port=9222) (reminder : don't forget to relaunch Brave)
Following Cornelius suggestion, you can simply add the following to your launch.json :
"runtimeArgs": [ "--remote-debugging-port=9222" ]
This second option applies ONLY if you have the request: "launch" option, not the request: "attach" one, and if you want to use the "lauch" option, it will open another Brave window, not a new tab. So you'll probably want to use the first method in the long run.

For those that need to see full code context, here is my complete launch.json file. The second item in the "configurations" array causes brave's dev browser to open for debugging (you can download the Brave dev browser here)
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
{
"type": "chrome",
"request": "launch",
"name": "Brave",
"runtimeExecutable": "C:/Program Files (x86)/BraveSoftware/Brave-Browser-Dev/Application/brave.exe",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
}

Brave install with APT package manager on Running Ubuntu 20.04
Add this line to the standard launch.json generated for chrome:
"runtimeExecutable": "/usr/bin/brave-browser"
Here is how the whole launch.json looks. If you want to copy this just make sure file points to the right location.
{
// 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": "pwa-chrome",
"request": "launch",
"name": "Open index.html",
"file": "/home/my-user/myDirectory/index.html",
"runtimeExecutable": "/usr/bin/brave-browser"
}
]
}

Steps to follow:
Open vs code.
wait for sec. bez it take time to open vs code
see left side Search icon.
click on it and type Setting.
see down click on Open setting.
Browser.
"liveServer.settings.AdvanceCustomBrowserCmdLine": "brave
or try this:
.vscode\settings.json:
{
"liveServer.settings.AdvanceCustomBrowserCmdLine": "brave"
}

Related

ECONNREFUSED error with WSL 2 with Chrome Debugger on VSCode

I'm on a Windows 10 machine, VS Code with WSL 2 (Ubuntu 18.04) trying to use the Chrome debugger extension, but to no avail. The following is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch index.html",
"type": "chrome",
"request": "launch",
"file": "${workspaceFolder}/index.html",
"runtimeExecutable": "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
"runtimeArgs": [" --remote-debugging-port=9222"],
"userDataDir": "${workspaceFolder}/chrome",
"port": 9222
},
]
}
I was expecting to see my index.html page loaded in a new Chrome tab whenever I press F5, but all it does is start a new, blank Chrome window and then two errors pop up about 15 seconds apart.
I'm less concerned about the first error, which says Google Chrome cannot read and write to its data directory: <VALID-DIRECTORY-ON-MY-MACHINE>. What I have been trying to address for the past day and a half is the second error, which says
Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9222)
I tried a lot of the solutions on Stack, GitHub, VS Code dev site etc. but nothing helps. On my Chrome browser, http://localhost:9222/json throws out some content which I understood to mean that the browser should be available for connection:
[ {
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/E7E1DFE661F744BE79A572564251BC39",
"id": "E7E1DFE661F744BE79A572564251BC39",
"title": "New Tab",
"type": "page",
"url": "http://localhost:9222/json",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/E7E1DFE661F744BE79A572564251BC39"
}, {
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/C089932CAB5A26F4409B78F887C84A50",
"id": "C089932CAB5A26F4409B78F887C84A50",
"title": "about:blank",
"type": "page",
"url": "about:blank",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/C089932CAB5A26F4409B78F887C84A50"
} ]
In addition, I've also set in my settings.json: "remote.extensionKind": {"msjsdiag.debugger-for-chrome": "workspace"} based on this recommendation. I've also restarted my machine, start VS Code and then launch (without opening any other Chrome windows).
It seems that all the things that were supposed to work doesn't, which meant that I could be misunderstanding something here. My question is, is there something that I'm doing incorrectly here?
It is a bug of vscode. This issue can be fixed by replacing extensions 'JavaScript Debugger' with 'JavaScript Debugger (Nightly)'.
See: https://github.com/microsoft/vscode/issues/120227

Debug Angular-CLI app accross Visual Studio Code not on localhost:4200

All!
How enable debug mode in Visual Studio Code for Angular-CLI application with arbitrary url.
With default ng serve url (localhost:4200) it works fine.
With another url breakpoints are set but not bound.
Here's vscode launch.config
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:///./*":"${workspaceRoot}/*"
},
"url": "http://localhost/CountrySite/v2/",
"webRoot": "${workspaceRoot}"
},
app folder structure
Thanks
The reason was in 401 response for js-sourcemaps returned from web server.
Solved

Visual studio code launches chrome with no extensions or autofill data [duplicate]

This question already has answers here:
run vscode chrome debugger with its extensions
(2 answers)
Closed 3 years ago.
I've recently started using chrome debugging for visual studio code on an angular project.
I've followed all the configuration steps described here and I'm able to successfully launch chrome against localhost, place breakpoints on VS Code and debug my code from there.
The issue is that the instance of chrome that VS Code launches does not have any of my chrome extensions, no auto fill information available and maybe even more things are missing.
Here is my launch.jsoncode:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
}
How may I configure VS Code to launch a chrome instance with everything that I would usually have available on chrome?
After struggling for some time, I've found a way to make it work. I've modified my launch config to also set userDataDir field to false:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"userDataDir": false
}
]
}
This will open chrome with all extensions enabled and autofill data available. Still, this only works if there is no chrome instance currently running.

Coldfusion at VScode localhost refused 8080

I wrote code with Visual Studio Code. When I try to debug my code, Chrome debug doesn't allow the to connection localhost. How to fix the debug settings with launch.json setting?
launch.json code
// 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:8080",
"webRoot": "${workspaceFolder}"
}
]
}
http://localhost-8080.com/ refused to connection with Chrome
But CF is adobe cold fusion and adobe has no work with this

How to view an HTML file in the browser with Visual Studio Code

How can I view my HTML code in a browser with the new Microsoft Visual Studio Code?
With Notepad++ you have the option to Run in a browser. How can I do the same thing with Visual Studio Code?
For Windows - Open your Default Browser - Tested on VS Code v 1.1.0
Answer to both opening a specific file (name is hard-coded) OR opening ANY other file.
Steps:
Use ctrl + shift + p (or F1) to open the Command Palette.
Type in Tasks: Configure Task or on older versions Configure Task Runner. Selecting it will open the tasks.json file. Delete the script displayed and replace it by the following:
{
"version": "0.1.0",
"command": "explorer",
"windows": {
"command": "explorer.exe"
},
"args": ["test.html"]
}
Remember to change the "args" section of the tasks.json file to the name of your file. This will always open that specific file when you hit F5.
You may also set the this to open whichever file you have open at the time by using ["${file}"] as the value for "args". Note that the $ goes outside the {...}, so ["{$file}"] is incorrect.
Save the file.
Switch back to your html file (in this example it's "text.html"), and press ctrl + shift + b to view your page in your Web Browser.
VS Code has a Live Server Extension that supports one click launch from status bar.
Some of the features:
One Click Launch from Status Bar
Live Reload
Support for Chrome Debugging Attachment
#InvisibleDev - to get this working on a mac trying using this:
{
"version": "0.1.0",
"command": "Chrome",
"osx": {
"command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
},
"args": [
"${file}"
]
}
If you have chrome already open, it will launch your html file in a new tab.
Open Extensions Sidebar (Ctrl + Shift + X)
Search for open in browser and install it
Right click on your html file, and select "Open in Browser" (Alt + B)
If you would like to have live reload you can use gulp-webserver, which will watch for your file changes and reload page, this way you don't have to press F5 every time on your page:
Here is how to do it:
Open command prompt (cmd) and type
npm install --save-dev gulp-webserver
Enter Ctrl+Shift+P in VS Code and type Configure Task Runner. Select it and press enter. It will open tasks.json file for you. Remove everything from it end enter just following code
tasks.json
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "webserver",
"isBuildCommand": true,
"showOutput": "always"
}
]
}
In the root directory of your project add gulpfile.js and enter following code:
gulpfile.js
var gulp = require('gulp'),
webserver = require('gulp-webserver');
gulp.task('webserver', function () {
gulp.src('app')
.pipe(webserver({
livereload: true,
open: true
}));
});
Now in VS Code enter Ctrl+Shift+P and type "Run Task" when you enter it you will see your task "webserver" selected and press enter.
Your webserver now will open your page in your default browser. Now any changes that you will do to your HTML or CSS pages will be automatically reloaded.
Here is an information on how to configure 'gulp-webserver' for instance port, and what page to load, ...
You can also run your task just by entering Ctrl+P and type task webserver
You can now install an extension View In Browser. I tested it on windows with chrome and it is working.
vscode version: 1.10.2
Click on this Left-Bottom Manage Icon. Click Extensions or Short Cut Ctrl+Shift+X
Then Search in Extension with this key sentence Open In Default Browser. You will find this Extension. It is better to me.
Now right click on the html file and you will see Open in Default Browser or Short Cut Ctrl+1 to see the html file in browser.
Here is a 2.0.0 version for the current document in Chrome w/ keyboard shortcut:
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Chrome",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
},
"args": [
"${file}"
],
"problemMatcher": []
}
]
}
keybindings.json :
{
"key": "ctrl+g",
"command": "workbench.action.tasks.runTask",
"args": "Chrome"
}
For running on a webserver:
https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
In linux, you can use the xdg-open command to open the file with the default browser:
{
"version": "0.1.0",
"linux": {
"command": "xdg-open"
},
"isShellCommand": true,
"showOutput": "never",
"args": ["${file}"]
}
I am just re-posting the steps I used from msdn blog. It may help the community.
This will help you to
setup a local web server known as lite-server with VS Code, and also guides you to host your static html files in localhost and debug your Javascript code.
1. Install Node.js
If not already installed, get it here
It comes with npm (the package manager for acquiring and managing your development libraries)
2. Create a new folder for your project
Somewhere in your drive, create a new folder for your web app.
3. Add a package.json file to the project folder
Then copy/paste the following text:
{
"name": "Demo",
"version": "1.0.0",
"description": "demo project.",
"scripts": {
"lite": "lite-server --port 10001",
"start": "npm run lite"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.5.4"
}
}
4. Install the web server
In a terminal window (command prompt in Windows) opened on your project folder, run this command:
npm install
This will install lite-server (defined in package.json), a static server that loads index.html in your default browser and auto refreshes it when application files change.
5. Start the local web server!
(Assuming you have an index.html file in your project folder).
In the same terminal window (command prompt in Windows) run this command:
npm start
Wait a second and index.html is loaded and displayed in your default browser served by your local web server!
lite-server is watching your files and refreshes the page as soon as you make changes to any html, js or css files.
And if you have VS Code configured to auto save (menu File / Auto Save), you see changes in the browser as you type!
Notes:
Do not close the command line prompt until you’re done coding in your
app for the day
It opens on http://localhost:10001 but you can change the port by
editing the package.json file.
That’s it. Now before any coding session just type npm start and you are good to go!
Originally posted here in msdn blog.
Credits goes to Author : #Laurent Duveau
There's now an official extension from the VS Code team called "Live Preview"
Quick setup:
Install "Live Preview" extension from Microsoft.
Open a html file from the workspace, files outside current workspace don't work.
Run command > Live Preview: Show Preview (External Browser)
There's also a command for launching it in the internal browser. You might also need to change the default port from the extension settings in case it's already in use on your system.
Documentation: https://marketplace.visualstudio.com/items?itemName=ms-vscode.live-server
Release notes: https://code.visualstudio.com/updates/v1_59#_live-preview
If you're just on Mac this tasks.json file:
{
"version": "0.1.0",
"command": "open",
"args": ["${file}"],
}
...is all you need to open the current file in Safari, assuming its extension is ".html".
Create tasks.json as described above and invoke it with ⌘+shift+b.
If you want it to open in Chrome then:
{
"version": "0.1.0",
"command": "open",
"args": ["-a", "Chrome.app", "${file}"],
}
This will do what you want, as in opening in a new tab if the app is already open.
For Mac - Opens in Chrome - Tested on VS Code v 1.9.0
Use Command + shift + p to open the Command Palette.
Type in Configure Task Runner, the first time you do this, VS Code will give you the scroll down menu, if it does select "Other." If you have done this before, VS Code will just send you directly to tasks.json.
Once in the tasks.json file. Delete the script displayed and replace it by the following:
{
"version": "0.1.0",
"command": "Chrome",
"osx": {
"command": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
},
"args": ["${file}"]
}
Switch back to your html file and press Command + Shift + b to view your page in Chrome.
One click solution simply install open-in-browser Extensions from the Visual Studio marketplace.
CTRL+SHIFT+P will bring up the command palette.
Depending on what you're running of course. Example in an ASP.net app you can type in:
>kestrel and then open up your web browser and type in localhost:(your port here).
If you type in > it will show you the show and run commands
Or in your case with HTML, I think F5 after opening the command palette should open the debugger.
Source: link
Openning files in Opera browser (on Windows 64 bits). Just add this lines:
{
"version": "0.1.0",
"command": "opera",
"windows": {
"command": "///Program Files (x86)/Opera/launcher.exe"
},
"args": ["${file}"] }
Pay attention to the path format on "command": line. Don't use the "C:\path_to_exe\runme.exe" format.
To run this task, open the html file you want to view, press F1, type task opera and press enter
my runner script looks like :
{
"version": "0.1.0",
"command": "explorer",
"windows": {
"command": "explorer.exe"
},
"args": ["{$file}"]
}
and it's just open my explorer when I press ctrl shift b in my index.html file
here is how you can run it in multiple browsers for windows
{
"version": "0.1.0",
"command": "cmd",
"args": ["/C"],
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"tasks": [
{
"taskName": "Chrome",
"args": ["start chrome -incognito \"${file}\""]
},
{
"taskName": "Firefox",
"args": ["start firefox -private-window \"${file}\""]
},
{
"taskName": "Edge",
"args": ["${file}"]
}
]
}
notice that I didn't type anything in args for edge because Edge is my default browser just gave it the name of the file.
EDIT: also you don't need -incognito nor -private-window...it's just me I like to view it in a private window
Yet another extension for previewing HTML files, called Live Preview. Couple reasons why I like it over the "Live Server" linked in this answer.
no need to start server, preview icon is integrated to into VS code (same as for mark down preview)
preview is opened within the VS code in split view (although option to open in browser is available)
developed by Microsoft (the same company developing VS code)
currently the "Live Preview" is in "Preview", just prefect :-)
Here is the version 2.0.0 for Mac OSx:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo Hello"
},
{
"label":"chrome",
"type":"process",
"command":"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"args": [
"${file}"
]
}
]
}
For Mac, set your tasks.json (in the .vscode folder) file contents to the following and use SHFT+COMMAND+B to open.
{
"version": "2.0.0",
"tasks": [
{
"label": "Chrome Preview",
"type": "shell",
"command": "open -a /Applications/Google\\ Chrome.app test.html",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Following worked in version 1.53.2 on windows 10 ->
choose run active file in terminal menu
It executed the html file in default edge browser
The Live Preview extension has just added (in Insiders Build now and Stable early February 2023) the ability to change the default browser that is opened (when you choose to open it in an external browser rather than as another tab within vscode). See Add option to choose default external browser.
The setting is
Live Preview: Custom External Browser
livePreview.customExternalBrowser
Options: Edge, Chrome, Firefox, none
none will use whatever you have set as your default browser in your operating system. The new setting allows you to override that default setting with another browser for the purposes of the Live Preview extension opening an external browser, via the command:
Live Preview: Show Preview (External Browser)
Ctrl + F1 will open the default browser. alternatively you can hit Ctrl + shift + P to open command window and select "View in Browser". The html code must be saved in a file (unsaved code on the editor - without extension, doesn't work)
probably most will be able to find a solution from the above answers but seeing as how none worked for me (vscode v1.34) i thought i'd share my experience. if at least one person finds it helpful then, cool not a wasted post, amiirte?
anyway, my solution (windows) is built a-top of #noontz's. his configuration may have been sufficient for older versions of vscode but not with 1.34 (at least, i couldn't get it working ..).
our configs are nearly identical save a single property -- that property being, the group property. i'm not sure why but without this, my task would not even appear in the command palette.
so. a working tasks.json for windows users running vscode 1.34:
{
"version": "2.0.0",
"tasks": [
{
"label": "Chrome",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
},
"args": [
"${file}"
],
"group": "build",
"problemMatcher": []
}
]
}
note that the problemMatcher property is not required for this to work but without it an extra manual step is imposed on you. tried to read the docs on this property but i'm too thick to understand. hopefully someone will come about and school me but yeah, thanks in advance for that. all i know is -- include this property and ctrl+shift+b opens the current html file in a new chrome tab, hassle free.
easy.
Open custom Chrome with URL from prompt
{
"version": "2.0.0",
"tasks": [
{
"label": "Open Chrome",
"type": "process",
"windows": {
"command": "${config:chrome.executable}"
},
"args": ["--user-data-dir=${config:chrome.profileDir}", "${input:url}"],
"problemMatcher": []
}
],
"inputs": [
{
"id": "url",
"description": "Which URL?",
"default": "http://localhost:8080",
"type": "promptString"
}
]
}
Open custom Chrome with active file
{
"label": "Open active file in Chrome",
"type": "process",
"command": "chrome.exe",
"windows": {
"command": "${config:chrome.executable}"
},
"args": ["--user-data-dir=${config:chrome.profileDir}", "${file}"],
"problemMatcher": []
},
Notes
if necessary, replace windows property by other OS
replace ${config:chrome.executable} with your custom chrome location, e.g. "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
replace ${config:chrome.profileDir} with your custome chrome profile directory, e.g.
"C:/My/Data/chrome/profile" or leave it out
You can keep the variables like above if you want. To do so, add following entries in settings.json - user or workspace - , adjust paths to your needs:
"chrome.executable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
"chrome.profileDir": "C:/My/Data/chrome/profile"
You could re-use these variables e.g. in launch.json for debugging purposes: "runtimeExecutable": "${config:chrome.executable}"
VSCode Task - Open by App bundle identifier (macOS only).
{
"version": "2.0.0",
"tasks": [
{
"label": "Open In: Firefox DE",
"type": "process",
"command": "open",
"args": ["-b", "org.mozilla.firefoxdeveloperedition", "${file}"],
"group": "build",
"problemMatcher": [],
"presentation": {
"panel": "shared",
"focus": false,
"clear": true,
"reveal": "never",
}
}
]
}
Recently came across this feature in one of the visual studio code tutorial in www.lynda.com
Press Ctrl + K followed by M, it will open the "Select Language Mode" ( or click on the right hand bottom corner that says HTML before that smiley ), type markdown and press enter
Now Press Ctrl + K followed by V, it will open your html in a near by tab.
Tadaaa !!!
Now emmet commands were not working in this mode in my html file, so I went back to the original state ( note - html tag tellisense were working perfectly )
To go to original state - Press Ctrl + K followed by M, select auto-detect. emmet commands started to work. If you are happy with html only viewer, then there is no need for you to come back to the original state.
Wonder why vscode is not having html viewer option by default, when it is able to dispaly the html file in the markdown mode.
Start the local web server!
(Assuming you have an index.html file in your project folder).
In the same terminal window (command prompt in Windows) run this command:
npm start