1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

This addresses Opera seemingly not supporting managed storage.

As reported in 43a5ed735b (all_commit_comments)
This commit is contained in:
gorhill 2015-10-24 09:20:39 -04:00
parent b5eeeee572
commit 26b70a1e64

View File

@ -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();
}
};
})()
};
/******************************************************************************/