Skip to content

Commit 22f5876

Browse files
committed
[code] fix #4063: proxy fetch in web workers
1 parent babf0a4 commit 22f5876

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

components/supervisor/frontend/public/worker-proxy.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,28 @@
1515
var originalImportScripts = self.importScripts;
1616
// hash contains the original worker URL to be used as a base URI to resolve script URLs
1717
var baseURI = decodeURI(location.hash.substr(1));
18-
self.importScripts = function (scriptUrl) {
19-
return originalImportScripts(new URL(scriptUrl, baseURI).toString());
18+
19+
self.importScripts = function (...scriptUrls) {
20+
return originalImportScripts(...scriptUrls.map(scriptUrl => new URL(scriptUrl, baseURI).toString()));
21+
}
22+
23+
var originalFetch = self.fetch;
24+
self.fetch = function (input, init) {
25+
if (typeof input === 'string') {
26+
return originalFetch(new URL(input, baseURI).toString(), init);
27+
}
28+
return originalFetch(input, init);
2029
}
30+
31+
var originalRequest = self.Request;
32+
function RequestProxy(input, init) {
33+
if (typeof input === 'string') {
34+
return new originalRequest(new URL(input, baseURI).toString(), init);
35+
}
36+
return new originalRequest(input, init);
37+
}
38+
RequestProxy.prototype = Object.create(originalRequest)
39+
self.Request = RequestProxy;
40+
2141
originalImportScripts(baseURI);
2242
})();

0 commit comments

Comments
 (0)