title: IndexedDB flush to disk on Chrome
body: <p>I'm facing an issue with IndexedDB on Chrome where I reload my page once the transaction returns a successful write.</p>
  
  <p>Problem is sometimes that data does not reflect after reload. I can solve this by giving a timeout of about 100ms before reload, which leads me to believe that the data is not flushed to disk everytime.</p>
  
  <p>Firexox has an <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#Adding_retrieving_and_removing_data" rel="nofollow noreferrer">experimental readwriteflush mode</a> which ensures data is flushed to disk before returning a success call, but can't seem to find a similar one for Chrome. Any suggestions?</p>
  
  <p>Here's my insert code:</p>
  
  <pre><code>const data = {type: type, value: value};
  
  const objectStore = StorageService.db.transaction(['localData'], 'readwrite').objectStore('localData');
  
  // readwriteflush doesn't work in chrome
  // const objectStore = StorageService.db.transaction(['localData'], 'readwriteflush').objectStore('localData');
  
  const requestSet = objectStore.put(data);
  
  requestSet.onerror = function (event) {
      alert('Error in saving data locally');
  };
  
  requestSet.onsuccess = function (event) {
      console.log('Data was successfully saved locally: ' + type);
      if (callback != undefined) {
          callback();
      }
  };
  </code></pre>
  
  <p>The callback has <code>location.reload = '/';</code> executed in it (along with some other things), so the page reloads after the onsuccess has been returned. </p>
  
  <p>After the page reloads, I cannot see any data on my IndexedDB storage, both via code and on developer tools. This does not always happen however, I've observed that this happens only when data is larger than usual.</p>