webview: respect default localResourceRoots for custom editors#312492
Merged
mjbvz merged 1 commit intomicrosoft:mainfrom May 1, 2026
Merged
webview: respect default localResourceRoots for custom editors#312492mjbvz merged 1 commit intomicrosoft:mainfrom
mjbvz merged 1 commit intomicrosoft:mainfrom
Conversation
Custom-editor flow constructs the webview overlay on the main thread with empty contentOptions and never propagates the documented default localResourceRoots (workspace folders + extension install directory), so asWebviewUri returns 401 unless the extension explicitly sets webview.options. The regular createWebviewPanel flow already applies this default in ExtHostWebviewPanels.createWebviewPanel. Add ExtHostWebviews.ensureDefaultContentOptions which calls $setOptions with the documented default when localResourceRoots is absent, and invoke it from $resolveCustomEditor right after createNewWebview. Fixes microsoft#282495
bpasero
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #282495
Problem
Per the
WebviewOptions.localResourceRootsdocs, if the option is left unset the webview should default to allowing the workspace folder roots plus the extension's install directory.vscode.window.createWebviewPanelhonors this contract —ExtHostWebviewPanels.createWebviewPanelfills in the default before the create RPC.Custom editors do not. The main thread builds the overlay with
contentOptions: {}and then calls$resolveCustomEditoron the extension host. Because the extension host never receives a chance to fill in the default,asWebviewUrireturns HTTP 401 for resources under the workspace or the extension folder unless the extension explicitly setswebview.options = { localResourceRoots: [...] }. This silently breaks custom-editor extensions that follow the documented default.Fix
Added
ExtHostWebviews.ensureDefaultContentOptions(handle, contentOptions, extension). WhencontentOptions.localResourceRootsisundefined, it calls$setOptionswith the documented default (workspace folders + extension install directory, mirroring the logic inExtHostWebviewPanels.createWebviewPanel). When the extension provided explicit roots — including an empty array — the helper does nothing.MainThreadCustomEditors.$resolveCustomEditorinvokes the helper fromExtHostCustomEditorsimmediately aftercreateNewWebview, before the provider'sresolveCustomTextEditor/resolveCustomEditorruns. Existingwebview.options = ...assignments inside provider callbacks continue to work — those go throughserializeWebviewOptions, which already re-applies the default.Tests
Added three unit tests in
src/vs/workbench/api/test/browser/extHostWebview.test.ts:localResourceRootsis omittedlocalResourceRoots(even[]) is respected —$setOptionsis not called