Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open browser from Visual Studio Code API

I am just exploring a way in order to open the default browser from Visual Studio Code API used for developing extensions.

Following is my code :

var disposable = vscode.commands.registerCommand('extension.browser', () => {
  // The code you place here will be executed every time your command is executed
  vscode.Uri.call("http://facebook.com");
});

How to open Browser URL from API using vscode class.

like image 925
Shan Khan Avatar asked Dec 10 '15 15:12

Shan Khan


People also ask

How do I open the browser window in Visual Studio Code?

Using the Visual Studio Code Editor, open the desired file. Go to the toolbar on the left and select “Extensions.” Click on the search bar in the Extensions panel and write “open in browser.”

Is there a browser in VS Code?

Microsoft has now launched an official browser version of Visual Studio Code that can be found at vscode. dev. It integrates with Github allowing easy access to code stored in Github repos right from your web browser.


1 Answers

There is no need for node or external libraries.

If you are using VS Code 1.31+, use the vscode.env.open function:

import * as vscode from 'vscode';

vscode.env.openExternal(vscode.Uri.parse('https://example.com'));

For older VS Code versions, use the vscode.open command:

vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://example.com'))

Both of these will open the page in the user's default browser

like image 73
Matt Bierner Avatar answered Sep 21 '22 08:09

Matt Bierner