Skip to content

Commit

Permalink
This addresses Opera seemingly not supporting managed storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 24, 2015
1 parent b5eeeee commit 26b70a1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){};

Expand Down Expand Up @@ -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();
}
};
})()
};

/******************************************************************************/
Expand Down

0 comments on commit 26b70a1

Please sign in to comment.