Skip to content
Advertisement

chrome.runtime is undefined when extension installed from chrome store

When i console.log(chrome) with google chrome browser i get certain properties but i find the ‘runtime’ property of chrome is not available.

JavaScript

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 :

JavaScript

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 :

JavaScript

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement