File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,18 @@ const wasmHelper = async (opts = {}, url: string) => {
30
30
// a lot of static file servers, so we just work around it by getting the
31
31
// raw buffer.
32
32
// @ts -ignore
33
- const response = await fetch ( url ) ;
33
+ const getBaseUrl = ( ) => {
34
+ const currentScriptUrl = getRunningScript ( ) ( )
35
+ if ( ! currentScriptUrl ) return ''
36
+ return new URL ( currentScriptUrl ) . origin
37
+ }
38
+ const getRunningScript = ( ) => {
39
+ return ( ) => {
40
+ return new Error ( ) . stack . match ( / ( [ ^ \n ] ) * ( [ a - z ] * : \/ \/ \/ ? ) * ?[ a - z 0 - 9 \/ \\ ] * \. j s / ig) ?. [ 0 ]
41
+ }
42
+ }
43
+ const baseUrl = typeof window !== 'undefined' ? getBaseUrl ( ) : ''
44
+ const response = await fetch ( baseUrl + url ) ;
34
45
const contentType = response . headers . get ( "Content-Type" ) || "" ;
35
46
if ( "instantiateStreaming" in WebAssembly && contentType . startsWith ( "application/wasm" ) ) {
36
47
result = await WebAssembly . instantiateStreaming ( response , opts ) ;
You can’t perform that action at this time.
0 commit comments