File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Expand file tree Collapse file tree 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
77 ? navigator . hardwareConcurrency
88 : 4
99
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 )
1111
1212function createSourceBlobURL ( code : string ) : string {
1313 const blob = new Blob (
@@ -34,12 +34,16 @@ function selectWorkerImplementation(): ImplementationExport {
3434 url = new URL ( url , options . _baseURL )
3535 } else if ( typeof url === "string" && ! isAbsoluteURL ( url ) && getBundleURL ( ) . match ( / ^ f i l e : \/ \/ / i) ) {
3636 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+ }
3840 }
3941 if ( typeof url === "string" && isAbsoluteURL ( url ) ) {
4042 // Create source code blob loading JS file via `importScripts()`
4143 // 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+ }
4347 }
4448 super ( url , options )
4549 }
Original file line number Diff line number Diff line change @@ -81,8 +81,11 @@ export interface ThreadsWorkerOptions extends WorkerOptions {
8181 /** The size of a pre-allocated memory range used for generated code. */
8282 codeRangeSizeMb ?: number
8383 }
84- /** Data passed on to Node worker_threads */
84+ /** Data passed on to node.js worker_threads. */
8585 workerData ?: any
86+
87+ /** Whether to apply CORS protection workaround. Defaults to true. */
88+ CORSWorkaround ?: boolean
8689}
8790
8891/** Worker implementation. Either web worker or a node.js Worker class. */
You can’t perform that action at this time.
0 commit comments