Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Resolved [Unity 2020.2 - 2021.1] UnityCache indexedDB database could not be opened in firefox private mode

Discussion in 'Web' started by suiboli314, Jan 29, 2021.

  1. suiboli314

    suiboli314

    Joined:
    Apr 8, 2020
    Posts:
    9
    • WebGL built by unity 2020.2
    • Decompress fallback enabled
    • Have read this thread but doesn't seem help
    Behavior:
    Firefox 85.0 and 84.0.2 doesn't work
    • Access built WebGL both on local and remote server with error:
      Code (Console):
      1. [UnityCache] indexedDB database could not be opened
      2. The Gamepad API will only be available in secure contexts (e.g., https).
      3. IndexedDB is not available. Data will not persist in cache and PlayerPrefs will not be saved.
      4. // ===== Error Loop start here ===== //
      5. still waiting on run dependencies:
      6. dependency: dataUrl
      7. (end of list)
      8. still waiting on run dependencies:
      9. dependency: dataUrl
      10. (end of list)
      11. ***
    • Game paused maybe because the loop is not end. No alert prompts. Error only shown in console.
    • Reload tab doesn't fix the issue.
    • Confused what's wrong with Firefox. I am not a full stack developer.
    Chrome 88 works
    • Access built WebGL both on local and remote server successfully and game is playable, but with some errors in console:
      Code (Console):
      1. getGamepad will now require Secure Context. Please update your application accordingly.
      2. staticInit
      3. still waiting on run dependencies:
      4. dependency: wasm-instantiate
      5. (end of list)
      6. // does not loop
    • indexedDB and dataUrl specified data file will successfully load later (in next 23th lines of output).
      [UnityCache] 'http://path/to/dataURL.data' successfully downloaded and stored in the indexedDB cache
    • It seems Chrome stops waiting automatically.
    Custom WebGL Template
    WebGL is embedded inside iframe
    Code (Javascript):
    1. <!DOCTYPE html><html lang="en-us">
    2. <head><meta charset="utf-8">
    3.     <title>{{{ PRODUCT_NAME }}}</title>
    4.     <style>
    5.     html { box-sizing: border-box; }
    6.     *,
    7.     *:before,
    8.     *:after { box-sizing: inherit; }
    9.     body { margin: 0; background: #444; }
    10.     #unity-canvas { width: 100vw; height: 100vh; }
    11.     canvas { width: 100%; height: 100%; display: block; }
    12.     </style>
    13. </head>
    14. <body><canvas id="unity-canvas"></canvas></body>
    15. <script>
    16. var buildUrl = "Build";
    17. var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
    18. var config = {
    19.     dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
    20.     frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
    21.     codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
    22. #if MEMORY_FILENAME
    23.     memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
    24. #endif
    25. #if SYMBOLS_FILENAME
    26.     symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
    27. #endif
    28.     streamingAssetsUrl: "StreamingAssets",
    29.     companyName: "{{{ COMPANY_NAME }}}",
    30.     productName: "{{{ PRODUCT_NAME }}}",
    31.     productVersion: "{{{ PRODUCT_VERSION }}}",
    32. };
    33.  
    34. var canvas = document.querySelector("#unity-canvas");
    35. var unityGame;
    36. var script = document.createElement("script");
    37. script.src = loaderUrl;
    38. script.onload = () => {
    39.     createUnityInstance(canvas, config, (progress) => {
    40.     }).then((unityInstance) => {
    41.         unityGame = unityInstance;
    42.     }).catch((message) => {
    43.         alert(message);
    44.     });
    45. };
    46. document.body.appendChild(script);
    47.  
    48. function getTrainingParams() {
    49.     let trainingParams = window.parent['getTrainingParams']();
    50.     unityGame.SendMessage('EventSystem', 'receiveData', JSON.stringify(trainingParams));
    51. }
    52. </script>
    53. </html>
    54.  
     
  2. suiboli314

    suiboli314

    Joined:
    Apr 8, 2020
    Posts:
    9
    Just read this post.
    I didn't realize my Firefox was opened in private mode by default, which may break indexedDB.
    No idea as well why Firefox private mode break indexedDB created by 2020.2.
    Nevertheless, Firefox private mode still works fine for WebGL app built by 2019.4 (current 18f).
    But the post talks about 2019.2. Is this a reoccurred issue?

    The post stated issue about Chrome in Incognito mode.
    My chrome in Incognito mode doesn't break the WebGL app and indexedDB as mentioned in my post #1.
     
    Last edited: Jan 30, 2021
  3. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Looking at the code, this is clearly a bug in the WebGL Data Caching feature. Turning off Data Caching should work around the problem.

    I have added a task to our team board to fix incognito mode support. If you'd like to track the progress, please report the bug using Unity's bug reporter tool. That will then go through the full QA loop.
     
  4. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Actually, nevermind, I see the problem, and pushed a fix to the code. If you want to fix it locally, you can apply the following changes to C:\Program Files\Unity\Hub\Editor\<unity version>\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\UnityLoader\XMLHttpRequest.js:

    Code (JavaScript):
    1. diff --git a/PlatformDependent/WebGL/UnityLoader/XMLHttpRequest.js b/PlatformDependent/WebGL/UnityLoader/XMLHttpRequest.js
    2. index 0256d777990f..5f0e2dab5bf9 100644
    3. --- a/PlatformDependent/WebGL/UnityLoader/XMLHttpRequest.js
    4. +++ b/PlatformDependent/WebGL/UnityLoader/XMLHttpRequest.js
    5. @@ -31,7 +31,7 @@
    6.          while (cache.queue.length) {
    7.            var queued = cache.queue.shift();
    8.            if (cache.database) {
    9. -            cache.execute.apply(cache, queued);
    10. +            cache.execute.apply(cache, queued.arguments);
    11.            } else if (typeof queued.onerror == "function") {
    12.              queued.onerror(new Error("operation cancelled"));
    13.            }
    14. @@ -87,7 +87,10 @@
    15.              onerror(e);
    16.          }
    17.        } else if (typeof this.database == "undefined") {
    18. -        this.queue.push(arguments);
    19. +        this.queue.push({
    20. +          arguments: arguments,
    21. +          onerror: onerror
    22. +        });
    23.        } else if (typeof onerror == "function") {
    24.          onerror(new Error("indexedDB access denied"));
    25.        }
    Let me know if you have any questions.
     
    protycon and rkvieira like this.
  5. Amalaryk

    Amalaryk

    Joined:
    Nov 14, 2013
    Posts:
    7
    Can confirm that it worked
     
    Last edited: Feb 5, 2021
    jukka_j likes this.
  6. Laur3nt1u

    Laur3nt1u

    Joined:
    Apr 30, 2014
    Posts:
    25
    Please add the fix to unity 2021 because the problem it's in the latest unity 2021.1.0b6 and 2020.2.4f1
     
    jukka_j likes this.
  7. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Thanks, yeah, that fix is in the process of being backported to earlier Unity versions.
     
  8. ry0shi

    ry0shi

    Joined:
    Mar 22, 2021
    Posts:
    1
    vscode doesn't allow me to save changes because the code has more than 9 errors in it.
    upload_2021-5-4_12-28-47.png
     
  9. Laur3nt1u

    Laur3nt1u

    Joined:
    Apr 30, 2014
    Posts:
    25
    OK, see the - and + ? It means the line with - was removed and the lines with + were added

    So you replace "cache.execute.apply(cache, queued);" with "cache.execute.apply(cache, queued.arguments);"
    and "this.queue.push(arguments);" with "this.queue.push({arguments: arguments, onerror: onerror});"

    It's still not fixed in 2021.1
     
  10. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    604
    Not fixed in Unity 2021.1.7f1 @jukka_j

    Thank you.
     
  11. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Thanks for pinging. Looking into this, it has not been high in priority to process by our backports team, because there haven't been any reports in the system of users having been affected by the issue.

    I took the patch now manually over to 2020.3 and 2021.1. In Unity 2021.2 and newer, this whole code has actually been rewritten to use the more modern Fetch API, so this XHR based code will no longer exist there.
     
    suiboli314, Fesener and roka like this.
  12. mickfcna

    mickfcna

    Joined:
    May 13, 2019
    Posts:
    46
    Hi,
    The bug is still present on Unity 2021.3.
    Regards,
     
    Gordon_G likes this.
  13. dkardell_gw

    dkardell_gw

    Joined:
    Nov 20, 2020
    Posts:
    2
    Still not fixed in 2021.3.14f1
     
    Gordon_G and AliAlbarrak like this.
  14. F-N

    F-N

    Joined:
    Apr 8, 2013
    Posts:
    11
    I can confirm that it's not fixed in 2021.3.14f1
    Any news about this @jukka_j ?
     
  15. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    Are there any updates for this issue?
     
  16. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    @jukka_j is there an issue we can track for this fix to make its way to 2021.3?
     
    LilGames likes this.
  17. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    577
    Getting this problem too in 2021.3.32f1, Microsoft Edge 121.0.2277.83 (Official build) (64-bit)
    Options on:
    Exceptions, Brotli compression, data caching, hash file names
     
    Last edited: Jan 30, 2024