Skip to content

Webview Panel with enableFindWidget does not work after Moving Editor Group into New Window #233044

Closed

Description

Does this issue occur when all extensions are disabled?: Yes - only extension is the one being developed

Version: 1.95.1 (Universal)
Commit: 65edc49
Date: 2024-10-31T05:14:54.222Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0

and

Version: 1.96.0-insider (Universal)
Commit: 231d373
Date: 2024-11-04T14:19:41.196Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 24.1.0

Steps to Reproduce:

  1. Clone the Microsoft VS Code extensions sample - webview-sample
  2. Replace src/extension.ts with:
import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
	context.subscriptions.push(
		vscode.commands.registerCommand('catCoding.start', () => {
			WebviewIssuePanel.createOrShow(context.extensionUri);
		})
	);
}

class WebviewIssuePanel {
	public static currentPanel: WebviewIssuePanel | undefined;

	public static readonly viewType = 'webviewIssue';

	private readonly _panel: vscode.WebviewPanel;
	private readonly _extensionUri: vscode.Uri;
	private _disposables: vscode.Disposable[] = [];

	public static createOrShow(extensionUri: vscode.Uri) {
		const column = vscode.window.activeTextEditor
			? vscode.window.activeTextEditor.viewColumn
			: undefined;

		if (WebviewIssuePanel.currentPanel) {
			WebviewIssuePanel.currentPanel._panel.reveal(column);
			return;
		}

		const panel = vscode.window.createWebviewPanel(
			WebviewIssuePanel.viewType,
			'Webview Issue',
			column || vscode.ViewColumn.One,
			{
				enableScripts: true,
				enableFindWidget: true,
				localResourceRoots: [vscode.Uri.joinPath(extensionUri, 'media')],
			}
		);

		WebviewIssuePanel.currentPanel = new WebviewIssuePanel(panel, extensionUri);
	}

	public static revive(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
		WebviewIssuePanel.currentPanel = new WebviewIssuePanel(panel, extensionUri);
	}

	private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
		this._panel = panel;
		this._extensionUri = extensionUri;

		this._panel.title = 'Webview Issue';
		this._panel.webview.html = this._getHtmlForWebview(this._panel.webview);

		this._panel.onDidDispose(() => this.dispose(), null, this._disposables);
	}

	public dispose() {
		WebviewIssuePanel.currentPanel = undefined;
		this._panel.dispose();

		while (this._disposables.length) {
			const x = this._disposables.pop();
			if (x) {
				x.dispose();
			}
		}
	}

	private _getHtmlForWebview(webview: vscode.Webview) {
		// Use a nonce to only allow specific scripts to be run
		const nonce = getNonce();

		return `<!DOCTYPE html>
			<html lang="en">
			<head>
				<meta charset="UTF-8">

				<!--
					Use a content security policy to only allow loading images from https or from our extension directory,
					and only allow scripts that have a specific nonce.
				-->
				<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${webview.cspSource}; img-src ${webview.cspSource} https:; script-src 'nonce-${nonce}';">

				<meta name="viewport" content="width=device-width, initial-scale=1.0">

				<title>Webview Issue</title>
			</head>
			<body>
				Text to search for
			</body>
			</html>`;
	}
}

function getNonce() {
	let text = '';
	const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
	for (let i = 0; i < 32; i++) {
		text += possible.charAt(Math.floor(Math.random() * possible.length));
	}
	return text;
}
  1. Start the sample and run Cat Coding: Start cat coding session
  2. Use Ctrl-F to search for text, you will see it correctly highlighted:

Image

  1. Run View: Move Editor Group into New Window command to open the webview in a new window
  2. Use Ctrl-F to search for text, you will see it does not highlight:

Image

Activity

  1. added
    help wanted
    webview
    bug
    on Dec 10, 2024
  2. added this to the Backlog milestone on Dec 10, 2024
  3. added a commit that references this issue on Oct 2, 2025
    500a1e7
  4. added a commit that references this issue on Sep 23, 2026
    9cc2a44
  5. added
    unreleased
    on Sep 23, 2026
  6. added
    insiders-released
    and removed
    unreleased
    on Sep 23, 2026
  7. added a commit that references this issue on Sep 23, 2026
    a8fc433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bughelp wantedinsiders-releasedverifiedwebview

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions