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.
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.”
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With