A brief example of the latest idea for communicating with PhantomJS from the client-side.
This is the next revision of ideas discussed in a previous Gist:
https://gist.github.com/JamesMGreene/3716654
This example demonstrates shimming in the new communication channels under discussion via existing methods (WebPage#onCallback
and window.callPhantom
).
The example does, however, take advantage of a yet-to-be-implemented EventEmitter API for core modules in the PhantomJS outer context. This API would add the following methods to core modules as appropriate:
on
/addEventListener
off
/removeEventListener
emit
(strictly for triggering handlers within the PhantomJS context)
I would argue that we may need not any kind of
window.top.parent
override (my suggestions was either and not both parent and CustomEvent). Perhaps we can get away by having a special name of the custom event, e.g.:which means that the event can be emitted in any place, wherever
dispatchEvent
is available.Any other kind of mapping for the convention, e.g.
phantomjs:foo
->page.on("foo", ...)
, is also a further possibility.