Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

UnityLoader stuck when IndexedDB can't be opened

Discussion in 'WebGL' started by CrazyGamesCom, Jul 28, 2021.

  1. CrazyGamesCom

    CrazyGamesCom

    Joined:
    Nov 11, 2016
    Posts:
    16
    UnityLoader for Unity 2020 gets stuck when the IndexedDB can't be opened.
    This happens when using private browsing and hosting the game in a cross-domain iframe.
    A user can work around it by allowing third party cookies ( which at least under chrome also unblocks access to IndexedDB), but the actual problem lies with UnityLoader.

    How to reproduce:

    Create an index.html file containing just an iframe to your Unity game, eg:

    Code (HTML):
    1. <!DOCTYPE html>
    2. <html>
    3. <body>
    4.   <iframe src="https://www.crazygames.com/embed/1v1battle-build-fight-simulator" frameborder="0" allow="autoplay; fullscreen:*; microphone; focus-without-user-activation*; wake-lock; gamepad;" allowfullscreen="true" referrerpolicy="origin-when-cross-origin"></iframe>
    5. </body>
    6. </html>
    7.  
    Start a webserver:

    python3 -m http.server


    Open a private window in either Chrome or Firefox, and you should see that your game gets stuck.

    Potential fix (?):

    If you place a breakpoint in the downloaded loader.js file at
    cacheControl: function(e) ...
    you'll see that the first call is for the .data file, and cache control is set to "must-revalidate". You can change the Xhr network call by placing a breakpoint near:

    Code (JavaScript):
    1. var n = l.companyName && l.productName ? new l.XMLHttpRequest({
    2.                 companyName: l.companyName,
    3.                 productName: l.productName,
    4.                 cacheControl: l.cacheControl(l[e])
    5.             }) : new XMLHttpRequest;
    6.  
    and modifying the cacheControl to "no-store". This fixes the loading behavior as Unity does not wait for IndexedDB to open, which will never happen.

    Afaik we can change the cacheControl through createUnityInstance and set it to no-store for all requests, but that is very detrimental for the user.
     
  2. CrazyGamesCom

    CrazyGamesCom

    Joined:
    Nov 11, 2016
    Posts:
    16
    This issue is still causing issues for us, and any insight would be useful