Path: blob/main/components/supervisor/frontend/src/ide/ide-worker.ts
2501 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/**7* Installs the proxy (shared) worker serving from the same origin to fetch content from the blobserve origin.8*/9export function install(): void {10if (window.Worker) {11const Worker = window.Worker;12window.Worker = <any>function (scriptUrl: string | URL, options?: WorkerOptions) {13return new Worker(proxyUrl(scriptUrl), options);14};15}16if (window.SharedWorker) {17const SharedWorker = window.SharedWorker;18window.SharedWorker = <any>function (scriptUrl: string, options?: string | SharedWorkerOptions) {19return new SharedWorker(proxyUrl(scriptUrl), options);20};21}22}2324function proxyUrl(scriptUrl: string | URL | TrustedScriptURL): string {25scriptUrl =26scriptUrl instanceof URL27? scriptUrl28: new URL(typeof scriptUrl === "string" ? scriptUrl : scriptUrl.toString(), document.baseURI);29if (scriptUrl.origin !== location.origin || (scriptUrl.protocol !== "http:" && scriptUrl.protocol !== "https:")) {30return scriptUrl.toString();31}32return new URL(33"_supervisor/frontend/worker-proxy.js#" + encodeURI(scriptUrl.toString()),34document.baseURI,35).toString();36}373839