Reputation: 1006
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:
So my question is, does anyone have successfully install jQuery in the main method of a Firefox Add-On?
Upvotes: 4
Views: 1878
Reputation: 4167
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's manifest.json
. Take a look at my firefox extension's main.js
. It looks like this:
exports.main = function() {};
var { MatchPattern } = require("match-pattern");
var pageMod = require("page-mod");
var data = require("self").data;
pageMod.PageMod({
include: [/.*phpminiadmin.*/, /.*phpmyadmin.*/, /.*devadmin.*/],
contentScriptWhen: 'ready',
contentScriptFile: [data.url('jquery-1.7.2.min.js'),data.url('jquery-ui-1.8.20.custom.min.js'),data.url('bootstrap.min.js'),data.url('querysaver.js')]
});
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 to lib/
.
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.
Upvotes: 4