I'm having major problems when I decided to port a Chrome extension to Firefox. One of the problems is that jQuery won't install itself in the "Lib/main.js" file. The error I get is the following:
ReferenceError: window is not defined
It seems that the window object is just not defined at the main method of a Firefox Add-On.
I understand that the extension itself doesn't need a committed window object because it doesn't represent an html page. But this makes it impossible to install jQuery while I want to take advantage of the ajax method and search-algorithm in dom elements.
I've tried several methods but they all failed:
- Retrieve the window object from an active tab (Failed to send the window-element because the sendMessage() method is part of the window-object)
- document.createElement (Failed because there is also no document-object)
- Some random stuff which also failed
So my question is, does anyone have successfully install jQuery in the main method of a Firefox Add-On?
Lib/main.js
is not where you have to put your application code. There you would put your initialization code. Like we did in chrome'smanifest.json
. Take a look at my firefox extension'smain.js
. It looks like this:It is the
pageMod
that would allow you to load your javascript on a page's context, which is of course inside a separate world w.r.t the page's own context.The scripts that you wish to load should reside inside
../data
with respect tolib/
.Take a look at folder structure of my addon. https://github.com/juzerali/Don-t-lose-your-query/tree/master/Firefox-Addon. I don't remember correctly but you might be needing to include api-utils.
I found it helpful to use Firefox's SDK.