-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Loïc Mangeonjean
committed
Jan 30, 2024
1 parent
25134a8
commit 16ae791
Showing
3 changed files
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Cross origin workers don't work | ||
* The workaround used by vscode is to start a worker on a blob url containing a short script calling 'importScripts' | ||
* importScripts accepts to load the code inside the blob worker | ||
*/ | ||
class CrossOriginWorker extends Worker { | ||
constructor (url: string | URL, options: WorkerOptions = {}) { | ||
const fullUrl = new URL(url, window.location.href).href | ||
const js = options.type === 'module' ? `import '${fullUrl}';` : `importScripts('${fullUrl}');` | ||
const blob = new Blob([js], { type: 'application/javascript' }) | ||
super(URL.createObjectURL(blob), options) | ||
} | ||
} | ||
|
||
export { CrossOriginWorker as Worker } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters