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
« Groups Home
Not able to figure out message passing
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
  3 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
 
Gaurang  
View profile  
 More options Jan 21 2010, 5:53 am
From: Gaurang <shahgo...@gmail.com>
Date: Thu, 21 Jan 2010 02:53:06 -0800 (PST)
Local: Thurs, Jan 21 2010 5:53 am
Subject: Not able to figure out message passing
Hi guys,
I am learning how to make chrome add-on and was just checking how
message passing thing works, but I am facing a problem in making it
work. I am taking the simple example from http://code.google.com/chrome/extensions/messaging.html
page but it's not working.

I want to My background.html page to send a request to content.js file
only when someone click on the browser button. for that i have done
something like this

background.html page
======================
<html>
<script>
  function getPageandSelectedTextIndex() {
  chrome.tabs.getSelected(null, function(tab) {
                chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function
(response) {
                        console.log(response.farewell);
                });
        });
        }
chrome.browserAction.onClicked.addListener(function(tab) {
        getPageandSelectedTextIndex();

});

</script>
</html>

content.js
=========================================
chrome.extension.onRequest.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"});
    else
      sendResponse({}); // snub them.
  });

i was thinking message will be logged in console when i will click on
the button. but i m not able to see any message there.

can anybody please tell me what's wrong going on here ??

Thanks in advance


 
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.
Arne Roomann-Kurrik  
View profile  
 More options Jan 21 2010, 1:43 pm
From: Arne Roomann-Kurrik <kur...@chromium.org>
Date: Thu, 21 Jan 2010 10:43:27 -0800
Local: Thurs, Jan 21 2010 1:43 pm
Subject: Re: [crx] Not able to figure out message passing

Hi,

     I tried copying and pasting your code into a test extension and I when
I pressed the browser action button, "from the extension" was printed in the
current HTML page's console, and "goodbye" was printed in the background
page's console.  Keep in mind that the pages run in different contexts, so
you'll need to open the console for each one to see both messages.

     Is it possible that your content script is not being injected properly?
 Could you share your manifest file?  Which HTML pages are you testing this
on?

~Arne


 
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.
Ernest Delgado  
View profile  
 More options Jan 21 2010, 2:18 pm
From: Ernest Delgado <erne...@google.com>
Date: Thu, 21 Jan 2010 11:18:47 -0800
Local: Thurs, Jan 21 2010 2:18 pm
Subject: Re: [crx] Not able to figure out message passing
To open the console for the background pages click on the links that
show up in your extensions list.

On Thu, Jan 21, 2010 at 10:43 AM, Arne Roomann-Kurrik


 
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     Older topic »