Skip to content

Commit b62a68a

Browse files
authored
fix: webviews failing to load the iframe HTML (#5103)
Code added in 1.65.0 broke webviews when you are hosting them from the same domain.
1 parent e7e6c16 commit b62a68a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: patches/webview.diff

+30
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ self-hosted.
66
When doing this CSP will block resources (for example when viewing images) so
77
add 'self' to the CSP to fix that.
88

9+
Additionally the service worker defaults to handling *all* requests made to the
10+
current host but when self-hosting the webview this will end up including the
11+
webview HTML itself which means these requests will fail since the communication
12+
channel between the webview and the main thread has not been set up yet as the
13+
webview itself is not ready yet (it has no HTML and therefore no script either).
14+
Since this code exists only for the authentication case we can just skip it when
15+
it is served from the current host as authentication is not a problem if the
16+
request is not cross-origin.
17+
18+
To test, open a few types of webviews (images, markdown, extension details, etc).
19+
920
Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
1021
===================================================================
1122
--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
@@ -44,3 +55,22 @@ Index: code-server/lib/vscode/src/vs/workbench/common/webview.ts
4455

4556
/**
4657
* Construct a uri that can load resources inside a webview
58+
Index: code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
59+
===================================================================
60+
--- code-server.orig/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
61+
+++ code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
62+
@@ -188,9 +188,11 @@ sw.addEventListener('fetch', (event) =>
63+
}
64+
}
65+
66+
- // If we're making a request against the remote authority, we want to go
67+
- // back through VS Code itself so that we are authenticated properly
68+
- if (requestUrl.host === remoteAuthority) {
69+
+ // If we're making a request against the remote authority, we want to go back
70+
+ // through VS Code itself so that we are authenticated properly. If the
71+
+ // service worker is hosted on the same origin we will have cookies and
72+
+ // authentication will not be an issue.
73+
+ if (requestUrl.origin !== sw.origin && requestUrl.host === remoteAuthority) {
74+
switch (event.request.method) {
75+
case 'GET':
76+
case 'HEAD':

0 commit comments

Comments
 (0)