mercredi 25 mars 2015

Firefox add-on SDK: Run content script in all open pages and any new ones


Let's say I have a simple content script, such as window.alert("Hey there"); console.log("Content script").


I cannot figure out a way in the SDK that will make the script run on each open window and tab and also allow it to run on every new one.


Using tabs, the script will run on all new opened windows and tabs but will ignore those that have already loaded:



require("sdk/tabs").on("ready", function(tab) {
tab.attach({
contentScript: 'window.alert("Hey there");'
});
});


Using pagemod with an include pattern of "*", the script will run only on windows and tabs with a non-blank URL:



require('sdk/page-mod').PageMod({
include: "*",
contentScriptWhen: "ready",
contentScript: 'window.alert("AAAAAAAAA");'
});


I'm probably missing something simple that will allow me to implement this correctly. What is the right way to call a content script on all open and new pages?





Aucun commentaire:

Enregistrer un commentaire