I am trying to do some messages parsing in between the extension popup and
a webpage designed to interact with the popup. Reading the documentation, I
found that the recommended way is via content script (
http://code.google.com/chrome/extensions/content_scripts.html), but I got
this from the popup:
Uncaught TypeError: Cannot call method 'addListener' of undefined
The popup is loading a javascript file in which a function calls (one
message off at the time):
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
// do something with the request and answer back via
sendResponse
});
extension_contentscript.js
===================
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
I loaded the extension and I checked the console:
Uncaught TypeError: Cannot call method 'addListener' of undefined
exactly at the line: chrome.extension.onMessage.addListener
More than that. I started index.html on 127.0.0.1 and I got:
Uncaught TypeError: Object #<Object> has no method 'sendMessage'
at the line: chrome.extension.sendMessage
As you can see, it's nothing else but copy-paste from
http://code.google.com/chrome/extensions/messaging.html (chapter "Simple
one-time requests") and it seems the "extension" object from within
"chrome" object is not recognized at all. Either I missed something in the
documentation, or the example from there doesn't work. In either case I am
pretty much frustrated, so, any help in understanding how that works is
much appreciated.
I am using Chromium 18.0.1025.168 (Developer Build 134367 Linux) Ubuntu
12.04.
On Fri, Jul 27, 2012 at 4:30 PM, CGS <cgsmcml...@gmail.com> wrote:
> Hi everyone,
> I am trying to do some messages parsing in between the extension popup and
> a webpage designed to interact with the popup. Reading the documentation, I
> found that the recommended way is via content script (
> http://code.google.com/chrome/extensions/content_scripts.html), but I got
> this from the popup:
> Uncaught TypeError: Cannot call method 'addListener' of undefined
> The popup is loading a javascript file in which a function calls (one
> message off at the time):
> chrome.extension.onMessage.addListener(
> function(request, sender, sendResponse) {
> // do something with the request and answer back via
> sendResponse
> });
Nevermind, I found the problem: Chromium has no extension object.
Everything works fine in Google Chrome for Linux. That is pretty much a
mess considering they are both shipped from Google.
> I loaded the extension and I checked the console:
> Uncaught TypeError: Cannot call method 'addListener' of undefined
> exactly at the line: chrome.extension.onMessage.addListener
> More than that. I started index.html on 127.0.0.1 and I got:
> Uncaught TypeError: Object #<Object> has no method 'sendMessage'
> at the line: chrome.extension.sendMessage
> As you can see, it's nothing else but copy-paste from
> http://code.google.com/chrome/extensions/messaging.html (chapter "Simple
> one-time requests") and it seems the "extension" object from within
> "chrome" object is not recognized at all. Either I missed something in the
> documentation, or the example from there doesn't work. In either case I am
> pretty much frustrated, so, any help in understanding how that works is
> much appreciated.
> I am using Chromium 18.0.1025.168 (Developer Build 134367 Linux) Ubuntu
> 12.04.
> Regards,
> CGS
> On Fri, Jul 27, 2012 at 4:30 PM, CGS <cgsmcml...@gmail.com> wrote:
>> Hi everyone,
>> I am trying to do some messages parsing in between the extension popup
>> and a webpage designed to interact with the popup. Reading the
>> documentation, I found that the recommended way is via content script (
>> http://code.google.com/chrome/extensions/content_scripts.html), but I
>> got this from the popup:
>> Uncaught TypeError: Cannot call method 'addListener' of undefined
>> The popup is loading a javascript file in which a function calls (one
>> message off at the time):
>> chrome.extension.onMessage.addListener(
>> function(request, sender, sendResponse) {
>> // do something with the request and answer back via
>> sendResponse
>> });
I think the reason for this issue would have been that sendMessage and onMessage have been introduced only after Chrome-20. Previous versions used sendRequest and onRequest instead which had a similar API but were less safe.
On Saturday, July 28, 2012 4:24:27 AM UTC+5:30, CGS wrote:
> Nevermind, I found the problem: Chromium has no extension object. > Everything works fine in Google Chrome for Linux. That is pretty much a > mess considering they are both shipped from Google.
> CGS
> On Sat, Jul 28, 2012 at 12:21 AM, CGS <cgsmc...@gmail.com <javascript:>>wrote:
>> Hi again,
>> I was trying to see where I went wrong with my messaging part, so, I >> created a simple test extension:
>> I loaded the extension and I checked the console:
>> Uncaught TypeError: Cannot call method 'addListener' of undefined
>> exactly at the line: chrome.extension.onMessage.addListener
>> More than that. I started index.html on 127.0.0.1 and I got:
>> Uncaught TypeError: Object #<Object> has no method 'sendMessage'
>> at the line: chrome.extension.sendMessage
>> As you can see, it's nothing else but copy-paste from >> http://code.google.com/chrome/extensions/messaging.html (chapter "Simple >> one-time requests") and it seems the "extension" object from within >> "chrome" object is not recognized at all. Either I missed something in the >> documentation, or the example from there doesn't work. In either case I am >> pretty much frustrated, so, any help in understanding how that works is >> much appreciated.
>> I am using Chromium 18.0.1025.168 (Developer Build 134367 Linux) Ubuntu >> 12.04.
>> Regards, >> CGS
>> On Fri, Jul 27, 2012 at 4:30 PM, CGS <cgsmc...@gmail.com <javascript:>>wrote:
>>> Hi everyone,
>>> I am trying to do some messages parsing in between the extension popup >>> and a webpage designed to interact with the popup. Reading the >>> documentation, I found that the recommended way is via content script ( >>> http://code.google.com/chrome/extensions/content_scripts.html), but I >>> got this from the popup:
>>> Uncaught TypeError: Cannot call method 'addListener' of undefined
>>> The popup is loading a javascript file in which a function calls (one >>> message off at the time):
>>> chrome.extension.onMessage.addListener( >>> function(request, sender, sendResponse) { >>> // do something with the request and answer back via >>> sendResponse >>> });