Bug? Generated UnityLoader.js fails in iOS 14 public beta

Unity: Unity 2019.4.5f1
Device A: Macbook Pro; Mac OS Big Sur Preview
Device B: iPhoneX; iOS 14 beta
Browser: Safari

Forgive the snippet here, but this is from the generated UnityLoader.js that the webgl build produces in Unity. This is approximately line 3, col 31,796. The line in question is:

case"Mac OS X":p=/Mac OS X (10[\.\_\d]+)/.exec(i)[1];

The navigator.appVersion (which seems to be the string this is parsing out) yields something along the lines of
5.0 (Macintosh; Intel Mac OS X 11_0)

As such, the assumption that it starts with a ‘10’ is wrong, and there is no index 1 in the result of the regex, it throws an exception, and unity fails to load.

I have hacked around this, without fully understanding the context or intent of this code snippet, by ignoring the generated UnityLoader.js, using my own fork, and just replacing it with this obviously wrong but non exception throwing code:
case"Mac OS X":p=function(){let x = /Mac OS X (10[\.\_\d]+)/.exec(i); return x ? x[1] : "10_15_6"}();

I think this is a bug. But also, if this is somehow my fault and I should tune some build paramter somewhere, please tell me as such :stuck_out_tongue:

macOS Big Sur just recently received a public beta, and is now officially macOS 11, it worked in the developer beta because it had a bug which displayed the version as 10.16.

Unity won’t update the public Unity builds until macOS Big Sur is in full release.
If you want a quick fix, open UnityLoader.js in your favorite code editor, and find a line with this text, “p = /Mac OS X (10[._\d]+)/.exec(i)[1];”, change it to “p = /Mac OS X (1[._\d][._\d]+)/.exec(i)[1];”

This will allow it to run on macOS 10.. to macOS 19..

Your Welcome!

4 Likes

Thank you mike_unity414 for raising the issue and a massive thank you to Joel4763 for being a lifesaver.

If anyone needs to fix this in Unity 2017 LTS, there is one difference to the 2019 code. 2017 has:

p = /Mac OS X (10[\.\_\d]+)/.exec(a)[1];

So exec(a) not exec(i) and that needs to be reflected in Joel4763’s replacement code of course:

p = /Mac OS X (1[\.\_\d][\.\_\d]+)/.exec(a)[1];
1 Like

Thanks for reporting! Marked down a TODO for the team to fix this up.

Also when working on this, it is a good idea to check if exec returns an actual array and not just a null value

1 Like

Hi, any update on this? I’m facing on this problem with unity 2020.1.8f1 and Big Sur official release

using the above discussion, i wrote this script that replace the wrong regex with a working regex automatically after build.
Put this under Assets/Scripts/Editor

using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

public class WebglPostBuild
{
    [PostProcessBuild(1)]
    public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target != BuildTarget.WebGL)
            return;

        Debug.Log(pathToBuiltProject);

        string[] filePaths = Directory.GetFiles(pathToBuiltProject, "*.js", SearchOption.AllDirectories);

        foreach(string file in filePaths)
        {
            if(file.ToLower().Contains("loader.js"))
            {
                string text = File.ReadAllText(file);
                text = text.Replace(@"Mac OS X (10[\.\_\d]+)", @"Mac OS X (1[\.\_\d][\.\_\d]+)");
                File.WriteAllText(file, text);
            }
        }
    }
}
8 Likes

Thanks for the solution above! FYI the “loader.js” check doesn’t work for us in production mode, so we just replaced on all JS files (there were just two of them total).

Same problems as above in Big Sur. None of our WebGL releases will execute in Chrome.

The above fix didn’t solve it for is in a quick test, but will investigate further. Using Unity 2019.3.15f1

1 Like

Same problem here. The solution were I modify the UnityLoader.js file does not seem to work. Anyone got it working, or do we need to upgrade Unity?

EDIT: After locating issue #1284215 about the same problem one of the suggested solutions worked for me (version 2019.3.6f1): replace “/Mac OS X (10[._\d]+)/.exec(i)[1];” with
“/Mac OS X (1[0-1][._\d]+)/.exec(i)[1];” inside UnityLoader.js (replacing the 10 with 1[0-1]).
Hope to see a fix from Unity soon.

Why does it not work for me?

case “Mac OS X”:
osVersion = /Mac OS X (1[._\d][._\d]+)/.exec(nAgt)[1];
break;

Hi, anyone know if this fix will be ported to 2019.4? I’m encountering this problem on 2019.4.8f1.
As I’ve seen here, [WebGL] UnityLoader.js fails to parse on Chrome - Unity Engine - Unity Discussions
that " and patches should be landing to other Unity branches very soon"

Unity 2019.4.16 contained this fix, but they did not tag the bug for some reason. Tested and working for us.

  • WebGL: Fixed a crash with Unity web loader on new macOS Big Sur.
1 Like

It looks like what was a pre-release Safari issue (that then wasn’t a Safari issue when macOS Big Sur actually released), now raised its head on Chrome. See this stickied thread Bug Fix: Unity WebGL Support for Chrome/Edge on macOS Big Sur for more information and ways to remedy.

Since we have a few threads opened about this, let’s consolidate conversation to that “official” sticky thread, and I’ll go ahead and close this one. Thanks for reporting, and sorry for the trouble!