Blazor in Internet Explorer

邮差的信 提交于 2019-12-21 10:51:09

问题


I am trying to run blazor application in Internet Explorer. On blazor page is written there is a fallback into asm.js for browsers without webassembly support. But when I load page in IE (with blazor.pollyfil.js script linked), I just get error "Browser does'n support WebAssembly".

I am able to run application in server mode (SignalR connection to rendering server), but it is solution for all browsers and the main benefit (WebAssembly) disappears.

Is there really way how to correctly fall back to asm.js mode in (only) Internet Explorer?


回答1:


WebAssembly is not included on Internet Explorer features. You can learn about Browser compatibility at mozilla.org, and not, IE has no support for WebAssembly.

Remember IE is discontinued, but still maintained:

Will Internet Explorer 11 continue to receive updates?

The latest features and platform updates will only be available in Microsoft Edge. We will continue to deliver security updates to Internet Explorer 11 through its supported lifespan. To ensure consistent behavior across Windows versions, we will evaluate Internet Explorer 11 bugs for servicing on a case by case basis.

Change from WebAssembly to component mode are just a few lines change code, but seems weird to deploy both modes to keep compatibility for IE. Remember Blazor is experimental, I guess for a real deployment you should to wait for a while ... time to update from IE to some other browser.

Is there really way how to correctly fall back to asm.js mode in (only) Internet Explorer?

I guess is the same question as "How can I check if a browser supports WebAssembly?" Just adapt the anwser for blazor:

const supported = (() => {
    try {
        if (typeof WebAssembly === "object"
            && typeof WebAssembly.instantiate === "function") {
            const module = new WebAssembly.Module(
                               Uint8Array.of(0x0, 0x61, 0x73, 0x6d,
                                             0x01, 0x00, 0x00, 0x00));
            if (module instanceof WebAssembly.Module)
                return new WebAssembly.Instance(module) 
                           instanceof WebAssembly.Instance;
        }
    } catch (e) {
    }
    return false;
})();

var script = document.createElement('script');
script.src = (supported)?
             "_framework/blazor.server.js":
             "_framework/blazor.webassembly.js";

Remember to include both js in your project.




回答2:


Support for asm.js was intentionally removed from Blazor in this commit: https://github.com/aspnet/Blazor/commit/4006cd543900fcc1cf76cd75a1b24007e60c8a67 . If I understand correctly, getting asm.js support back from stock blazor would require the mono project to start including an asm.js build in its binary distribution and for the Blazor project to add that back to its build/deploy tooling.

I haven’t tried it, but it might be possible to build mono for asm.js yourself and inject it into your built Blazor application as part of your own deploy process.

If I understand correctly, Blazor still runs using mono’s interpreted mode, so supplementing the wasm build of mono with an asm.js one might still be sufficient. If Blazor switches to actually compiling assemblies to wasm directly in the future, things will become more complicated.

Alternatives

Blazor supports server-side hosting mode. You already mentioned this in your question, but I am discussing this here in case others skipped over that. In server hosting mode, the client only needs to be able to run “traditional” JavaScript (though it may need polyfills). This can be made to work in IE11 and other clients lacking wasm support. Of course, this takes more resources on the server, prevents the client from supporting offline scenarios, and is basically like a glorified telnet session. But this may be sufficient for LOB applications.




回答3:


It looks like other users are also facing this issue.

That user find that the problem is with the polyfills (and Internet Explorer 11 of course), and it occur with babel / core-js and other compatible polyfills.

It seem that IE11 have some difficulties with deep setter recursion on Symbol, and it get a Stack memory exceeded error.

he also try to fix the polyfill. You can try to make a test with it to check whether it help to solve your issue or not.

Reference:

asm.js fallback not working on IE11

Polyfills for Blazor (for Internet Explorer 11 support and some other browsers)



来源:https://stackoverflow.com/questions/53478760/blazor-in-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!