2

How to 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?

I tried to manage the task.json file as:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Chrome",
            "type": "process",
            "command": "chrome.exe",
            "windows": {
            "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
            },
            "args": [
               "${index.html}"
            ],
            "problemMatcher": []
        }
   ]
}

also i installed the View In Browser extenstion for VSCode, but also nothing happend.

1

1 Answer 1

1

Change your "args" option to something like:

"args": [
    "${workspaceRoot}/index.html"
],

You may need more directories to get to your index.html, I don't know your folder structure. But if index.html is in the root of your workspace the above will work.

Of course with this method you are not actually serving your web page or watching for changes to css, js or html so you would need to refresh your browser each time to see any changes.

Sign up to request clarification or add additional context in comments.

2 Comments

we should use double backslash " \\" to avoid the escape character warning in VSC: "${C:\\Users\\Toshiba\\gamelayout\\index.html}"
I didn't get any warning when I tested this exact code but I am glad you have it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.