eastboundr
eastboundr

Reputation: 1877

How to pass out ContentScript data out to a module-global variable in JavaScript?

I been working on a firefox extension project and now I'm stuck on this,

var abc = 123;

var pageMod = require("page-mod");
pageMod.PageMod({
  include: "*",
  contentScriptWhen: 'ready',
  contentScript:  'var newabc = 456;',
});

where abc is a global variable and newabc is a variable within the contentScript.

How do I make abc = newabc ?

Thanks!!

Upvotes: 4

Views: 873

Answers (1)

erikvold
erikvold

Reputation: 16558

For the Addon-SDK v1.0b3's PageMod API:

var abc = 123;

var pageMod = require("page-mod");
pageMod.PageMod({
  include: "*",
  contentScriptWhen: 'ready',
  contentScript:  'var newabc = 456;postMessage(newabc);',
  onAttach: function onAttach(worker) {
    worker.on('message', function(newabc) {
      abc = newabc;
    });
  }
});

Upvotes: 4

Related Questions