Skip to content

Commit efaa9c3

Browse files
authored
Merge pull request microsoft#131967 from microsoft/joh/fix/131902
patch XMLHttpRequest and (partially) fetch to massage uris
2 parents 1dd5ec7 + e0384e5 commit efaa9c3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/vs/workbench/services/extensions/worker/extensionHostWorker.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { URI } from 'vs/base/common/uri';
2323

2424
declare function postMessage(data: any, transferables?: Transferable[]): void;
2525

26+
declare type _Fetch = typeof fetch;
27+
2628
declare namespace self {
2729
let close: any;
2830
let postMessage: any;
@@ -32,6 +34,8 @@ declare namespace self {
3234
let indexedDB: { open: any, [k: string]: any };
3335
let caches: { open: any, [k: string]: any };
3436
let importScripts: any;
37+
let fetch: _Fetch;
38+
let XMLHttpRequest: any;
3539
}
3640

3741
const nativeClose = self.close.bind(self);
@@ -40,6 +44,27 @@ self.close = () => console.trace(`'close' has been blocked`);
4044
const nativePostMessage = postMessage.bind(self);
4145
self.postMessage = () => console.trace(`'postMessage' has been blocked`);
4246

47+
const nativeFetch = fetch.bind(self);
48+
self.fetch = function (input, init) {
49+
if (input instanceof Request) {
50+
// Request object - massage not supported
51+
return nativeFetch(input, init);
52+
}
53+
if (/^file:/i.test(String(input))) {
54+
input = FileAccess.asBrowserUri(URI.parse(String(input))).toString(true);
55+
}
56+
return nativeFetch(input, init);
57+
};
58+
59+
self.XMLHttpRequest = class extends XMLHttpRequest {
60+
override open(method: string, url: string | URL, async?: boolean, username?: string | null, password?: string | null): void {
61+
if (/^file:/i.test(url.toString())) {
62+
url = FileAccess.asBrowserUri(URI.parse(url.toString())).toString(true);
63+
}
64+
return super.open(method, url, async ?? true, username, password);
65+
}
66+
};
67+
4368
self.importScripts = () => { throw new Error(`'importScripts' has been blocked`); };
4469

4570
// const nativeAddEventListener = addEventListener.bind(self);

0 commit comments

Comments
 (0)