Answer the question
In order to leave comments, you need to log in
How to cast Chrome Extension API functions into variables?
Hello.
I have an extension for Google Chrome. There is a task to overtake this extension to browsers that support the Chrome Extension API (such as Yandex.Browser, Opera, etc.). Only as you know, not all browsers fully support all the features of the API. At the very least, Opera doesn't support chrome.storage.sync and some options in chrome.notifications.create . In order not to make an individual extension for each browser, it was decided to wrap functions with weak support in their own variable. chrome.storage.sync.get(keys, callback)
For example, to call instead of cbf.storage.sync.get(keys, callback)
. It is implemented like this:
var cbf = {};
cbf.storage = {};
cbf.storage.sync = {};
// browser_name задается чуть раньше
cbf.storage.sync.get = browser_name == "Chrome" ? chrome.storage.sync.get : chrome.storage.local.get;
cbf.storage.sync.get(function(sync_storage) { /* ... */ });
extensions::StorageArea:26 Uncaught TypeError: Cannot read property 'get' of undefined
Answer the question
In order to leave comments, you need to log in
And what you add there - chrome.storage.sync.get or chrome.storage.local.get - is it defined? What is there if output to the console?console.log(chrome.storage.local.get);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question