Chrome.runtime undefined when extension is installed from chrome storage

When I console.log(chrome) with google chrome browser I get certain properties, but I believe that the "runtime" chrome property is not available.

 app: Object csi: function () { native function GetCSI(); return GetCSI();} loadTimes: function () { native function GetLoadTimes(); return GetLoadTimes();} webstore: Object __proto__: Object __defineGetter__: function __defineGetter__() { [native code] } __defineSetter__: function __defineSetter__() { [native code] } __lookupGetter__: function __lookupGetter__() { [native code] } __lookupSetter__: function __lookupSetter__() { [native code] } constructor: function Object() { [native code] } hasOwnProperty: function hasOwnProperty() { [native code] } isPrototypeOf: function isPrototypeOf() { [native code] } propertyIsEnumerable: function propertyIsEnumerable() { [native code] } toLocaleString: function toLocaleString() { [native code] } toString: function toString() { [native code] } valueOf: function valueOf() { [native code] } get __proto__: function __proto__() { [native code] } set __proto__: function __proto__() 

therefore chrome.runtime is undefined.

and therefore I cannot use chrome.runtime.sendMessage for my extension

How to resolve the above?

EDIT:

my code is:

  if(typeof(chrome) === 'undefined'){ result.isChromeBrowser = false; return next(result); } else { result.isChromeBrowser = true; } console.log(chrome.runtime); // undefined //check whether the chrome runtime is available or not ... if(!chrome.runtime){ result.isChromeRuntimeAvailable = false; console.log(result); } else { result.isChromeRuntimeAvailable = true; } 

EDIT 2:

from here: https://developer.chrome.com/extensions/manifest/externally_connectable.html . I am sure (correct me if I am mistaken after following the link above) that the web page can link to the chrome extension. But it was not possible to execute it when the extension was installed from the chrome repository, however, it works fine if the extension is installed from the local directory.

I provide externallyConnectable as:

 "externally_connectable": { "matches": [ "*://local.mywebsite.com/*" ] } 

I have included externally_connectable with the "matches" property. Now, when I download the unpacked directory to install the extension, my web page receives chrome.runtime .. but when I install the extension from the chrome store, the same web page in the same browser does not receive chrome.runtime .. why so ?? in the end, I still don't have chrome.runtime on the page: //local.mywebsite.com/. help me.

+6
source share
2 answers

My problem is solved by completely removing the plugin from the chrome storage and reloading and republishing the plugin again.

The problem was this: Initially, I did not have the "externally_connectable" property, so I could not determine chrome.runtime . Later, when I turned it on, I updated the chrome plugin. And the main reason may be this: β€œChrome repository does not modify manifest.json (at least for certain properties, such as externally_connectable), just updating the plugin by downloading. You may need to uninstall and re-download to get manifest.json updated '(This is what I can conclude because of my experience, please correct me if I am mistaken in some valid link source.)

and therefore 'chrome.runtime' remains undefined.

Later, when I removed the plugin and downloaded it again, everything worked fine.

+2
source

You may have this problem that was previously resolved:
chrome.runtime.sendMessage does not work as expected

Try checking if sendMessage is available. If not, then the chrome version is really old:
Chrome extension: Port error: connection failed. End of reception does not exist.

I hope I helped, cheers!

+1
source

All Articles