Chrome.extension.onMessage undefined

I have a simple plugin that just does something like this:

chrome.extension.onMessage.addListener(function(msg, _, sendResponse) { log("Got message from background page: " + msg); }); 

Unfortunately, when my panel is loaded, the following error is displayed:

 TypeError: Cannot call method 'addListener' of undefined 

and according to my tests chrome.extension.onMessage is undefined

According to this page http://code.google.com/chrome/extensions/messaging.html I have to have access to this chrome API from my page, so it has to be something small so that I disappear here .. .

+7
source share
3 answers

Note that the chrome.extension.onRequest and chrome.extension.sendRequest , as originally suggested in this answer, are deprecated from Chrome 33.


You have to use

 chrome.extension.onRequest 

instead

 chrome.extension.onMessage 

And on the original page or any other extension scripts:

 chrome.tabs.sendRequest 

instead

 chrome.tabs.sendMessage 

(documentation is out of date ... warning for google team;))

+3
source

Just a note: Yandex browser (mainly focused on Russians), which is also based on Chromium (as of 11/10/2012, version 1.0), has. * Request method instead. * Message. Thanks a lot to Ciprian Amariei for the tip, it saved me a lot of time!

PS: In fact, this should be a comment on the answer of Ciprian Amariei, but, unfortunately, I can not leave comments, and although this information can be very useful for those who are developing extensions for the Yandex browser.

0
source

Make sure you are using the latest version of Google Chrome. Older versions do not have the chrome.extension.onMessage API.

0
source

All Articles