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
content script question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
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, 10:30 am
From: CGS <cgsmcml...@gmail.com>
Date: Fri, 27 Jul 2012 16:30:03 +0200
Local: Fri, Jul 27 2012 10:30 am
Subject: content script question

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.
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


 
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.
CGS  
View profile  
 More options Jul 27 2012, 6:54 pm
From: CGS <cgsmcml...@gmail.com>
Date: Sat, 28 Jul 2012 00:54:27 +0200
Local: Fri, Jul 27 2012 6:54 pm
Subject: Re: content script question

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


 
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.
Tanushree Jindal  
View profile  
 More options Oct 27 2012, 3:31 am
From: Tanushree Jindal <tanushree.jin...@gmail.com>
Date: Sat, 27 Oct 2012 00:31:20 -0700 (PDT)
Local: Sat, Oct 27 2012 3:31 am
Subject: Re: content script question

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.

http://codereview.chromium.org/9965005/


 
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.
End of messages
« Back to Discussions « Newer topic