Search Unity

Official Bug Fix: Unity WebGL Support for Chrome/Edge on macOS Big Sur

Discussion in 'Web' started by Emily_Diehl, Jan 30, 2021.

  1. Emily_Diehl

    Emily_Diehl

    Unity Technologies

    Joined:
    Dec 18, 2019
    Posts:
    4
    Hello all,

    We’ve identified an issue with our loader’s handling of a new user agent string that some browsers use to identify macOS Big Sur. The impact is that Unity WebGL games will fail to run on Chrome or Edge for macOS users running Big Sur.

    To address this issue, we have made the following bug fix to the Unity loader.js.

    https://issuetracker.unity3d.com/issues/unity-webgl-builds-do-not-run-on-macos-big-sur

    This fix requires developers to upgrade their Unity Editor and rebuild their WebGL projects. We have addressed this issue in the following Unity releases: 2018.4.31f1, 2019.4.16f1, 2020.1.15f1, 2020.2.0f1, and Unity 2021.1.0a2 and above. We are also looking into what we can do for developers that cannot rebuild their existing games, and will provide additional updates here and on the issue tracker when more information becomes available.

    Please let us know if you have any questions!
     
    Last edited: Jan 30, 2021
  2. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    Thanks - you don't mention 2021.1, is that because it's already in b4?

    Edit: "Fixed in Unity 2021.1.0a2 and above" - guess I should have read that before posting :rolleyes:
     
    Emily_Diehl likes this.
  3. Emily_Diehl

    Emily_Diehl

    Unity Technologies

    Joined:
    Dec 18, 2019
    Posts:
    4
    No worries, and thank you for catching that! I've updated my post to make it more clear. :)
     
    adamgolden likes this.
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    This issue was originally reported against macOS Beta in https://forum.unity.com/threads/bug...ls-in-ios-14-public-beta.942484/#post-6152134 , where it was noticed that pre-release Safari in macOS beta channel was unable to run Unity WebGL builds.

    A symptom of this issue was an error box at page startup, that prints

    Uncaught TypeError: Cannot read property '1' of null

    or the progress bar hangs at 0%, and observing the web page console prints the same error.

    Back then, patches were deployed to all Unity release channels like Emily mentions, though when it came time to release, it looks like Apple actually froze Safari's user agent to an earlier version, sidestepping the problem altogether, hence the fixes were not needed after all for Safari.

    The root cause of the issue was an old piece of system information identification script in Unity that was not robustly future proof to major OS version number changes. I.e. it is not a bug in Safari, or in Chrome.

    In the past year, there has been intent for browser vendors to "freeze and mask" navigator user agent strings in time, deprecating navigator.userAgent to avoid increasing fingerprinting possibilities on the web. See
    - https://www.chromestatus.com/feature/5704553745874944
    - https://groups.google.com/a/chromium.org/g/blink-dev/c/-2JIRNMWJ7s/m/yHe4tQNLCgAJ
    - https://medium.com/naver-fe-platform/prepare-for-client-hints-freezing-user-agent-9c0ea1ddd02c
    - https://bugzilla.mozilla.org/show_bug.cgi?id=1609304

    It looks like Apple had done just that with the macOS Big Sur release. Firefox has the UA string also frozen for Big Sur. Chrome has a tracking bug for the same here: https://bugs.chromium.org/p/chromium/issues/detail?id=955620 .

    What caught us by surprise was that the same issue that Unity had with the pre-release version of Safari Beta channel, also now unsurfaced in Chrome 88 Stable release. Now we are (quite painfully so) aware that older already deployed Unity games are unable to run on this Chrome version.

    Here is what to do:

    A. First, if you are an author of a Unity game, you can resolve the issue by updating and rebuilding your Unity project using one of:
    - 2018.4.31f1 or newer,
    - 2019.4.16f1 or newer,
    - 2020.1.15f1 or newer,
    - 2020.2.0f1 or newer,
    - 2021.1.0a2 or newer.

    This is the preferred and cleanest fix.

    B. However, if you have a project that is for some reason unable to update to a newer Unity editor version, you do not have the source project any more, or if you are a maintainer of existing built content (a website admin, a portal author, etc.), and cannot rebuild the project(s), we have created a hotfix script that can be used to patch already produced Unity game builds. You can find the script attached in this post.

    Copy the script to the same directory as the build, and run python patch_unity_big_sur_build.py to patch. Or run python patch_unity_big_sur_build.py --help for detailed instructions. You can use the script to mass patch a whole directory tree.

    C. If you just want to run your favorite Unity game that is affected by this bug in Chrome on macOS Big Sur, and the author has not yet provided an updated game build, you can adjust the user agent header posted by Chrome by following the instructions at https://www.searchenginejournal.com/change-user-agent/368448/#close . Using one of the offered user agent strings, e.g. for "Chrome - Mac", should work. Also clearing out the field by replacing it with a single space bar or period character will avoid the issue.

    Hopefully one of these methods should unblock you to be able to resume work and play. We are terribly sorry for the trouble, please let us know if further issues persist. Especially if there are any blockers or regressions that would prevent from updating projects to one of the newer Unity versions.
     

    Attached Files:

    aromana likes this.
  5. TheRoccoB

    TheRoccoB

    Joined:
    Jun 29, 2017
    Posts:
    54
    Hi I help run simmer.io one of the unity hosting sites.

    Sounds like the script above will work for most use cases, however for us to run a script like that across our thousands of UnityLoaders would be a real hassle (we have all kinds of CDN caching that would have to be invalidated too).

    I think I have a fix that won't require a rebuild and since we do inject our own javascript before UnityLoader.js is loaded. I "monkey patch" regex.prototype.exec to make it not throw an error. As long as this code is run before UnityLoader.js is loaded, it looks like this solves the problem on our side.

    This most likely could be slipped in a <script> tag towards the top of any exported unity HTML files. It's a gnarly hack but it works (I think!)

    Code (JavaScript):
    1. (function(exec) {
    2.     RegExp.prototype.exec = function() {
    3.         arguments[0] = arguments[0].replace('Mozilla/5.0 (Macintosh; Intel Mac OS X 11', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10');
    4.         return exec.apply(this, arguments);
    5.     };
    6. })(RegExp.prototype.exec);
     
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    So dirty, I like it :)
     
    ashishsfb and MadeFromPolygons like this.
  7. thomasneuro

    thomasneuro

    Joined:
    Mar 22, 2019
    Posts:
    8
    Hi, can someone confirm that the issue is fixed in 2018.4.31f1? I created a new build with Unity updated to 2018.4.33f1 but still no loading happening. If I switch the user Agent to something else it loads and I confirm that the correct version is uploaded.
     
  8. Richard85

    Richard85

    Joined:
    Aug 5, 2015
    Posts:
    1
    Hi, are there any recommendations for supporting older versions of Unity such as 2017?
    Unfortunately it's not economically viable for us to upgrade Unity version, since our hosted web game relies on an older version of Timeline. Upgrading unity breaks the majority of our game content but we're also obliged to support browser updates for the next 4 years... It's not always possible for devs to upgrade unity version, sometimes we're on a budget.
     
  9. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Looking at our database, I do see that the fix did land to 2018.4 tree on 2020-11-12. If you are still having errors with this specific issue, please open a bug report, along with the console error stack trace of the issue you have, and a test project.
     
  10. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    I would recommend creating a web page template with TheRoccoB's code from above https://forum.unity.com/threads/bug...e-edge-on-macos-big-sur.1048310/#post-6817892 wrapped into a script element at the beginning of the html page. That could be stored in a HTML web page template, so that it carries over to all new made builds without needing to manually update each time.
     
  11. viknesh2020

    viknesh2020

    Joined:
    Jul 19, 2016
    Posts:
    52
    This post got my eye when I was looking for a solution to the progress bar issue on the iPad. I am using

    - Unity 2019.4.10f1
    - macOS Big Sur 11.2.1
    - Mac pro

    In contrary to the mentioned post, I don't have any issues in my mac. Both chrome and safari opens the page and builds are running smooth without progress bar issues. However, when I serve the build and checked in my iPads, the progress bar hanged at 0%. I checked the builds in an android phone and an iPhone 6 plus. They used chrome and safari respectively. These two have no issues at all. Problem is only with iPads. They are

    - iPad Air 2 running iPad OS 14.6 (18F72), both safari and chrome (version 91.0.4472.80) having issue.
    - iPad pro 2nd Generation iPad OS 14.6 (18F72), both safari and chrome (version 91.0.4472.80) having issue.

    Any help would be appreciated !
     
    Last edited: Jul 9, 2021
  12. muhammadimyusoff

    muhammadimyusoff

    Joined:
    Oct 3, 2018
    Posts:
    2
    Wait why no LTS version mentioned here? Are they trash because it's recommended for beginners? Yeah I think I will go for Unreal instead of Unity, better unsub your channels too. I don't care Unreal is hard but I suppose LTS versions are First Class for support as you guys recommended for "newbies".

    Thanks, really helping us the noobs.
     
  13. everettjohn

    everettjohn

    Joined:
    Mar 7, 2023
    Posts:
    2
    Google's Chrome browser recently announced that they have added WebGL support to the browser. This means developers can now create games and interactive applications that use the GPU to render graphics on the web. However, this feature is not yet supported on macOS. We have taken it upon ourselves to create a plugin for Unity which will make WebGL work on macOS. We hope to make this plugin available for public use soon!