Skip to content

Commit

Permalink
fix: 1444
Browse files Browse the repository at this point in the history
  • Loading branch information
timhub66 committed Dec 3, 2024
1 parent ce2689e commit 358199c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/proxies/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ interface WorkerOptions {
credentials?: 'omit' | 'same-origin' | 'include';
}

const EXCLUDE_URL_PROTOCOLS = [
'blob:'
]

interface WorkerInstance extends EventTarget {
postMessage(message: any, transfer?: Transferable[]): void;
terminate(): void;
Expand All @@ -20,14 +24,12 @@ interface Worker {
const originalWorker = window.Worker

function isSameOrigin(url: string | URL): boolean {
if (url instanceof URL && url.protocol === 'blob:') {
// 如果 url 是 Blob URL,直接返回 true
return true
}

// 检查 URL 是否与当前页面在同一个源
try {
const parsedUrl = new URL(url as string)
// 检查 URL 是否与当前页面在同一个源
const parsedUrl = url instanceof URL ? url : new URL(url as string)
if (EXCLUDE_URL_PROTOCOLS.includes(parsedUrl.protocol)) {
return true
}
return (
parsedUrl.protocol === window.location.protocol &&
parsedUrl.hostname === window.location.hostname &&
Expand Down

0 comments on commit 358199c

Please sign in to comment.