Search Unity

Question Chromebook WebGL context creation failed on Chrome versions >112

Discussion in 'Web' started by dseabolt_il, May 4, 2023.

  1. dseabolt_il

    dseabolt_il

    Joined:
    Jan 18, 2018
    Posts:
    6
    We have customers who are seeing Unity not start when Chrome updated to 112. I've done some preliminary investigation and found that it seems to be mostly effect Chromebooks running old Celeron processors and it seems to be failing when trying to create a context that has the attribute `"premultipliedAlpha":false`. It effects all WebGL projects, not just Unity builds.

    Since this doesn't seem to be Unity's fault per se, I'd like some help to figure out how to hijack the UnityModule and prevent it from setting that attribute. It's causing a lot of problems. I've done a grep in the Unity code and in my Project and can't find that phrase, so it must be in a binary file somewhere. Could I get some assistance?
     
  2. dseabolt_il

    dseabolt_il

    Joined:
    Jan 18, 2018
    Posts:
    6
    For anyone else who may be running into this issue, if you go on to your build machines and go to your Unity install location/WebGL Support/BuildTools/Emscripten/src there is a file called
    library_html5.js
    . In there if you scroll down to line 2157 for my version, but you're looking for a function that is setting up an array of attributes for createContext. In there I added these lines:
    Code (JavaScript):
    1.  
    2. console.log(“Overiding Unity default premultipliedAlpha”);
    3.  
    4. contextAttributes[“premultipliedAlpha”] = true;
    5.  
    Note, if your application relies on blending with the canvas, it won't work anymore. Hope this helps anyone else stuck here. It's a very hacky fix, and I'm assuming Chrome will fix it eventually. Here's the Chromium ticket if they ever do: https://issuetracker.google.com/issues/280659200
     
    jeffreylanters likes this.
  3. jeffreylanters

    jeffreylanters

    Joined:
    May 8, 2013
    Posts:
    10
    We've encountered the same issue where our games fail to start on Chromebooks that run ChromeOS 112. Your proposed temporary solution does fix the problem, but there's a simpler way to enable premultipliedAlpha without the need to delve into the compiler.

    You can easily overwrite the WebGL's Context Attributes in the createUnityInstance method. Simply provide the webglContextAttributes object to the UnityParameters and overwrite the required attributes. You can find more attributes that can be overwritten by visiting https://react-unity-webgl.dev/docs/api/webgl-rendering-context.

    Here's an example of how to implement it in the createUnityInstance method:

    Code (JavaScript):
    1. createUnityInstance(someCanvasReference, {
    2.   dataUrl: "unitybuild/module.data",
    3.   frameworkUrl: "unitybuild/module.framework.js",
    4.   codeUrl: "unitybuild/module.wasm",
    5.   // Add the `webglContextAttributes` object to the UnityParameters
    6.   webglContextAttributes: {
    7.     // Overwrite the required attributes
    8.     premultipliedAlpha: true,
    9.   },
    10. });
     
    dseabolt_il likes this.
  4. alexstonefilament

    alexstonefilament

    Joined:
    Jul 14, 2015
    Posts:
    1
    jeffreylanter's solution is for Unity 2020 and above. For older versions of Unity, use this syntax:

    Code (JavaScript):
    1. gameInstance = UnityLoader.instantiate("gameContainer", "Build/release.json", {
    2.   Module: {
    3.     webglContextAttributes: {
    4.       // Overwrite the required attributes
    5.       premultipliedAlpha: true,
    6.       preserveDrawingBuffer: false,
    7.     },
    8.   },
    9. });
    10.  
     
  5. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    I'm wondering if there's a performance impact to using the premultipliedAlpha workarounds noted above, ..I mean if we want WebGL builds working on the broken Chromebook Chrome versions, is it safe/performant just to enable premultipliedAlpha always, or should there be Chrome OS detection + Chrome browser detection (if Chromebooks run other browsers - I don't know anything about them)?

    A quick idea based on pages here and here I thought the below approach might work, but maybe it could be improved further with a version test so older versions could still run without the [potential] overhead of the workaround - does anyone have a tested/working approach to solve this conditionally? I don't have a Chromebook or know anybody with one, so I can't test this myself.. but maybe as a way to specifically target only that browser:
    Code (CSharp):
    1. premultipliedAlpha: (/\bCrOS\b/.test(navigator.userAgent) && Boolean(window.chrome))