Path: blob/main/components/supervisor/frontend/public/worker-proxy.js
2500 views
/**1* Copyright (c) 2020 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56// @ts-check78/**9* The proxy (shared) worker serving from the workspace origin to fetch content from the blobserve origin.10*/1112// TODO(ak) importScripts is not going to work for module workers: https://web.dev/module-workers/13(function () {14var originalImportScripts = self.importScripts;15// hash contains the original worker URL to be used as a base URI to resolve script URLs16var baseURI = decodeURI(location.hash.substr(1));1718self.importScripts = function (...scriptUrls) {19return originalImportScripts(...scriptUrls.map((scriptUrl) => new URL(scriptUrl, baseURI).toString()));20};2122var originalFetch = self.fetch;23self.fetch = function (input, init) {24if (typeof input === "string") {25return originalFetch(new URL(input, baseURI).toString(), init);26}27return originalFetch(input, init);28};2930var originalRequest = self.Request;31function RequestProxy(input, init) {32if (typeof input === "string") {33return new originalRequest(new URL(input, baseURI).toString(), init);34}35return new originalRequest(input, init);36}37RequestProxy.prototype = Object.create(originalRequest);38self.Request = RequestProxy;3940originalImportScripts(baseURI);41})();424344