question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Passthrough changes Response to be not compliant with WebAssembly.instantiateStreaming

See original GitHub issue

First of all, we are using Mirage with an Ember project and it works fine šŸ˜Šthanks for the awesome work. Since we really like Mirage we also tried to get it running for a Vue project which was scaffolded with vue-cli.

Currently, we are struggling to get Cypress running. We use the following plugin @vue/cli-plugin-e2e-cypress. I tried several things but Iā€™m just not able to get our WebAssembly module running.

We start our WebAssembly module with WebAssembly.instantiateStreaming and also if I passthrough the wasm file Chrome complains the following way:

Mirage: Passthrough request for GET /static/artifacts/wasm/kernel.wasm
TypeError: Failed to execute 'compile' on 'WebAssembly': An argument must be provided, which must be a Response or Promise<Response> object

After some investigation, I think that Mirage wraps every Response in its own Response class? Is this true? For some reason, I wasnā€™t able to figure out why the type-check on instantiateStreaming fails. When searching the internet for this error message I only found the following source code: https://doss-gitlab.eidos.ic.i.u-tokyo.ac.jp/kevin/chromium/blob/ad3841a1e47cd90bba10f271a8495d4040490b07/third_party/blink/renderer/bindings/core/v8/v8_wasm_response_extensions.cc#L283

Iā€™m a little bit lost (also because debugging is super hard with the vue-cli setup since Cypress is running somewhere else etc).

Any ideas what I could try to get the WebAssembly module running? Basically I followed those two quickstarters:

Let me know if you need further info

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
tschoartschicommented, Apr 23, 2020

I found a workaround which works at least for us, what I do now is the following:

new Server({
  environment: 'development',
  logging: true,
  routes() {
    // Needed because Chrome recognizes that the Mirage Response is not a real response
    // with setting instantiateStreaming to null we fallback to legacy WebAssembly instantiation
    // this works with the Mirage Response, therefore the app can start
    // for more details see: https://github.com/miragejs/miragejs/issues/339
    Object.defineProperty(window.WebAssembly, 'instantiateStreaming', {value: null});
    const oldPassthroughRequests = (this.pretender as any).passthroughRequest.bind(this.pretender);
    (this.pretender as any).passthroughRequest = (verb: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, request: any) => {

      // Needed because responseType is not set correctly in Mirages passthrough
      // for more details see: https://github.com/miragejs/ember-cli-mirage/issues/1915
      if (verb === 'GET' && path.match(/\.wasm$/)) {
        console.log('Set responseType for wasm correctly');
        request.responseType = 'arraybuffer';
      }
      return oldPassthroughRequests(verb, path, request);
    };
    this.passthrough();
  },
});

@samselikoff maybe you could have a look at this workaround and let me know if this is OK or if itā€™s a stupid idea to do it like this šŸ˜‰ thanks a lot

3reactions
tschoartschicommented, May 22, 2020

@ryanto thanks for the response and sorry for the late reply but yesterday was a national public holiday in Austria. I created a repo which demonstrates the issue: https://github.com/miragejs/miragejs/issues/339#issuecomment-596625395

Let me know if this is enough our if you need further information šŸ™‚

I think itā€™s a bug šŸ› in FakeXMLHttpRequest because I think FakeXMLHttpRequest does not set the responseType correctly. When debugging I found no sane way to tell FakeXMLHttpRequest to set the responseType. The only way I found was to set the rsponseType based on the file extension. This is what I outlined above in the passthrough hack

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebAssembly.instantiateStreaming() - MDN Web Docs
The WebAssembly.instantiateStreaming() function compiles and instantiates a WebAssembly module directly from a streamed underlying source.
Read more >
Safari Technology Preview Release Notes
Note: Shared Tab Groups and syncing for Tab Groups, Website Settings, and Web Extensions are not enabled in this release. WebAssembly. Fixed error...
Read more >
Content Security Policy Level 3
A server SHOULD NOT send more than one HTTP response header field named " Content-Security-Policy-Report-Only " with a given resourceĀ ...
Read more >
WebAssembly InstantiateStreaming Wrong MIME type
Considering you can't change the server to properly return application/wasm for .wasm file requests for any reason, you can work around theĀ ...
Read more >
Web Embedding
Note that it is expected that compileStreaming and instantiateStreaming be ... If the Response is not CORS-same-origin, does not represent an ok status,Ā ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found