Avoiding CORS problem when publishing

761 views
Skip to first unread message

Ian Bell

unread,
Mar 30, 2019, 7:27:54 PM3/30/19
to emscripten-discuss
I have an enscripten-wrapped C++ library, and running it in a local webserver works fine.  But when I try to drop the .js and .wasm files onto another server and include it in a block like this:

<script src="http://www.coolprop.sourceforge.net/jscript/coolprop.js"></script >

In my HTML, I get CORS errors (see below). I've set the MIME type on the WASM successfully, but this is a classic CORS problem I surmise.

Can somebody point me to an example of a properly functioning publishing of js+wasm combo that can be successfully included in another script in the manner that I have tried to do? The emscripten docs on this topic are decidedly unhelpful: https://emscripten.org/docs/compiling/Deploying-Pages.html#prepare-for-the-web-environment

wasm streaming compile failed: TypeError: NetworkError when attempting to fetch resource. coolprop.js:1651:11
falling back to ArrayBuffer instantiation coolprop.js:1652:11
Cross-Origin
 
Request Blocked: The Same Origin Policy disallows reading the remote
resource at
http
://www.coolprop.dreamhosters.com:8010/binaries/Javascript/coolprop.wasm.
 
(Reason: CORS header Access-Control-Allow-Origin missing).[Learn More]

both async and sync fetching of the wasm failed coolprop.js:10604:5
both async and sync fetching of the wasm failed coolprop.js:10605:5
Cross-Origin
 
Request Blocked: The Same Origin Policy disallows reading the remote
resource at
http
://www.coolprop.dreamhosters.com:8010/binaries/Javascript/coolprop.wasm.
 
(Reason: CORS header Access-Control-Allow-Origin missing).[Learn More]

Floh

unread,
Apr 3, 2019, 6:53:32 AM4/3/19
to emscripten-discuss
It looks like you're loading the JS file from a different URL than the WASM file:


vs 


The easiest solution is to host all files (.html, .js, .wasm) from the same domain (so either all files
on sourceforge, or on dreamhoster, but not both).

The complicated solution (which I haven't done so far) is to change the configuration of the
dreamhoster webserver to accept cross-origin requests from the sourceforge domain (assuming dreamhoster
even allows this sort of configuration). Google for 'CORS whitelist' or similar.

Floh

unread,
Apr 3, 2019, 1:30:04 PM4/3/19
to emscripten-discuss
PS: for an example of a WASM webpage you can look at the github-pages repo for my sokol-samples page

The github-pages repo is here: https://github.com/floooh/sokol-html5

Producing this webpage: https://floooh.github.io/sokol-html5/

The interesting files are here:


For each demo, there's a .html, .js and .wasm file. For instance the files for the triangle demo (https://floooh.github.io/sokol-html5/wasm/triangle-sapp.html) would be:




I guess the interesting part is that all URL files are relative, there's no "http://hostname/..." part anywhere, only the filenames (I'm not doing anything special for this during compilation, this seems to be emscripten's default). This basically ensures that that the demo works locally, as well as
any domain / URL.
Reply all
Reply to author
Forward
0 new messages