Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor in Internet Explorer

I am trying to run a blazor application in Internet Explorer. On the blazor page there is a notification stating there is a fallback into asm.js for browsers without webassembly support. When I load the page in IE (with blazor.pollyfil.js script linked), I just get the error "Browser doesn't support WebAssembly".

I am able to run the application in server mode (using a SignalR connection to rendering server) but it is a solution for all browsers and loses the benefits of web assembly.

Is there a way to correctly fall back to asm.js mode, only in Internet Explorer?

like image 795
Fanda Avatar asked Nov 26 '18 10:11

Fanda


People also ask

Does Blazor work on Internet Explorer?

That is the case for all modern browsers, including on mobile. Your Blazor WASM application will run fine on Chrome, Edge, Firefox, Safari and also on the mobile variants of these. However, Internet Explorer doesn't support WASM and therefore can't run client-side Blazor apps.

What browsers support Blazor?

For Blazor Hybrid apps, we test on and support the latest platform Web View control versions: Microsoft Edge WebView2 on Windows. Chrome on Android. Safari on iOS and macOS.

Why Blazor is not popular?

Blazor projects are slow on the client-side because you have to download the entire dot net runtime along with the necessary DLL libraries on your browser. Additionally, Blazor apps have latency issues.

Can Blazor run on desktop?

Blazor Hybrid apps with WPF and Windows FormsRazor components run natively in the Windows desktop and render to an embedded Web View. Using Blazor in WPF and Windows Forms enables you to add new UI to your existing Windows desktop apps that can be reused across platforms with . NET MAUI or on the web.


2 Answers

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.

like image 135
binki Avatar answered Oct 18 '22 03:10

binki


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

enter image description here

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.

Changing from WebAssembly to component mode is 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 answer for Blazor:

const isClientSideWebAssemblySupported = (() => {
    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 = (isClientSideWebAssemblySupported)?
             "_framework/blazor.server.js":
             "_framework/blazor.webassembly.js";

Remember to include both js in your project.

like image 3
dani herrera Avatar answered Oct 18 '22 02:10

dani herrera