Support additional actions in integrated browser (#287653)

* Add setting to redirect simple browser

* Open in external browser

* Open settings

* Move to new window

* clean

* Add element shortcut

* Menu item updates

* PR feedback
This commit is contained in:
Kyle Cutler
2026-01-14 12:43:16 -08:00
committed by GitHub
parent 7341d1baed
commit 4e9b0b7fc3
6 changed files with 199 additions and 54 deletions

View File

@@ -14,6 +14,8 @@ declare class URL {
const openApiCommand = 'simpleBrowser.api.open';
const showCommand = 'simpleBrowser.show';
const integratedBrowserCommand = 'workbench.action.browser.open';
const useIntegratedBrowserSetting = 'simpleBrowser.useIntegratedBrowser';
const enabledHosts = new Set<string>([
'localhost',
@@ -31,6 +33,27 @@ const enabledHosts = new Set<string>([
const openerId = 'simpleBrowser.open';
/**
* Checks if the integrated browser should be used instead of the simple browser
*/
async function shouldUseIntegratedBrowser(): Promise<boolean> {
const config = vscode.workspace.getConfiguration();
if (!config.get<boolean>(useIntegratedBrowserSetting, false)) {
return false;
}
// Verify that the integrated browser command is available
const commands = await vscode.commands.getCommands(true);
return commands.includes(integratedBrowserCommand);
}
/**
* Opens a URL in the integrated browser
*/
async function openInIntegratedBrowser(url?: string): Promise<void> {
await vscode.commands.executeCommand(integratedBrowserCommand, url);
}
export function activate(context: vscode.ExtensionContext) {
const manager = new SimpleBrowserManager(context.extensionUri);
@@ -43,6 +66,10 @@ export function activate(context: vscode.ExtensionContext) {
}));
context.subscriptions.push(vscode.commands.registerCommand(showCommand, async (url?: string) => {
if (await shouldUseIntegratedBrowser()) {
return openInIntegratedBrowser(url);
}
if (!url) {
url = await vscode.window.showInputBox({
placeHolder: vscode.l10n.t("https://example.com"),
@@ -55,11 +82,15 @@ export function activate(context: vscode.ExtensionContext) {
}
}));
context.subscriptions.push(vscode.commands.registerCommand(openApiCommand, (url: vscode.Uri, showOptions?: {
context.subscriptions.push(vscode.commands.registerCommand(openApiCommand, async (url: vscode.Uri, showOptions?: {
preserveFocus?: boolean;
viewColumn: vscode.ViewColumn;
}) => {
manager.show(url, showOptions);
if (await shouldUseIntegratedBrowser()) {
await openInIntegratedBrowser(url.toString(true));
} else {
manager.show(url, showOptions);
}
}));
context.subscriptions.push(vscode.window.registerExternalUriOpener(openerId, {
@@ -74,10 +105,14 @@ export function activate(context: vscode.ExtensionContext) {
return vscode.ExternalUriOpenerPriority.None;
},
openExternalUri(resolveUri: vscode.Uri) {
return manager.show(resolveUri, {
viewColumn: vscode.window.activeTextEditor ? vscode.ViewColumn.Beside : vscode.ViewColumn.Active
});
async openExternalUri(resolveUri: vscode.Uri) {
if (await shouldUseIntegratedBrowser()) {
await openInIntegratedBrowser(resolveUri.toString(true));
} else {
return manager.show(resolveUri, {
viewColumn: vscode.window.activeTextEditor ? vscode.ViewColumn.Beside : vscode.ViewColumn.Active
});
}
}
}, {
schemes: ['http', 'https'],