firefox addon - Open page from main.js and pass data to it -
i trying create simple test addon 1 thing: open html page (located in info folder) main.js, pass generated json can display. i've figured out complex way using message-passing , cloning unsafewindow.options, there must simpler way?
ps. i'm happy utilize 'addon-page' module if right way it...
a simple template opening tab, when tab ready, attach content scripts, pass parameters, , setup message handlers:
in addon module:
var resourceurl=require("sdk/self").data.url; require("sdk/tabs").open({ url:resourceurl("index.html"), onready:function(tab){ var worker=tab.attach({ contentscriptfile:["support.js","content.js"].map(resourceurl), contentscriptoptions:{}, //parameters passed content script }); worker.port.on("ready",function(msgin){ worker.port.emit("acknowledge",msgout); }); } });
and in content script; send "ready" message , recieve "acknowledge" message:
self.port.on("acknowledge",function(msgin){}); self.port.emit("ready",msgout);
there might changes handling of parameters url
and/or contentscriptfile
, such relative paths allowed without need require("sdk/self").data.url. not sure if speculation/proposal or if it's implemented; haven't checked.
also think addon-page
depreciated , hasn't worked since upgrade australis ui (i.e. navigation bar no longer hidden special uris about:addons).
firefox-addon firefox-addon-sdk
No comments:
Post a Comment