Interesting, I didn't know Service Workers disallowed XHRs but allow fetch.
Then yes, we should use fetch where it is available.

The place to fix this is in src/shell.js, in readAsync. Apparently fetch is
in all modern browsers now, https://caniuse.com/#search=fetch so we can
probably just use fetch (or maybe fall back to XHR if legacy vm support is
enabled).

Feel free to open a PR with that, or if not then please open a github issue
for this and hopefully someone else will soon.

On Fri, Feb 9, 2018 at 10:00 AM, Lucas Pardue <lucaspardue.2...@gmail.com>
wrote:

> Hi,
>
> We have a little project that we've run through emscripten and it produces
> an asm.js output called example.js, and example.js.mem. Inside example.js
> is the generated function fetchRemotePackage(), which uses XMLHttpRequest
> (XHR is also used elsewhere in example.js).
>
> I've tried to use this in my Service Worker, starting simply with
> importScripts('example.js'). Unforturnately both Chrome and Firefox return
> a ReferenceError stating that XMLHttpRequest is not defined. It seems that
> Service Worker does not support XHR and it would rather I use the WHATWG Fetch
> API <https://fetch.spec.whatwg.org/>. Note that this is seems to be
> completely distinct from Emscripten's Fetch API.
>
> I wondered if this issue with Service Worker was already on Emscripten's
> radar, a search did not yield much. I also had a look if there was some
> kind of build option that would replace XHR with Fetch but did not have
> much luck.
>
> I suppose I could manually transform the generated code with
> --js-transform but that does not seem ideal, especially since the problem
> is so broad as to affect all Service Workers.
>
> Any tips?
>
> Kind regards
> Lucas
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to