maui: Unexpected Syntax Error in blazor.webview.js on iOS lower than v17 in .NET 9 Pre7

Description

We’re trying to update our projects and templates to the .NET. 9 preview 7 but in iOS version of our app on devices with OS versions lower than 17 not working!

Steps to Reproduce

  1. Create a new .NET MAUI Blazor app using .NET CLI
  2. Run it on iOS versions lower than 17

Link to public reproduction project repository

https://github.com/mhrastegari/BlazorIssueWithOldIosVersions

Version with bug

9.0.0-preview.7.24407.4

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.80 SR8

Affected platforms

iOS

Affected platform versions

Tested on iOS 16 & iOS 15

Did you find any workaround?

No

Relevant log output

SyntaxError: Unexpected token '{'
If (anonymous function) — blazor.webview.js:1
ReferenceError: Can't find variable: Blazor
Global Code - user-script:1:15

Screenshots

Screenshot 2024-08-16 at 16 53 11

Working on iOS 17 but not 16: Screenshot 2024-08-16 at 16 59 11

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 28 (11 by maintainers)

Most upvoted comments

Also just ran into this. .NET MAUI 8 worked; after an upgrade to 9, it immediately stopped working on the same app, with the errors noted above. This can’t possibly be a “.NET 10 Planning” issue – I have nothing against iOS 17, but given that iOS 18 just came out, .NET 9 should at least be fully backwards compatible with iOS 16, if not also the later versions of iOS 15. Plenty of business users can’t update to the latest few versions on their devices for various reasons. Please bump this up to recompile at least the Blazor-MAUI JS dependencies on ES2019 (again) as opposed to ES2022. Either that, or provide a documented workaround.

This issue essentially makes .net 9 a non starter for us. We’re currently in the process of upgrading our app from Xamarin Forms to Maui/BlazorHybrid and we have the need to support a wide range of devices. It seems crazy to me that a breaking change like this is just introduced with no warning and no resolution in sight. It gives me pause and makes me wonder how long we’ll be stuck on .net 8.

While I understand that the commitment is to only support the latest browsers. Such a small change, that offers (as far as I can tell) very little benefit to anyone, breaking support for a decent proportion of our users is worth fixing. Even if we need to set a config option in the csproj.

Unfortunately, non-dev users are pretty renowned for being terrible at updating their phones.

or upgrading their devices… a 7 year old iPad which still still looks brand new but no longer gets iOS updates and thus stuck with a now incompatible old Safari version.

While I understand that the commitment is to only support the latest browsers. Such a small change, that offers (as far as I can tell) very little benefit to anyone, breaking support for a decent proportion of our users is worth fixing. Even if we need to set a config option in the csproj.

Unfortunately, non-dev users are pretty renowned for being terrible at updating their phones.

To fix this issue I took a different approach, by downgrading “Microsoft.AspNetCore.Components.WebView.Maui” to version 8.0.100 and stayed on .NET 9.

My MAUI / Blazor hybrid app now works on iOS 15 and later.

Could someone having this issue on Android please see if that fixes your problem as well?

@smmaya @Ed156 this has been ongoing and worsening issue since at least 2021 and and they have refused to fix in the past…

I haven’t tried it but this fix might be an option - https://github.com/dotnet/aspnetcore/issues/53699

The issue seems to stem from updated build/package changes e.g. https://github.com/dotnet/maui/issues/4517 and https://github.com/dotnet/aspnetcore/issues/53699

They really need to at least add the graceful fail and a message to know what is going on as mentioned before e.g. https://github.com/dotnet/aspnetcore/issues/53699

I also wasted way too much time on this…

At least on Android, you could possibly update WebView with an old OS but Apple doesn’t support devices beyond ~7 years old…

boo… just came across this too… blank screen loading Blazor 9 web page (not MAUI Blazor) in Safari (and Chrome) on iPad Mini 4 with iOS 15.8.3

Worked previously when the app was Blazor 8… how do I tell the client he has to upgrade all the company iPads now… ?

I don’t have a Mac to see more in developer info…

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

If 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.

Gosh, I wasted a week on this bs 😉 Works on a simulator (iPhone 16) but not on my real device (15.8.3) - what to do, revert back to .NET8 or try the preview?

Not even ios 16 is supported, which is exactly the phone I’m currently using. Android’s API 31, which was also released in October 2021, just doesn’t work to use for those who don’t update their systems. It’s almost unacceptable for Maui to require users to use a new device

The Github Copilot answer:

The error Uncaught SyntaxError: Unexpected token . in older browsers is likely caused by the optional chaining operator (?.), which is not supported in those browsers.

To make the code compatible with older browsers, you can replace the optional chaining operator with a more traditional approach:

export function getBrowserEventName(possibleAliasEventName: string): string {
  const eventOptions = eventTypeRegistry.get(possibleAliasEventName);
  return eventOptions && eventOptions.browserEventName ? eventOptions.browserEventName : possibleAliasEventName;
}

boo… just came across this too… blank screen loading Blazor 9 web page in Safari (and Chrome) on iPad Mini 4 with iOS 15.8.3

Worked previously when the app was Blazor 8… how do I tell the client he has to upgrade all the company iPads now… ?

I don’t have a Mac to see more in developer info…

OK, I have a Mac now… can confirm same Unexpected token error as @mhrastegari in Safari.

Thanks for the report we will investigate!