diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 8b3b6a808..8b22f89aa 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -37,6 +37,7 @@ var chrome = self.chrome; var manifest = chrome.runtime.getManifest(); vAPI.chrome = true; +vAPI.opera = /\bOPR\/[\d.]+\b/.test(self.navigator.appVersion); var noopFunc = function(){}; @@ -1011,12 +1012,29 @@ vAPI.punycodeURL = function(url) { // https://github.com/gorhill/uBlock/issues/531 // Storage area dedicated to admin settings. Read-only. +// https://github.com/gorhill/uBlock/commit/43a5ed735b95a575a9339b6e71a1fcb27a99663b#commitcomment-13965030 +// Not all Chromium-based browsers support managed storage. Merely testing or +// exception handling in this case does NOT work: I don't why. The extension +// on Opera ends up in a non-sensical state, whereas vAPI become undefined out +// of nowhere. So only solution left is to test explicitly for Opera. + vAPI.adminStorage = { - getItem: function(key, callback) { - chrome.storage.managed.get(key, function(store) { - callback(store[key] || undefined); - }); - } + getItem: (function() { + if ( vAPI.opera ) { + return function(key, callback) { + callback(); + }; + } + return function(key, callback) { + try { + chrome.storage.managed.get(key, function(store) { + callback(store[key] || undefined); + }); + } catch (ex) { + callback(); + } + }; + })() }; /******************************************************************************/