The event before the “download event” for the Firefox extension?

I am writing an extension for Firefox,

This is my XUL (no problem there)

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE overlay SYSTEM "chrome://locale/myDtd.dtd">
<page id="overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <script type="application/x-javascript" src="chrome://addon/content/test.js" />
</page>

And here is the problematic part of Javascript test.js

window.addEventListener("load",
    function(event) {
        var appcontent = window.document.getElementById("appcontent");
        appcontent.addEventListener("load",onEventLoad,true);
    }, true);

The second load listener for appcontent is too slow for my needs. The "load" event is fired when the DOM finishes loading.

My question is: does anyone have an idea on how to run the code as soon as the document starts loading (before the DOM loading event)? (it is desirable that an onBeforeLoad or onRequestStart event exists)

In Chrome extensions we can use "run_at": "document_start" in "manifest.json", and in Safari extensions we can use "Starting script" in the extension builder, but in Firefox ... I don't know how to do the same trick.

, DOM, ( ).

.

+3
3

:

http://blog.webmynd.com/2011/04/04/equivalent-to-beforeload-event-for-firefox-extensions/

Firefox http-on-modify-request:

Components.classes["@mozilla.org/observer-service;1"]
  .getService(Components.interfaces.nsIObserverService)
  .addObserver({
    observe: function(aSubject, aTopic, aData) {
      if ("http-on-modify-request" == aTopic) {
        var url = aSubject
          .QueryInterface(Components.interfaces.nsIHttpChannel)
          .originalURI.spec;
        if (url && url.match('facebook')) {
          aSubject.cancel(Components.results.NS_BINDING_SUCCEEDED);
        }
    }
  }
}, "http-on-modify-request", false);
+3

var appcontent = window.document.getElementById("appcontent"); eventlistener setInterval, , DOM ?

init();

function init(){
    var intval = setInterval ( "checkForElement()", 200 );
}

function checkForElement(){
    if (document.getElementById('appcontent') != 'undefined'){
        clearInterval(intval);
        var appcontent = window.document.getElementById("appcontent");
        appcontent.addEventListener("load",onEventLoad,true);
    }
}

, alert(document.getElementById('appcontent'));, , .

0

src appcontent XUL? , XUL , . , , XBL . , DOMContentLoaded . appcontent , .

0

All Articles