Live data from Hacker News

Chrome 59 has cross-platform headless support

chromestatus.com

21–30 of 161 posts

Re: Chrome 59 has cross-platform headless support

#21
post #3

Earlier quoted context omitted.

FWIW, you can do that now, using phantomjs (which is chrome) http://phantomjs.org/screen-capture.html

Also with https://wkhtmltopdf.org/ and http://pandoc.org/

Tried all of these and haven't found any as good as http://www.nightmarejs.org/

Re: Chrome 59 has cross-platform headless support

#26
post #6

Any way of scripting this to automate button clicks etc? I use PhantomJS for this now but found it to be incredibly unstable for complex pages.

There is an excellent library called nightmare (based on electron). If you need print-screens you can use xvfb

or wait for this issue: https://github.com/segmentio/nightmare/issues/224

Re: Chrome 59 has cross-platform headless support

#27
post #22

Please let this be capable of generating PDFs from HTML from the command line.

Is there an easy way to do the opposite? e.g. read PDFs as HTML (intended to be read through a remote shell), or text?

You might be able to tweak this pdf.js example to dump out its canvas element after it renders.

https://github.com/mozilla/pdf.js/blob/master/examples/learn...

Re: Chrome 59 has cross-platform headless support

#28
post #22

Please let this be capable of generating PDFs from HTML from the command line.

Is there an easy way to do the opposite? e.g. read PDFs as HTML (intended to be read through a remote shell), or text?

Extracting text from PDF is not hard, though PDF only contains low-level formatting instructions so the result might not be nice, especially if the original PDF has any non-trivial formatting, like pull quotes, multi-column text, etc. If you don't care about that or the correct "flow" of text, it should be easy enough to just find all the Tj and TJ operators and extract their operands. You might also need to reverse some ligatures though.

Producing nice semantic HTML is much harder, though also easy if you don't mind every word in a separate absolutely positioned div.

Many PDF reader software already contains empirically tuned routines to infer the text flow and generate text files (because the software needs to handle Select All and Copy), but they often produce bad results.

But if you just want to read a PDF on a remote machine over ssh, the easiest solution might be just transferring the file and then opening it locally, or use X forwarding and open the PDF with a graphic reader.

Re: Chrome 59 has cross-platform headless support

#29

This is fantastic. I'm using a combination of Chrome and PhantomJS for karma testing right now, for https://github.com/paypal/paypal-checkout and https://github.com/krakenjs/xcomponent . There are hundreds of tests opening up hundreds of iframes and popup windows, and sending a lot of cross-window messages, and that ends up being really memory hungry. Chrome deals pretty well with garbage collection, so long as I'm c…

I've been using post-robot and xcomponent a lot recently as I'm solving a bunch of similar challenges. Just wanted to say thank you for sharing your solutions and expertise.

Re: Chrome 59 has cross-platform headless support

#30
post #12

Also checkout https://github.com/cyrus-and/chrome-remote-interface for an easy way to fully control those headless instances

If you're using Go, https://github.com/knq/chromedp

It's also worth noting that the 57+ series has a nice embedded viewer you can use to view the actual viewport via devtools.

Post reply on HN