Allow users to upload wasm files to use within the extension?

Is it possible to allow users to “upload” a wasm file to the extension (put that in storage and ideally simply access it with a local extension URL) and then use this within the extension?

My extension has an optional function that works with a .wasm file. But because it is optional and not all users will need it I don’t want to distribute it by default. (also because it is rather big)

does anyone know if that’s possible?

2 Likes

I haven’t tested it myself, but maybe something like below?

/* fetch and save .wasm */
const userWasm = await fetch('/path/to/user.wasm')
  .then(res => res.arrayBuffer())
  .then(buf => new Uint8Array(buf));
await browser.storage.local.set({ userWasm });

/* get and use .wasm */
const { userWasm } = await browser.storage.local.get('userWasm');
const res = await WebAssembly.instantiate(userWasm);

Addons doesn’t have access to files on user drive. Except maybe in the “downloads” folder with a downloads permission…
Otherwise user would have to load through the “input” element. But still, can you even serialize a wasm and save it in the store and then load and execute it? I have doubts.

Maybe “fetch” it from a server, but that would probably be a remote code execution violation…

Indeed, passing arbitrary user-entered strings to fetch is very dangerous.

thanks for the replies.

Indeed I was thinking about some “upload” through some file input and store it locally in browser storage.
If base64 encoded or similar this should also work for wasm files, no?

I’d like to avoid the fetch() because of the potential remote code execution violation - though I am still not sure if this is one or not. (right now it works)
And I don’t want to include the wasm file in the extension because it is optional and not all users need it.