[UnityCache] indexedDB database could not be opened Error

Hello,

What appears to be randomly we will get this error with all of our WebGL games, when this occurs the game will just progress to the end of the WebGL loading bar and then just get stuck and never load, which makes sense.

Unfortunately I cannot reproduce it, it does happen randomly, nothing seems to stand out, expect that error message is always there.

Has anyone figured out a way to fix this error?

Hey,

Yeah we’ve been having the issue as well. I just found out where this issue is (or where I think it is). It appears to be related to a issue in UnityLoader.js:

try {
  var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
  var openRequest = indexedDB.open(databaseName);
  openRequest.onupgradeneeded = function (e) {
    var objectStore = e.target.result.createObjectStore(store, { keyPath: "url" });
    ["version", "company", "product", "updated", "revalidated", "accessed"].forEach(function (index) { objectStore.createIndex(index, index); });
  };
  openRequest.onsuccess = function (e) { initDatabase(e.target.result); };
  openRequest.onerror = function () { initDatabase(null); };
  setTimeout(openRequest.onerror, 1000);
} catch (e) {
  initDatabase(null);
}

The relevant line of code that is causing the issue is: setTimeout(openRequest.onerror, 1000). Basically, what seems to be happening is that the loader waits for IndexedDB to start up for 1 second then gives up. If the user has a slower machine this might happen. This will just cause PlayerPrefs to not save and data caching to fail. I think Unity fixed the data caching crash in the early 2018 releases, but the underlying issue still seems to exist.

You can reliably reproduce the error if you put the below JavaScript on your page. It will delay IndexedDB opens by 5 seconds.

(function() {
    var delegate = window.indexedDB.open;

    window.indexedDB.open = function(databaseName) {
        var orgRequest = delegate.call(this, databaseName);

        var fakeRequest = {};

        orgRequest.onsuccess = function(e) {
            fakeRequest.result = orgRequest.result;
            setTimeout(function() {
                fakeRequest.onsuccess(e);
            }, 5000);
        };

        return fakeRequest;
    };
})();

How to fix it (TLDR):

I think you can avoid the issue by upgrading to the most recent version of Unity or turn off “data caching” in the publishing settings in WebGL’s player settings (more info here).

Either way though, the PlayerPrefs will stop working occasionally until Unity fixes the UnityLoader.js file. I’m pretty sure this issue still exists in Unity 2018.2. You could change UnityLoader.js to have a longer timeout, but that’s kind of annoying to do (if you want to I can walk you through that process).

2 Likes

Thanks,

That is really useful.

However for us it looks like the entire game fails to load, which is much worse than just not having player prefs, have you seen this happen as well?

We are running our builds on Latest 2018.1, we have flipped to 2018.2 as we like to give a month for patches to come out.

Yes. That’s what I meant by the data cache crashing. I observed it in 2017.2, and I thought they fixed it in 2018.1, but maybe not? Try compiling with “data caching” turned off. This fixed the freeze in loading for us.

If you want to force the IndexedDB failure so that you can test it, put the second piece of JavaScript from above into your web page.

So this what I think is happening to you:

  • IndexedDB takes too long to start and UnityLoader.js gives up loading IndexedDB.
  • Data caching crashes, because IndexedDB didn’t start.
  • The loading routine freezes.

Ok, Thanks I wasn’t sure if that is what you meant, I am going to pass this along to our deployment dev and see if there is anything we can do about this.

What is “Data caching crashes, because IndexedDB didn’t start” ?
My Firefox version have bugs with IndexedDB and this unity code, related to “data caching” option, log to console “indexedDB database could not be opened”, simple, and not crashes. Why it should crash?

Same problem with Unity 2018.3 in Chrome

I am getting this problem sometime while i am using unity 2018.9. I even unable to change the time duration in unityloader.js file because it is minified and i am unable to find the location of that syntax.
Disabling data caching is not a suitable option i guess because it won’t allow faster load. How you solve this issue?

Hey did you solve the problem?

Unityloader.js is a mini file, you can’t edit the timeout time? how can you increase the time?

I have updated to latest unity 2019.8.3 but it sometime get the problem.

Still happen even 2018.3.9f1 (Yesterday)

The timeOut number should just be able to set from unity editor

I’m having the same issue as well…

You can search for setTimeout function that has 1000 as a value

I didn’t find any setTimeout with 1000 value, there are several setTimeout in my unitylaoder.js like

setTimeout(o.callback.bind(null,e,o),0)

or
etTimeout(a.onerror,1e3)
but no time out with 1000 value. How did you get it?

@MFKJ 1e3 means 1000

e means exponent which e3 is a notation for * 10^3

2 Likes

Oh thanks, but it available on two places

setTimeout(a.onerror,1e3)

and

setTimeout(r,1e3)

where should i change and what should i write, the ideal value that dont produce the error?

where should i change

I don’t know I replace both

the ideal value that dont produce the error

Don’t know too I just put 1e4 which is 10 sec. You might try 1e5

2 Likes

Thanks for you help, i will implement it as you said but we still require a better and proper solution. If anyone found please share.

MFKJ, just by doing that it solves the problem, right?

Edit: Sounds like it worked for me.

Yeah by increasing the time, i never found any report that the problem is producing again. But i still searching for better and proper solution as you can forget to edit the compile code after build.

2 Likes