1
votes

Hi i am currently working on a firefox Addon-sdk and i would like to know if there is a way to import JS files which uses DOM objects(like window) into the main.js code. I did use "mozIJSSubScriptLoader" but the addon keeps returning all the dom objects defined in the loaded scripts as "NOT DEFINED" and i think this should be because the main.js code does not have access to the DOM. Please, let me know if there is any other way to import/load these js files. Thanks in advance.

2
Why do you need access to the entire JS doc in main.js? Typically you would execute whatever code you want on those objects in a contenct script then pass the results out to main.js - willlma
Well i have declared and initiated few variables in those files and i need to use those in main.js file. If there is anyway to get the varaible alone that would also work. The problem here is that the main.js does not accept DOM objects which is why my addon returns that window is undefined and also contentScriptFile does not have access to SDK modules. . so i cannot use require and get Components import and import the files using mozIJSSubScriptLoader - Vickmaniac
I think the best solution will be to pass only the variables you need from the DOM objects into main.js using port.emit rather than trying to pass entire DOM objects. - willlma
So, i should include that file as a content script and get the variable using port.emit ? is that what you are saying ? - Vickmaniac

2 Answers

0
votes

You can get access to a window like this:

const { getMostRecentBrowserWindow } = require('sdk/window/utils');
var aXULBrowser = getMostRecentBrowserWindow();

or you can enumerate through them all, that should be something in sdk/window/utils called "somethingEnumerateSomething"

0
votes

Based on your comments in my other solution posted in this topic:

Posting as separate answer as I think the solution is totally different. If this is the right answer Ill delete my previous solution.

Check out the following: