Firefox addon: how to fire an event when a page loads * starts *?

I wrote a sidebar:

  • which retrieves the current page URL
  • makes a personal server call with a url
  • and displays contextual information in the sidebar

This function is currently called on the following events:

  • when you turn on the addon
  • when loading windows
  • when loading appcontent
  • in tabselect

However, there are times when a webpage takes too long to fire the load event. Therefore, what I would prefer is a way to call the function of my addon as soon as the first request for the current page is sent .

, . Progress-Listener, (, ).

// . .

+3
2

, Observer , . , , "http-on-modify-request" ( ).

:

var MyAwesomeObserver = {
observe: function(subject, topic, data)
{
    if (topic == "http-on-modify-request") {
        MyLogger.info('Yosssssssss! '+topic); //customer Logger that uses nsIConsoleService
        MyAwesomeObject.notSoAwesomeFunction(); //invoke the custom method here
    }
},

get observerService() {
    return Components.classes["@mozilla.org/observer-service;1"]
    .getService(Components.interfaces.nsIObserverService);
},

register: function(){
    this.observerService.addObserver(this, "http-on-modify-request", false);
},

}
   MyAwesomeObserver.register();
+1

, , - "DOMContentLoaded". , "", , .

0

Source: https://habr.com/ru/post/1762632/


All Articles