The code in a Greasemonkey user script gets invoked when the DOMContentLoaded
event fires. It is a DOM event implemented by Mozilla, similar to window.onload. However, since it waits only for the DOM to load, instead of the entire page (including images, style sheets, and etc.) it happens sooner. The DOMContentLoaded
event does not fire for non-text content types such as images.
Although it happens sooner than the Load
event (onload
), there is still a delay between when the page starts loading and when this event fires. This delay is the amount of time that it takes for the HTML content of the page itself to load. Greasemonkey injects user scripts at DOMContentLoaded
time. Thus, there is a period of time when the page is loading, and may be showing on screen, before Greasemonkey has injected into the page. This delay is often known as flicker, where the page appears to load, then changes after a (usually) short delay.
Generally, flicker is a problem that should be ignored. If, however, a script author decides that it must be avoided there is at least one technique.
Using a combination of userContent.css and @-moz-document() rules, the page can be hidden completely. The Greasemonkey script would then be crafted to undo this CSS rule, after altering it, thereby never showing the page in its pre-greased state.