Hello.
I have the extension for Google Chrome. The challenge is to surpass this extension on browsers that support Chrome Extension API (such as Yandex.Browser, Opera, etc.). Just as we know, not all browsers fully support all of the features of the API. At least Opera doesn't support
chrome.storage.sync and some settings in
chrome.notifications.create. Not to do for each individual browser extension, it was decided to wrap functions with weak support in their own variable. For example, instead of
chrome.storage.sync.get(keys, callback)
to call the
cbf.storage.sync.get(keys, callback)
. It is done like this:
var cbf = {};
cbf.storage = {};
cbf.storage.sync = {};
// browser_name set earlier
cbf.storage.sync.get = browser_name == "Chrome" ? chrome.storage.sync.get : chrome.storage.local.get;
Only problem is that it doesn't work. When you call the function in the console error is thrown:
cbf.storage.sync.get(function(sync_storage) { /* ... */ });
The error text:
extensions::StorageArea:26 Uncaught TypeError: Cannot read property 'get' of undefined
It seems that I do not understand something. Prompt, please, as correctly.

Here is a good demonstration of the problem:
If you type
console.log(chrome.storage.local.get);
, it prints the following:Image is clickable. - clifton83 commented on July 9th 19 at 13:18
Something like:
cbf.storage.sync = {
get: function (/*string or array of string or object*/ keys, /*function*/ callback) {
// here - forwarding at any given store, depending on the browser https://developer.chrome.com/extensions/storage#ty...
}
}; - Leon59 commented on July 9th 19 at 13:21
Although the solution seems to me not very elegant, and indeed, it would be cool to know why the above code did not give the expected results. For self-development, so to speak. - clifton83 commented on July 9th 19 at 13:24