views:

481

answers:

1

Hi, I am trying to develop a firefox plugin, which should be executed, whenever a page is loaded.Can someone please tell me which event to use it. In firefox, document.ready gets executed when I open a new window and it does not gets executed, when I open a new tab :(. Any help is appreciated. Thanks

+3  A: 

Originally I was hooking into DOMContentLoaded, but this took too long as it won't fire until Firefox has loaded the DOM tree for the page and any of its iframes.

Load was similarly slow because it requires the page to fully load as well as all its images.

Ultimately, after going through those, as well as setting up XPCOM for nsIWebProgressListener.onLocationChange and a few others, I ultimately settled on DOMTitleChanged as such:

appcontent.addEventListener("DOMTitleChanged", events.onPageLoad, true);

(Note that DOMTitleChanged seems to fire even when the HTML page has no <title> attribute, or has an equivalent <title> to the previous page.)

I don't remember 100% why I settled on DOMTitleChanged but I believe it was because it was the best fit for my needs -- which is, basically, the quickest way to get the user's navigated URL without waiting for anything to load while simultaneously firing on every conceivable way a new page is loaded... new tabs, page changes, and all else.

The only catch is that you will need to add code to manually look up the URL in your add-on's overlay startup code, as unless you addEventListener() before FF starts loading the first page on new window, you will have added your event listener too late to reliably catch that initial page load. (This is because a new, isolated instance of your add-on is loaded every time Firefox opens a new Window.)

Tom the Junglist