emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.9k stars 3.32k forks source link

Refused to execute script from 'http://localhost/undefined' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled #22117

Open andynewman10 opened 5 months ago

andynewman10 commented 5 months ago

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.57 (1df9c1977b49926c1efca672c31414da45c0c7bb)
clang version 19.0.0git (https:/github.com/llvm/llvm-project ccdebbae4d77d3efc236af92c22941de5d437e01)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/fred/emsdk/upstream/bin

(also tried with latest)

Repro

The problem occurs when using OpenCV.js compiled with emscripten (3.1.57, or latest)

$ git clone https://github.com/opencv/opencv.git
$ git checkout 4.10.0

Now build opencv.js:

$ emcmake python3 ./opencv/platforms/js/build_js.py build_wasmthreads --build_wasm --threads

See opencv.js under build_wasmthreads/bin.

Now try it out:

Make sure SharedArrayBuffer is enabled regardless of cross-origin header status ; for this, I use --enable-features=SharedArrayBuffer on Chrome.

Case 1)

Case 2)

Note that OpenCV will always work fine when WASM threads are disabled (--threads option not used).

sbc100 commented 5 months ago

Has this ever worked in the past? i.e. is this a regression?

andynewman10 commented 5 months ago

Good question. What is puzzling me is why is this working from the main page, and not from a web worker.

sbc100 commented 5 months ago

Thats a good question too, but I think in the general case starting the program from within a worker is something we do test, so there could be something odd going on here with opencv. Since this is not a known regression (i.e it wasn't known to work in the past) I'm temped to suggest you file an upstream bug with opencv to ask them about it, since its hard to know if this is something they expect to work.

andynewman10 commented 5 months ago

OpenCV issue opened here:

https://github.com/opencv/opencv/issues/25790

vittorioromeo commented 3 months ago

I'm having the same exact issue with a program that does not use OpenCV, it just uses std::thread, so I don't think this is OpenCV's fault.

I am serving the program on GitHub pages using https://github.com/gzuidhof/coi-serviceworker

This is the source code: https://github.com/vittorioromeo/SFML/blob/wip_emcc/examples/island/Island.cpp

This is the live demo: https://vittorioromeo.github.io/VRSFML_HTML5_Examples/island.html

vittorioromeo commented 3 months ago

Note: I only get this error with -sSINGLE_FILE=1, removing the flag fixes it.