1

Assume a panel injected:

   //main.js
    var ext = require("sdk/panel").Panel({
      width: 300,
      height: 500,
      contentScriptFile: [data.url("js/angular/angular.min.js"),
                          data.url("js/angular/angular-route.js"),
                          data.url("js/app.js"),
                          data.url("js/utilities.js"),
                          data.url("js/services.js"),
                          data.url("js/directives.js"),
                          data.url("js/controllers.js"),
                          data.url("js/popup.js")],
      contentScriptWhen: "ready"
    });

I can attach a listener to DOM of the active tab to detect some events:

if(window.customObj != undefined)
{
  window.postMessage(window.customObj, window.location.href);
}

how to get the object I'm sending by this custom message inside popup.js or main.js?

1 Answer 1

2

Your main script can only communicate with content scripts, including those injected into tabs and those injected into panels. Your content scripts can communicate with your main scripts and with page scripts. So, in order to get something from a page script to main.js, your path needs to be:

page script/DOM --> content script

content script --> main script

And, optionally, main script --> panel script

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.