How to attach the VSCode debugger to the Brave browser?

10,536

Solution 1

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

Solution 2

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}"
}

Solution 3

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",

Solution 4

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 :

  1. 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)
  2. 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.

Solution 5

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}"
        }
    ]
}
Share:
10,536
Stephane
Author by

Stephane

A code writing dinosaur from the no-internet age

Updated on June 04, 2022

Comments

  • Stephane
    Stephane almost 2 years

    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.