Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open static html files in default browser in Visual Studio Code

Anyone been using Visual Studio Code know if there is a way to right click and open in default browser (a la Sublime Text)? I know you can right click on the file node and "reveal in explorer" and then manually open it in a browser... but I want to save that extra 2 secs.

like image 878
davidpm4 Avatar asked Aug 29 '26 00:08

davidpm4


2 Answers

Actually both the above code opens windows file explorer not BROWSER.

I am using following code which works perfectly, opens file in Chrome, while testing a static html file with Javascript.

{
   "version": "0.1.0",
   "command": "Chrome",
   "windows": {
       "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
   },
   "args": ["${file}"]
}
like image 83
Rafique Ahmed Avatar answered Sep 01 '26 12:09

Rafique Ahmed


I've got something similar in one of my projects. I've set up my tasks.json as shown below. With that in place I can type "Ctrl+P then type "task start" and hit enter to load the current HTML file in the default browser :-)

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process
{
    "version": "0.1.0",
    "command": "powershell",
    "isShellCommand": true,
    "suppressTaskName": true,
    "tasks": [
        // other tasks here,
        {
            "taskName": "start browser",
            "args": [
                "start", "${file}"
            ]
        }
    ]
}
like image 41
Stuart Leeks Avatar answered Sep 01 '26 13:09

Stuart Leeks