File tree 2 files changed +11
-4
lines changed
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export const defaultPoolSize = typeof navigator !== "undefined" && navigator.har
7
7
? navigator . hardwareConcurrency
8
8
: 4
9
9
10
- const isAbsoluteURL = ( value : string ) => / ^ ( f i l e | h t t p s ? : ) ? \/ \/ / i . test ( value )
10
+ const isAbsoluteURL = ( value : string ) => / ^ [ a - z A - Z ] [ a - z A - Z \d + \- . ] * : / . test ( value )
11
11
12
12
function createSourceBlobURL ( code : string ) : string {
13
13
const blob = new Blob (
@@ -34,12 +34,16 @@ function selectWorkerImplementation(): ImplementationExport {
34
34
url = new URL ( url , options . _baseURL )
35
35
} else if ( typeof url === "string" && ! isAbsoluteURL ( url ) && getBundleURL ( ) . match ( / ^ f i l e : \/ \/ / i) ) {
36
36
url = new URL ( url , getBundleURL ( ) . replace ( / \/ [ ^ \/ ] + $ / , "/" ) )
37
- url = createSourceBlobURL ( `importScripts(${ JSON . stringify ( url ) } );` )
37
+ if ( options ?. CORSWorkaround ?? true ) {
38
+ url = createSourceBlobURL ( `importScripts(${ JSON . stringify ( url ) } );` )
39
+ }
38
40
}
39
41
if ( typeof url === "string" && isAbsoluteURL ( url ) ) {
40
42
// Create source code blob loading JS file via `importScripts()`
41
43
// to circumvent worker CORS restrictions
42
- url = createSourceBlobURL ( `importScripts(${ JSON . stringify ( url ) } );` )
44
+ if ( options ?. CORSWorkaround ?? true ) {
45
+ url = createSourceBlobURL ( `importScripts(${ JSON . stringify ( url ) } );` )
46
+ }
43
47
}
44
48
super ( url , options )
45
49
}
Original file line number Diff line number Diff line change @@ -81,8 +81,11 @@ export interface ThreadsWorkerOptions extends WorkerOptions {
81
81
/** The size of a pre-allocated memory range used for generated code. */
82
82
codeRangeSizeMb ?: number
83
83
}
84
- /** Data passed on to Node worker_threads */
84
+ /** Data passed on to node.js worker_threads. */
85
85
workerData ?: any
86
+
87
+ /** Whether to apply CORS protection workaround. Defaults to true. */
88
+ CORSWorkaround ?: boolean
86
89
}
87
90
88
91
/** Worker implementation. Either web worker or a node.js Worker class. */
You can’t perform that action at this time.
0 commit comments