Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.extension.onMessage is 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 shown:

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 should be able to access this chrome API from my page so it has to be something small that I am missing here...

like image 866
ganoro Avatar asked Jun 28 '12 14:06

ganoro


1 Answers

Please note methods chrome.extension.onRequest and chrome.extension.sendRequest, as originally suggested in this answer, are deprecated as of Chrome 33.


You should use

chrome.extension.onRequest

instead of

chrome.extension.onMessage

And in background page or any other extension scripts:

chrome.tabs.sendRequest

instead of

chrome.tabs.sendMessage

( the documentation is outdated... alert to google team ;) )

like image 109
Ciprian Amariei Avatar answered Sep 28 '22 06:09

Ciprian Amariei