aspnetcore: [.NET 9] BlazorWebView fails to load on older Android devices `Uncaught SyntaxError: Unexpected token .`
The JS file generated for blazor.webview.js contains JS code that is not valid on older Android systems unless they update their WebView.
This error occurs immediately when loading a BlazorWebView’s contents: Uncaught SyntaxError: Unexpected token .
And occurs on this JS line in the file:
function l(e) {
const t = a.get(e);
return t?.browserEventName || e // <------------
}
It seems to be this code, which oddly doesn’t seem to have changed in very, very long time.
I’m not sure what did change that this would start happening only recently. Maybe TypeScript changed to generate different code?
This happens by default on Android Emulators with API 30 and older (we know that API 33 works, not sure about 31 and 32).
On these older Android emulator images you can update the System WebView to get newer versions, and that seems to fix the problem.
Some options to consider:
- Do nothing. Users and/or app developers have to make sure the system is up-to-date. Well, minimally we’d want to document this, but no code change.
- Have BlazorWebView detect older WebView on Android and fail more gracefully. Or perhaps log something?
- Have Blazor use JS code that is compatible with older Android WebView versions. Perhaps there is a TypeScript flag to tell it to generate ‘old’ JS that is more compatible?
Note: This scenarios is somewhat reminiscent of the fact that on Windows you have to have Edge WebView2 installed and that things won’t work if you don’t. You’ll probably get some weird errors, but the BlazorWebView control doesn’t do a lot to help you (for better or for worse).
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (7 by maintainers)
Hi everyone, I’ve posted a step-by-step guide on how to work around this issue by using an ES2019-compatible version of
blazor.webview.js: https://github.com/dotnet/maui/discussions/27327If you’re running into the problem described in this issue, please try that out and let us know if the workaround is working for you.
@Eilon this was likely me, as part of revamping our JS infrastructure.
We did switch bundlers and “standarized” compiler settings, etc. One of the things that we did was making sure that we targeted modern JS.
All three options you propose sound fine to me, but this comes down to the support we wanted to offer, and I think we aligned the Android support with the general platform support for Browsers we had, so I’m more inclined to suggest we tell developers to update their webview. Probably with a better error message if possible. As far as I know, webview updates automatically on Android devices too, isn’t it? So this is more of an “emulator” driven issue than an issue on real devices.
Also note, that previous versions up to 8.0 are fine, as this change was introduced in January, so there’s no rush for us to react. (By the time we ship again, we might consider those platforms too old (as I think we already do) and all versions we care about might not have issues).
In any case, should we need to react, there’s some work that we can do to make this work if needed by providing a custom config for webview.