#[Solved] How can I set a mimetype for a .wasm file?

1 messages · Page 1 of 1 (latest)

paper verge
#

This is a unique scenario... TLDR is my JS is trying to load a .wasm file which contains a brotli decryption library that's pretty specific to my use case.

Desired workflow:

  1. User scans QR code to my site
  2. App intercepts it and handles it locally / offline, redirecting the user to /board/HASH which loads a self-container index.html with it's own js/css and .wasm file (for decrypting the hash).
  3. Currently, this is where it breaks, because the index.html loads brotli_wasm_bg-NfWIZley.wasm which is a relative path and appears to be returning an empty body instead of the static file I'm expecting.

Existing file structure is attached. Here's a snipper from index.html:

    <script type="module" crossorigin src="board-DEn-zR7s.js"></script>
    <link rel="stylesheet" crossorigin href="main-DgwIXneD.css">

and from the boardxxxx.js file: ...en(e){typeof e>"u"&&(e=new URL("brotli_wasm_bg-NfWIZley.wasm",import.meta.url));const t={...

#

The below logs are coming back from adb logcat | grep -E "(chromium|Console)", suggesting it's getting an empty http response. Claude

01-25 16:53:13.162  6679  6679 D PHPMonitor-Console: `WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:
01-25 16:53:13.162  6679  6679 D PHPMonitor-Console:  TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'. -- From line 5
01-25 16:53:13.099  6679  6679 D PHPMonitor-Console: [WASM DEBUG] Response - Status: 200 Content-Type: text/html, application/wasm Content-Length: 0, 1056860 URL: http://127.0.0.1/api/board-wasm/brotli_wasm_bg-NfWIZley.wasm -- From line 5
01-25 16:53:13.162  6679  6679 D PHPMonitor-Console: [WASM DEBUG] Buffer size: 0 -- From line 5
01-25 16:53:13.162  6679  6679 D PHPMonitor-Console: [WASM DEBUG] EMPTY BUFFER! -- From line 5
01-25 16:22:46.828  5033  5033 D PHPMonitor-Console: Error decoding token: CompileError: WebAssembly.instantiate(): BufferSource argument is empty -- From line 5
01-25 16:22:46.828  5033  5033 D PHPMonitor-Console: Error decoding token: CompileError: WebAssembly.instantiate(): BufferSource argument is empty -- From line 5

In the above logs, AI suggests it's getting a text/html redirect before actually accepting application/wasm. Is this expected?

stoic quail
#

We haven’t drive anything to support wasm, it’s not currently on our radar at all. Why can’t you use some native ability to decrypt the hash?

paper verge
#

gzip isn't compressed enough for my needs. We're trying to fit data into a QR version 40 QR code. I'll keep digging and see if I can work around the mime type issue, seems like a strange limitation or blocking issue.

paper verge
#

I worked around it by base64 encoding the wasm file in the JS and then loading it from memory. It got the job done.