Return to Snippet

Revision: 26660
at May 5, 2010 19:42 by the_vinci


Initial Code
// contentscript.js - get inserted into the browser page
chrome.extension.sendRequest({greeting: "hello"}, function(response) {
  console.log(response.farewell);
});

// background.html - opens a listener to listen for requests
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.
  });

Initial URL


Initial Description


Initial Title
Google Extension Messaging

Initial Tags


Initial Language
JavaScript