Question

I am wondering how I can add a JS file that runs on all pages opened in firefox and that will reload each time user opens a new page/tab.

I would like my script to load before the DOM (and if possible CSS) of the page has loaded.

Here is what I have so far (//COMMENTS were added just for better understanding purposes):

main.js

var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "http://*/*","https://*/*",//LOADS ON ALL PAGES (not sure if I'm correct)
contentScriptFile: data.url("performcheck.js"),//LOADS THE JS FILE I WANT
});



performcheck.js

if (document.domain=="www.google.com"){
    alert('Welcome Google user! I said it before the page loaded.');
}

I don't know in which folders I should be placing these files and what I should add to my

install.rdf or chrome.manifest file so that the script can be generated on every page.

Thanks in advance for your help.

Was it helpful?

Solution

Place the main.js in lib folder and performcheck.js in the data folder and that should be fine. Make sure "main": "main" is set in the package.json file (no need to mention this line if it is missing default is main.js)

There is no need to modify install.rdf its job is for describing the addon and compatibility.

Further information can be read from this documentation link https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top