Reputation: 41
Right now I'm developing an add-on for firefox 26 and I need to know if there is an event that keeps listening all the time when we are browsing the web even if there a script running, and if the event has a kind of trigger when you reach a specific url and How can I use it? Por example I want to do something similar to the FoxyProxy add-on. The foxyproxy kept listening until it reaches a URL which redirects to a port or other ... how can I subscribe to that event, I'm new at this, please help me... Regards.
Upvotes: 4
Views: 165
Reputation: 1327
You want to use the sdk/system/events/ module. For example:
let { Cc, Ci } = require("chrome");
let events = require("sdk/system/events");
events.on("http-on-examine-response", afterLoad);
function afterLoad(e) {
var httpChannel = e.subject.QueryInterface(Ci.nsIHttpChannel);
var url = httpChannel.URI.spec;
// do what you want with the url
console.log("Loaded: "+url);
}
The full list of events you can listen for is here: https://developer.mozilla.org/en/docs/Observer_Notifications
Upvotes: 2
Reputation: 5830
It kind of sounds to me like you want to look at the tabs module in the Add-on SDK:
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/tabs.html
The simplest implementation would look like:
require('sdk/tabs').on('ready', function(tab) {
// do something here
console.log(tab.url);
});
For more guides on how to use the SDK:
https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/tutorials/index.html
Upvotes: 0