.css selector for page screenshot robot and screenshot robot performance

Archived from the Transloadit support forum. Originally posted on March 13, 2014; details may be outdated, see our docs for current behavior. Original thread

Hey,

Currently I use screenshot robot for generating some type of page facebook share preview.
This preview should contain only part of the page.
I tried to use phantomjs app for that and it actually works fine, doing screenshot by css selector.
In phantomjs it is done like this:

var getBoundingRect = function() {
return page.evaluate(function(selector) { return document.querySelector(selector).getBoundingClientRect(); }, SELECTOR); }; page.clipRect = getBoundingRect();
var b64 = page.renderBase64(‘PNG’);

I don’t like phantomjs solution because there is issues with bunch of simultaneous requests; just phantomjs built-in server isn’t enough and requests should be queued somewhere (and queue should be accessible through phantomjs that could be a problem too because there’s possible incompatible nodejs queue-cli libraries). Moreover, screenshot requests have certain performance requirements that may result in incresing number of servers to handle it.

I don’t really want to mess with that all, and, since I’m already using transloadit media handling, I decided to try transloadit screenshot robot.

There’s no option to set selectors to screenshot only part of page. Currently I’m rendering different static page for that.

So proposal is to add css selector to screenshot robot. I know that I could pass screenshot to cropping robots but it isn’t looks good. Actually, it isn’t very important for me, I could live with static rendering or different page.
More important if how robust screenshot robot? Would it work with something like 5 requests per second? (it’s unprobable but possible scenario)

Thanks,
Igor

Hi Igor,

We use http://wkhtmltopdf.org/. Which is ok but doesn’t support css selectors like your current phantomjs setup does unfortunately. Sometimes it hangs on pages for quite some time. We kill it and have it retry, then it works.
In the end this means screenshots are made in a reliable way - but sometimes (I’d say <1% of our jobs, but still) it takes longer due to this bug.

About scaling. As with all our tools: jobs go in a queue and we scale up if we detect that queue building up. We have a base capacity of 16 octacore machines and that will surely suffice for your scenario of 5 per second without us needing to scale though.

We’ll upgrade wkhtmltopdf soon and that will hopefully resolve the ‘hanging’ issue, fwiw.

Hope this helps,
Kevin