Reputation: 18619
When i console.log(chrome)
with google chrome browser i get certain properties but i find the 'runtime' property of chrome 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__()
so chrome.runtime is undefined.
and hence i am not able to 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/docs/extensions/mv3/manifest/externally_connectable. I am sure(correct me if i am wrong after going through above link) that a web page can communicate with a chrome extension. But not able to make it up through when the extension is installed from chrome store, however working perfectly in case of extension installed from local directory.
i am providing externallyConnectable as :
"externally_connectable": {
"matches": [
"*://local.mywebsite.com/*"
]
}
I have included the externally_connectable with "matches" property.. Now when i load unpacked directory to install extension, my web page get chrome.runtime.. but when i install extension from chrome store, the same web page on same browser does not get chrome.runtime.. why so?? in the end i still dont have chrome.runtime on the page ://local.mywebsite.com/. help me out.
Upvotes: 9
Views: 11358
Reputation: 18619
My problem get to solved by removing the plugin completely from chrome store and re-upload and re-publish the plugin again.
The problem was :
Initially i did not had 'externally_connectable' property, so wasn't able to get chrome.runtime
defined. Later when i included, then i was updating the chrome plugin.
And the main cause may be : 'Chrome store does not modify the 'manifest.json' (at least for certain properties like 'externally_connectable') just by updating the plugin by uploading. You may have to remove and re-upload to get manifest.json updated' (This is what i can conclude because of my experience, Please correct me if i am wrong with some valid reference source.)
and so 'chrome.runtime' remains undefined.
Later when i removed the plugin and re-uploaded, everything worked fine.
Upvotes: 2
Reputation: 688
You might have this issue which was previously already resolved:
chrome.runtime.sendMessage not working as expected
Try to check what sendMessage is availaible. If none are, then the chrome version is really old:
Chrome Extension: Port error: Could not establish connection. Receiving end does not exist.
Hope I helped, cheers!
Upvotes: 1