Skip to content

Commit 4f5bc5e

Browse files
refactor(Sky): Expand Blob patch to rewrite vscode-file:// URLs and simplify polyfill comments
Refactor the Blob constructor patch in Workbench.ts to handle VS Code worker file URLs more robustly: 1. Remove the restrictive `_VSCODE_NLS_MESSAGES` check — now applies the __name shim to all application/javascript blobs for broader compatibility 2. Add URL rewriting: convert `vscode-file://vscode-app/Static/Application/out/` paths to `${origin}/Static/Application/` so Tauri can serve VS Code assets locally 3. Simplify the three separate WKWebView polyfill comments into a single grouped comment This ensures VS Code extension workers can load assets correctly in Tauri's webview environment.
1 parent 736ca26 commit 4f5bc5e

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

Source/Workbench/Electron/Workbench.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ console.log(
6262
(window as any).vscode?.process?.env?.VSCODE_DEV,
6363
);
6464

65-
// Stubs for APIs that VS Code uses but don't exist in Tauri's WKWebView.
66-
67-
// requestIdleCallback/cancelIdleCallback: WKWebView doesn't support these.
68-
// VS Code uses them in workbench.js for deferred canvas cleanup and other
69-
// non-critical tasks. Without this polyfill, the workbench crashes on load.
65+
// WKWebView polyfills: requestIdleCallback, queryLocalFonts, __name.
7066
if (typeof window.requestIdleCallback !== "function") {
7167
(window as any).requestIdleCallback = (
7268
Callback: IdleRequestCallback,
@@ -89,14 +85,10 @@ if (typeof window.cancelIdleCallback !== "function") {
8985
};
9086
}
9187

92-
// queryLocalFonts: VS Code's fonts.js calls mainWindow.queryLocalFonts() to
93-
// enumerate system fonts. Returns empty array = VS Code falls back to defaults.
9488
if (typeof (window as any).queryLocalFonts !== "function") {
9589
(window as any).queryLocalFonts = () => Promise.resolve([]);
9690
}
9791

98-
// __name: esbuild keepNames helper used inside VS Code blob workers.
99-
// Without this, the extension host blob throws "Can't find variable: __name".
10092
if (typeof (globalThis as any).__name !== "function") {
10193
(globalThis as any).__name = (Target: any, Value: string) => {
10294
Object.defineProperty(Target, "name", {
@@ -107,15 +99,12 @@ if (typeof (globalThis as any).__name !== "function") {
10799
};
108100
}
109101

110-
// Inject __name into blob workers via Blob constructor patch (zero-cost).
111-
// VS Code's getWorkerBootstrapUrl builds blobs from string arrays. We intercept
112-
// Blob creation and prepend the __name shim to any application/javascript blob
113-
// that contains the VS Code worker marker. No XHR, no re-fetch — just string
114-
// prepend at construction time.
102+
// Blob patch: inject __name + rewrite vscode-file:// to http://localhost in worker blobs.
115103
{
116104
const OriginalBlob = globalThis.Blob;
117105
const NameShim =
118106
"var __defProp=Object.defineProperty;var __name=(t,v)=>__defProp(t,'name',{value:v,configurable:true});\n";
107+
const Origin = window.location.origin;
119108

120109
(globalThis as any).Blob = function PatchedBlob(
121110
Parts?: BlobPart[],
@@ -124,10 +113,15 @@ if (typeof (globalThis as any).__name !== "function") {
124113
if (
125114
Options?.type === "application/javascript" &&
126115
Parts?.length &&
127-
typeof Parts[0] === "string" &&
128-
Parts[0].includes("_VSCODE_NLS_MESSAGES")
116+
typeof Parts[0] === "string"
129117
) {
130-
// This is a VS Code worker bootstrap blob — prepend __name shim
118+
Parts = Parts.map((Part) => {
119+
if (typeof Part !== "string") return Part;
120+
return Part.replace(
121+
/vscode-file:\/\/vscode-app\/Static\/Application\/out\//g,
122+
`${Origin}/Static/Application/`,
123+
);
124+
});
131125
Parts = [NameShim, ...Parts];
132126
}
133127
return new OriginalBlob(Parts, Options);

0 commit comments

Comments
 (0)