Home:ALL Converter>Can you run web assembly in the content part of chrome extension in all websites?

Can you run web assembly in the content part of chrome extension in all websites?

Ask Time:2022-04-01T07:08:31         Author:mortonprod

Json Formatter

I have been playing about with chrome extensions and web assembly, both of which I know very little about. I am looking to create an extension which does image manipulation which in the end generates 'video' (Series of image frames drawn using the HTML canvas element).

What I would like to do is have the content part of a web extension to

  1. Inject a wasm function onto the webpage
  2. Collect image information and pass to wasm function
  3. Process images on website to create 'video' (Details not important)
  4. Place 'video' back on the website by passing data back to page and onto the HTML canvas

However some websites block this with the error:

Uncaught (in promise) CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder

From research this seems to be due to CSP headers on the website which I will not be able to change.

Is this true? Is there anyway round this? If not, why can I run arbitrary js but not wasm?


An alternative is to get the images on the webpage and send them to the background script running in the chrome extension, which would then process the images using wasm, then forwarding any output of 'video' back to the content script to draw on the webpage.

However, I don't think you can do that level of communication between the content and background scripts in a chrome extension so this way also does not seem to work.

Anyone done something similar and know a way around this? Thanks in advance.

Author:mortonprod,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71700093/can-you-run-web-assembly-in-the-content-part-of-chrome-extension-in-all-websites
yy