How to score the functionality of the Chrome Extension API variables?


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 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, callback) to call the, callback). It is done like this:

var cbf = {}; = {}; = {};
// browser_name set earlier = browser_name == "Chrome" ? :;

Only problem is that it doesn't work. When you call the function in the console error is thrown: { /* ... */ });

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.

July 9th 19 at 13:13
1 answer
July 9th 19 at 13:15
And what you put in there - or - it is defined? What is it, if print it to the console?

Yes, and are built-in methodsused in Chrome extensions.

Here is a good demonstration of the problem:

If you type console.log(;, it prints the following:

Image is clickable. - clifton83 commented on July 9th 19 at 13:18
: what if you try to wrap your function?

Something like: = {
get: function (/*string or array of string or object*/ keys, /*function*/ callback) {
// here - forwarding at any given store, depending on the browser
}; - Leon59 commented on July 9th 19 at 13:21
in principle, we did so:

var cbf = {}; = {}; = {};
cbf.notifications = {}; = function() { 
 if (browser_info['name'] == "Chrome") {
 if (arguments.length === 1) {[0]); }
 else if (arguments.length === 2) {[0], arguments[1]); }
 else {
 if (arguments.length === 1) {[0]); }
 else if (arguments.length === 2) {[0], arguments[1]); }

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
: maybe the context is not enough? - Leon59 commented on July 9th 19 at 13:27

Find more questions by tags Extensions for browsersJavaScriptGoogle Chrome