Skip to content

Commit

Permalink
Merge pull request #131967 from microsoft/joh/fix/131902
Browse files Browse the repository at this point in the history
patch XMLHttpRequest and (partially) fetch to massage uris
  • Loading branch information
jrieken authored Aug 31, 2021
2 parents 1dd5ec7 + e0384e5 commit efaa9c3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/vs/workbench/services/extensions/worker/extensionHostWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { URI } from 'vs/base/common/uri';

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

declare type _Fetch = typeof fetch;

declare namespace self {
let close: any;
let postMessage: any;
Expand All @@ -32,6 +34,8 @@ declare namespace self {
let indexedDB: { open: any, [k: string]: any };
let caches: { open: any, [k: string]: any };
let importScripts: any;
let fetch: _Fetch;
let XMLHttpRequest: any;
}

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

const nativeFetch = fetch.bind(self);
self.fetch = function (input, init) {
if (input instanceof Request) {
// Request object - massage not supported
return nativeFetch(input, init);
}
if (/^file:/i.test(String(input))) {
input = FileAccess.asBrowserUri(URI.parse(String(input))).toString(true);
}
return nativeFetch(input, init);
};

self.XMLHttpRequest = class extends XMLHttpRequest {
override open(method: string, url: string | URL, async?: boolean, username?: string | null, password?: string | null): void {
if (/^file:/i.test(url.toString())) {
url = FileAccess.asBrowserUri(URI.parse(url.toString())).toString(true);
}
return super.open(method, url, async ?? true, username, password);
}
};

self.importScripts = () => { throw new Error(`'importScripts' has been blocked`); };

// const nativeAddEventListener = addEventListener.bind(self);
Expand Down

0 comments on commit efaa9c3

Please sign in to comment.