0

When I'm getting a message from popup I want to execute a script, simply:

chrome.runtime.onMessage.addListener(function(message, sender, response) {

      chrome.tabs.executeScript({file: "content.js"});
});

My problem: content.js needs the data from message. How do I pass it?

Community
  • 1
  • 1
Billie
  • 8,938
  • 12
  • 37
  • 67

1 Answers1

1

Try

chrome.runtime.onMessage.addListener(function(message, sender, response) {
    chrome.tabs.executeScript({code: paramName=paramValue},function() {
        chrome.tabs.executeScript({file: "content.js"});
    });
});

They both get injected into the same isolated world, so content.js can refer to the same variables.

Teepeemm
  • 4,331
  • 5
  • 35
  • 58