Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/launcher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@ const installFetchPatches = ({
headers: { 'Content-Type': 'text/plain' }
});
};
const oldImportScripts = globalThis.importScripts;
globalThis.importScripts = (...args) => {
const newargs = args.map(url => {
const urlObj = new URL(url, location.href);
if (allowedOrigins.includes(urlObj.origin)) {
return url;
}
if (proxySites && proxySites.includes(urlObj.origin)) {
return proxyURL + urlObj.hostname + urlObj.pathname;
}
throw new Error('Script is from blocked URL');
});
return oldImportScripts(...newargs);
};
const oldWorker = Worker;
const NewWorker = function (
script: string | URL,
Expand Down Expand Up @@ -339,6 +353,20 @@ const installFetchPatches = ({
headers: { 'Content-Type': 'text/plain' }
});
};
const oldImportScripts = globalThis.importScripts;
globalThis.importScripts = (...args) => {
const newargs = args.map(url => {
const urlObj = new URL(url, location.href);
if (allowedOrigins.includes(urlObj.origin)) {
return url;
}
if (proxySites && proxySites.includes(urlObj.origin)) {
return proxyURL + urlObj.hostname + urlObj.pathname;
}
throw new Error('Script is from blocked URL');
});
return oldImportScripts(...newargs);
};
Object.defineProperty(globalThis, 'location', {
value: new URL('${scriptURL.href}'),
writable: false,
Expand Down