0

This is the flow I'm trying to accomplish:

User clicks button on a regular webpage -> JSON message is sent to the extension -> Extension opens tab.

I understand that content scripts are needed to send the message to the extension:

contentscript.js

chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
  console.log(response.farewell);
});

src: Simple Messaging

some arbitrary "listener"

chrome.runtime.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"});
  });

src: Simple Messaging

Now, I'm confused about two things:

  1. How will contentscript.js talk to JSON variables loaded in the webpage?
  2. Which file listens to the messages?
Carpetfizz
  • 8,707
  • 22
  • 85
  • 146
  • Define "button on a regular webpage". Is this a webpage you control? If not, which buttons should be affected? – Xan Oct 30 '14 at 10:32
  • @Xan, sorry, this is a button on my own webpage and I have full access to its actions. – Carpetfizz Oct 30 '14 at 14:45
  • Then you don't need a content script even. See http://stackoverflow.com/a/26095346/934239 – Xan Oct 30 '14 at 14:47

0 Answers0