Skip to content

[.NET 9] BlazorWebView fails to load on older Android devices Uncaught SyntaxError: Unexpected token . #53699

@Eilon

Description

@Eilon

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   // <------------
    }

image

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:

  1. 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.
  2. Have BlazorWebView detect older WebView on Android and fail more gracefully. Or perhaps log something?
  3. 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-blazor-hybrid

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions