Skip to content

fix: webviews failing to load the iframe HTML #5103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions patches/webview.diff
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ self-hosted.
When doing this CSP will block resources (for example when viewing images) so
add 'self' to the CSP to fix that.

Additionally the service worker defaults to always trying to handle any requests
made to the current host but this will include the webview HTML itself which
means these requests will fail since the communication channel between the
webview and the main thread has not been set up yet so patch the service worker
to skip handling requests for other webview assets.

To test, open a few types of webviews (images, markdown, extension details, etc).

Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
===================================================================
--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
Expand Down Expand Up @@ -44,3 +52,23 @@ Index: code-server/lib/vscode/src/vs/workbench/common/webview.ts

/**
* Construct a uri that can load resources inside a webview
Index: code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
===================================================================
--- code-server.orig/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
+++ code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
@@ -188,9 +188,12 @@ sw.addEventListener('fetch', (event) =>
}
}

- // If we're making a request against the remote authority, we want to go
- // back through VS Code itself so that we are authenticated properly
- if (requestUrl.host === remoteAuthority) {
+ // If we're making a request against the remote authority, we want to go back
+ // through VS Code itself so that we are authenticated properly. Requests to
+ // other static assets in this directory (like the iframe HTML) must be
+ // fetched normally since there will not yet be a communication channel set up
+ // to retrieve them (they do not require authentication anyway).
+ if (requestUrl.host === remoteAuthority && !requestUrl.pathname.startsWith(rootPath)) {
switch (event.request.method) {
case 'GET':
case 'HEAD':