[Greasemonkey] Execution Order

Nikolas Coukouma lists at atrus.org
Tue Aug 16 05:16:43 EDT 2005


Gareth Simpson wrote:

> Hi,
>
> Can someone tell me what the expected execution order of
> Greasemonkey scripts is in 0.5?
>
> I have a script which I want to run after all scripts on the target
> page have completed execution.
>
> In 0.3 I was intercepting the load event of the window and adding
> my functionality there. This doesn't work in 0.5.
>
> In 0.5 all the scripts on the page (including those called from the
> load event) seem to execute followed by the Greasemonkey scripts.
>
> Except when they don't. Sometimes scripts in the load event seem
> to execute simultaneously with the Greasemonkey scripts.
>
> You (or at least I) can see the effect on these pages using the
> linked script :
>
> http://xurble.org/userscripts/order.html
>
> Navigating between the test pages, mostly I get a sequence of alert
> boxes - "Page Bottom", "On Load", "Greasemonkey". Occasionally
> though I get "Page Bottom" and then "On Load" and "Greasemonkey"
> simultaneously.
>
> I'm using FF 1.0.4
>
> Is this a known issue, a gap in my understanding or something new?
>
> Cheers
>
> Gareth

This is perfectly reasonable in Javascript. Obviously, while GM is
still injecting scripts when the load event fires. This is similar to
getting another keypress event while you're still handling the first
one. The language has no features to cope with concurrency
(synchronization via mutexes or semaphores) despite running in an
concurrent environment. The only thing I know of is the Synchronizer
class[1] that you can use from Rhino (a Java interpreter for JS).

If it's not vital, perhaps you could use setTimeout to run, say, one
second after the load event?

[1]
http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Synchronizer.html

-Nikolas



More information about the Greasemonkey mailing list