[Greasemonkey] What is window.addEventListener('load', ...) required?

Jeremy Dunck jdunck at gmail.com
Fri Apr 15 09:04:09 EDT 2005

On 4/15/05, Mark Pilgrim <pilgrim at gmail.com> wrote:
> Subject says it all: under what circumstances would you want to delay
> execution of some portion of your script until window onload?  I ran
> across this comment in BetterDir, written at about 4 AM:

We originally injected on load, but that caused flickering.  So we
moved injection to DOMContentLoaded (a FF-specific event), which
worked great, except when it didn't.

Seems that the DOM's parsed and loaded when that event's loaded, but
internal magic is happening which assumes the DOM structure is stable
(and maybe non-blocking) between the DOMContentLoaded and
document.load events.

I can't find the first report, but I apparently knew about the problem
on Mar 21:

Therein, sil is replacing the entire document content w/ a new
document using document.write().

Here's the first report on list:

Wherein the script is replacing the entire document contents with
document.innerHTML = "foo".  Or at least, it was.  If only we had a
version archive...

So I thought I understood the problem (and the solution: don't replace
the entire document contents!), but then this data point:

Wherein the script simply pops alert on ebay.com.  It worked for me,
but crashed other's browsers.

But we may be moving before DOMContentLoaded, which why Aaron's been
talking about HTML Overlays lately.

Here's (sort of) an explanation of how that would be accomplished:

So.. We don't really know under which conditions the crash occurs, but
these rules of thumb seem to address the issue:
 * don't do anything blocking when first injected
 * don't replace the entire contents of the document when first injected.

... Of course, I may have missed a data point.

More information about the Greasemonkey mailing list