Is there a way for a content script to know when all handlers for an
event have returned?

Context:

I have a setup along the lines of:
Background page sends a message to content script with an action, e.g.
"click on element".
Content script does the action
Content script sends message back to background page informing it the
action has been done

This works fine, if the result of the action is quick.  But if the
action has side-effects, I run into the problem that while the action
itself is done, really it's still taking place (as its event handlers
are still running).  I need to know when all consequences of an action
have finished.

Some ideas, with underlying assumptions:

Assuming that the most recently added event handler is the final event
handler to be executed, I could add an event handler just before
sending the action, and only send the response to the background page
when that event has been fired.
Problem: If the thing being done is clicking on a link, the onclick is
done before the link is followed (and loading a (new) page is a
side-effect I care about).  A way to generalise a solution to include
link clicking would be very useful.  Could a content script with
run_at document_start be of any use in that case?

Assuming that when an event is fired, all of its handlers execute
before any code which has been queued up with setTimeout to run at a
`reasonably guessed to happen after the event happens' time (but not
assuming that at this time the handlers have finished, as they could
be doing long tasks), a script could be injected into the page with a
setTimeout(someFunc, someTime) in it, which triggers the response (so
it would happen in someTime + someDelta if the event handlers were
taking longer to run).

It's not good enough to simply hope that the event will be finished in
some arbitrary time.

Any better ideas, or thoughts on the assumptions underlying mine would
be appreciated! Thanks,

Daniel

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Chromium-extensions" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/chromium-extensions?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to