Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home for chromium.org
« Groups Home
Message from discussion content script question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
CGS  
View profile  
 More options Jul 27 2012, 6:21 pm
From: CGS <cgsmcml...@gmail.com>
Date: Sat, 28 Jul 2012 00:21:24 +0200
Local: Fri, Jul 27 2012 6:21 pm
Subject: Re: content script question

Hi again,

I was trying to see where I went wrong with my messaging part, so, I
created a simple test extension:

manifest.js
========
{
    "name": "Content Script",
    ... // all the necessary things here
    "background": {
        "page": "background.html"
    },
    "content_scripts": [
        {
            "matches": ["http://127.0.0.1/*"],
            "js": ["page_contentscript.js"]
        }
    ],
    "permissions": [
        "background","tabs","<all_urls>"
    ]

}

background.html
============
<!doctype html>
<html>
<body>
<script src="extension_contentscript.js" type="text/javascript"></script>
</body>
</html>

page_contentscript.js
================
chrome.extension.sendMessage({greeting: "hello"}, function(response) {
  console.log(response.farewell);

});

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.

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 manifest permissions:

>     "permissions": [
>         "background","tabs","<all_urls>"
>     ],

> 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
>     });

> Am I missing anything?

> CGS


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.