I’m using Add-on Builder Beta (Firefox) and I’m trying to do something like this:
(There are 3 sections in Addon Builder: Lib, Data, Libraries)
-
Get “def.htm” file from data section and open it in new tab
I do it with this:var tabs = require("tabs"); var data = require("self").data; tabs.open(data.url('def.htm')); -
Get the JSON definition from “def.htm”
def.htm looks like this:<html><head> <title>Def title</title> </head><body> <script type="text/javascript"> this.definition = { aaa: 1000, bbb: { ccc: { ddd: "eee", ... ... }; </script> </body></html> -
Call JS function and pass the definition to it:
It works with the Jetpack extension (on Firefox 3.5), here is the code:
jetpack.tabs.onReady(function() {
var window = this.contentWindow.wrappedJSObject;
var def = window.definition;
dowork (def);
});
I need the same functionality on Add-on SDK.
That’s a rather strange approach, why are you trying to get JSON data in such a complicated way? How about putting it into a file
data/definition.json(properly encoded then):And reading it out using the
requestpackage:But if you really want to access data in a tab – the Add-on SDK doesn’t allow direct access to content pages from your extension. You can use the
page-modpackage to inject a content script into this page that will then send the data back to the extension. Something along these lines: