From 4fad82e94d9963d185c58ae526dbe0afe79efcee Mon Sep 17 00:00:00 2001 From: yogeshwaran-c Date: Sun, 5 Apr 2026 16:19:11 +0530 Subject: [PATCH] feat: add Simple Browser: Focus Content command Adds a new command that moves focus directly to the browser content/webview, bypassing the URL bar. This improves accessibility for screen reader users who need a more efficient way to navigate into the browser content. Fixes #305717 --- extensions/simple-browser/package.json | 10 ++++++++++ extensions/simple-browser/package.nls.json | 1 + extensions/simple-browser/src/extension.ts | 5 +++++ extensions/simple-browser/src/simpleBrowserManager.ts | 4 ++++ extensions/simple-browser/src/simpleBrowserView.ts | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/extensions/simple-browser/package.json b/extensions/simple-browser/package.json index bf4dfcb250ae5..13739e5dbf9b3 100644 --- a/extensions/simple-browser/package.json +++ b/extensions/simple-browser/package.json @@ -24,6 +24,7 @@ ], "activationEvents": [ "onCommand:simpleBrowser.api.open", + "onCommand:simpleBrowser.focusContent", "onOpenExternalUri:http", "onOpenExternalUri:https", "onWebviewPanel:simpleBrowser.view" @@ -40,6 +41,11 @@ "command": "simpleBrowser.show", "title": "Show", "category": "Simple Browser" + }, + { + "command": "simpleBrowser.focusContent", + "title": "%command.focusContent.title%", + "category": "Simple Browser" } ], "menus": { @@ -47,6 +53,10 @@ { "command": "simpleBrowser.show", "when": "isWeb" + }, + { + "command": "simpleBrowser.focusContent", + "when": "activeWebviewPanelId == 'simpleBrowser.view'" } ] }, diff --git a/extensions/simple-browser/package.nls.json b/extensions/simple-browser/package.nls.json index 496dc28dfddf4..1458ae0fbd6e5 100644 --- a/extensions/simple-browser/package.nls.json +++ b/extensions/simple-browser/package.nls.json @@ -1,5 +1,6 @@ { "displayName": "Simple Browser", "description": "A very basic built-in webview for displaying web content.", + "command.focusContent.title": "Focus Content", "configuration.focusLockIndicator.enabled.description": "Enable/disable the floating indicator that shows when focused in the simple browser." } diff --git a/extensions/simple-browser/src/extension.ts b/extensions/simple-browser/src/extension.ts index ddcdc52b42de0..931426f2d28a9 100644 --- a/extensions/simple-browser/src/extension.ts +++ b/extensions/simple-browser/src/extension.ts @@ -14,6 +14,7 @@ declare class URL { const openApiCommand = 'simpleBrowser.api.open'; const showCommand = 'simpleBrowser.show'; +const focusContentCommand = 'simpleBrowser.focusContent'; const integratedBrowserCommand = 'workbench.action.browser.open'; const enabledHosts = new Set([ @@ -75,6 +76,10 @@ export function activate(context: vscode.ExtensionContext) { } })); + context.subscriptions.push(vscode.commands.registerCommand(focusContentCommand, () => { + manager.focusContent(); + })); + context.subscriptions.push(vscode.commands.registerCommand(openApiCommand, async (url: vscode.Uri, showOptions?: { preserveFocus?: boolean; viewColumn: vscode.ViewColumn; diff --git a/extensions/simple-browser/src/simpleBrowserManager.ts b/extensions/simple-browser/src/simpleBrowserManager.ts index ef485916411cd..2a0833d2cb14d 100644 --- a/extensions/simple-browser/src/simpleBrowserManager.ts +++ b/extensions/simple-browser/src/simpleBrowserManager.ts @@ -38,6 +38,10 @@ export class SimpleBrowserManager { this._activeView ??= view; } + public focusContent(): void { + this._activeView?.focusContent(); + } + private registerWebviewListeners(view: SimpleBrowserView) { view.onDispose(() => { if (this._activeView === view) { diff --git a/extensions/simple-browser/src/simpleBrowserView.ts b/extensions/simple-browser/src/simpleBrowserView.ts index 56c5aff5c8a52..5836db911da33 100644 --- a/extensions/simple-browser/src/simpleBrowserView.ts +++ b/extensions/simple-browser/src/simpleBrowserView.ts @@ -110,6 +110,11 @@ export class SimpleBrowserView extends Disposable { this._webviewPanel.reveal(options?.viewColumn, options?.preserveFocus); } + public focusContent() { + this._webviewPanel.reveal(undefined, false); + this._webviewPanel.webview.postMessage({ type: 'focus' }); + } + private getHtml(url: string) { const configuration = vscode.workspace.getConfiguration('simpleBrowser');