Browse Source

fix: reuse blob URL on reload

In Chrome, if an old BLOB URL is revoked, sometimes the newly
generated BLOB URLs will be unable to reach.
Gerald 7 years ago
parent
commit
43ced8fadf
1 changed files with 11 additions and 7 deletions
  1. 11 7
      src/options/app.js

+ 11 - 7
src/options/app.js

@@ -48,12 +48,8 @@ function initScript(script) {
 function loadData(clear) {
   sendMessage({ cmd: 'GetData', data: clear })
   .then(data => {
-    if (store.cache) {
-      Object.keys(store.cache).forEach(url => {
-        URL.revokeObjectURL(store.cache[url]);
-      });
-      store.cache = null;
-    }
+    const oldCache = store.cache || {};
+    store.cache = null;
     [
       'cache',
       'scripts',
@@ -67,9 +63,17 @@ function loadData(clear) {
     if (store.cache) {
       Object.keys(store.cache).forEach(url => {
         const raw = store.cache[url];
-        store.cache[url] = cache2blobUrl(raw, { defaultType: 'image/png' });
+        if (oldCache[url]) {
+          store.cache[url] = oldCache[url];
+          delete oldCache[url];
+        } else {
+          store.cache[url] = cache2blobUrl(raw, { defaultType: 'image/png' });
+        }
       });
     }
+    Object.values(oldCache).forEach(blobUrl => {
+      URL.revokeObjectURL(blobUrl);
+    });
     store.loading = false;
   });
 }