IndexedDB onbeforeunload Test

This page has just created (or attempted to create) an IndexedDB in your browser's storage. Saving to this database is done on your browser's onbeforeunload event (when this tab/window is closed or is refreshed). It will attempt to save around 10MB of three different sets of data. Which will show in the results section below if they in fact were saved and can be grabbed from your storage. "Did not get test data!" should appear three times on your first load.

There is no known spec or consensus for how this is supposed to happen, but since Indexed DB is asynchronous, one would expect the behavior to be that NO data would be saved, or that ALL data would be saved (storage functions processed on onbeforeunload could wait for finish). Currently, some data, can be saved, sometimes, depending on how fast your browser is, your hardware, how much data you are saving, and what browser function you are performing to initialize the onbeforeunload event. It's completely inconsistent.


No results were found.


Latest Chrome (37), will only be able to save the first set of data on a refresh, while closing the tab or window will allow enough time? to save more data (but not all), and only sometimes? Usually 2/3. Funilly enough, if this is run locally, even less can be saved. Running this same test on my 2013 Macbook Pro will allow all data to be stored, every time.

Similar situation with Firefox (33), except that on a close, it can usually get 3/3 - seems a bit faster.

Internet Explorer (11) can't seem to get anything saved in the onbeforeunload event.


There is none. There's no synchronous API for Indexed DB and localStorage is too small. Trying to prolong the onbeforeunload event with a blocking loop won't allow for any extra time for the saving to get done since it's also blocking the saving process. You may be able to create a work around by storing "some" data in localStorage, then updating it into Indexed DB on next load. But this will only work if you are storing small amounts of data. Sucks.

View on GitHubGist.