[Greasemonkey] addEventListener, DOMNodeInserted event in GM user script

arantius at gmail.com arantius at gmail.com
Tue Mar 7 09:43:24 EST 2006


On 3/7/2006 12:24 AM, Brian Donovan wrote:
> document.addEventListener('DOMNodeInserted',function(){alert('DOMNodeInserted
>  !');},true); window.addEventListener('load',function(){alert('load
> !');},true);
> 
> Why is it that ... only the latter ... will pop when those lines are
> present in a GM user script?

Because an in-line script in a page runs before the DOM is fully 
constructed, so the nodes haven't been inserted into the page yet.  GM 
on the other hand, runs at the "DOMContentLoaded" event, which is after 
nodes have been inserted into the document.  The whole DOM has been 
constructed already, in fact.
(Because GM runs later, to put it shorter.)


More information about the Greasemonkey mailing list