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/addEventListeneroff/removeEventListeneremit(strictly for triggering handlers within the PhantomJS context)
Follow-up Questions:
Would it make sense to call
dispatchEventon any object other than a Window object (window,window.parent,window.opener,top,self, etc.) if trying to communicate with PhantomJS, though?I'd be fine with doing just the
CustomEventapproach, likely with an event naming convention ofphantomjs:foo(orphantom:foo, if you're still interested in dropping the "JS") like you mentioned. However, I haven't been able to find any existing signals or callbacks for connecting to such from the Qt side. As such, it seems like the best we could do [if allowing theCustomEventto be dispatched on any object] is either to:Or am I missing something?