There is a phantomjs example out there called waitfor.js I believe. You can modify it to check for the existance of svg tags. I'm pretty sure if those are in the dom then hc is done or almost done due to animation..
Let me know if you cannot find it. I have it somewhere.
Mike
For example, if I'm using Highcharts to render a chart, and I want a trigger a render once Highcharts is done processing.
Another method, but some may say is silly is to send an ajax request out. You can check using webpage.onresourceseny and webpage.onresourcerecevied.
If something is sent and not received the page is not yet done.
So your hc is done, triiger ajax to page which print true. Then the handler onresourcerecevied knows its complete.
If you can have a prior count of total hc on page this can be easy to accomplish.
Webpage.onresourcereceveid = function {
If (r_recevied == test_resource) {
Total_hc--
}
If (total_hc == 0) // page loaded
None the less when doing things like this don't make the page load take forver. It may be nice to die gracefully in the case where hc was not loaded in 3 seconds or something.
Setinterval if no exit or way out is set or even with the onreceived total_hc == 0. There is the potential for the output to stay inside of a phantomjs instance.
Just saying make sure of a way out.
I believe Ivan added an "onCallback" mechanism in 1.6 to address this (such that the client can trigger PhantomJS code) for GhostDriver.
~~James
--
page.evaluate(function() {...window.callPhantom(somethingFromThePage);});page.onCallback = function(somethingFromThePage) {...}
~~James--
Since window.postMessage requires a reference to the "other window", will PhantomJS attach a reference onto the WebPage's window object, like window.phantom (with a postMessage method: window.phantom.postMessage)?
Or would you just have the window postMessage to itself (window.postMessage) but with setting the targetOrigin to a special value like "PhantomJS", perhaps?
--
--
Going with window.postMessage does, however, utilize an existing API and leads to the introduction of PhantomJS-side handlers (page.onPostMessage/page.onMessagePosted) for such, which likely would've desired in future iterations anyway.
~~James
--
--
if (window.phantom && window.phantom.postMessage){
// targetOrigin needs to be "*" unless we give the phantom window a fake origin, e.g. "http://phantom.js"
window.phantom.postMessage("hi", "*");
}
--
page.evaluateAsync(function(done) {
setTimeout(function() {
done('rat');
}, 3000);
}, function(vermin) {
// vermin is 'rat'
});
--
--
Well, I am getting the impression that our opinions on this are too scattered and unproven to push into 1.7 before Saturday with ample testing. Would you all agree?
In the meanwhile....
Ivan: You've mentioned that you think the new version of QtWebKit has the support we need to implement the signals (or override the virtual methods, or whatever) for `Window.postMessage` calls. Can you refer us to any documentation, discussions, bugs, etc. on its implementation? I'd like to start looking at whatever info I can since I figure we will want to implement that functionality even if we choose not to utilize it for direct communication back to PhantomJS.
// Signature #1: Single argument, matches properties of spec
page.onMessageReceived = function(messageEvent) {
// `data` is not required to be a string, it can be anything that the "structured clone algorithm" can support... so basically JSON)
var data = messageEvent.data;
// Caller's origin (protocol + hostname + port)
var origin = messageEvent.origin;
// Not so sure we can provide `source`, which is a reference to the calling `Window` object
var source = messageEvent.source;
// Do stuff....
};
//Signature #2: Spread/splat the MessageEvent properties into individual arguments
page.onMessageReceived = function(data, origin, source){
// Do stuff....
};
We likely need to hash it again for 1.8. One criteria will be that the
client page should never know whether it runs under PhantomJS or not.
The current undocumented callback breaches this, any web page can
detect whether 'callPhantom' exists or not and thereby providing a
reliable sniffing mechanism.
> In the meanwhile....It does not exist right now, so the route must be specially
> Ivan: You've mentioned that you think the new version of QtWebKit has the
> support we need to implement the signals (or override the virtual methods,
> or whatever) for `Window.postMessage` calls. Can you refer us to any
> documentation, discussions, bugs, etc. on its implementation? I'd like to
> start looking at whatever info I can since I figure we will want to
> implement that functionality even if we choose not to utilize it for direct
> communication back to PhantomJS.
implemented for PhantomJS.
--
You received this message because you are subscribed to the Google Groups "phantomjs" group.--
To unsubscribe from this group and stop receiving emails from it, send an email to phantomjs+...@googlegroups.com.
Visit this group at http://groups.google.com/group/phantomjs?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.