| 146 | |
| 147 | /* Blob URL inherits the page's origin -> sidesteps Chromium's cross-origin block; the imported module then loads under CORS (Cloudflare Pages OK by default). `Function.toString` keeps the bootstrap as real JS in source. */ |
| 148 | function spawnCrossOriginWorker(workerUrl) { |
| 149 | const source = `(${crossOriginBootstrap.toString()})(${JSON.stringify(workerUrl)});`; |
| 150 | const blob = new Blob([source], { type: 'application/javascript' }); |
| 151 | const blobUrl = URL.createObjectURL(blob); |
| 152 | const worker = new Worker(blobUrl, { type: 'module' }); |
| 153 | // Defer revoke a tick; some browsers race it against the module fetch. |
| 154 | setTimeout(() => URL.revokeObjectURL(blobUrl), 0); |
| 155 | return worker; |
| 156 | } |