Live data from Hacker News

Puppeteer: Headless Chrome Node API

github.com

71–80 of 105 posts

Re: Puppeteer: Headless Chrome Node API

#71

Is there an equivalent of this for C#? I use Selenium a lot and find it annoying. Be interested to see if this is much better.

Under the covers this uses the DevTools protocol which has a number of projects around it: https://github.com/ChromeDevTools/awesome-chrome-devtools/#c... A C# binding was added just recently: https://github.com/BaristaLabs/chrome-dev-tools

Yes, I understand it's just a protocol but it's a pain writing it by hand especially when I just want to test it out on some existing projects Vs selenium.

Thanks for the binding link. Will check it out this weekend.

Re: Puppeteer: Headless Chrome Node API

#72
> Crawl a SPA and generate pre-rendered content (i.e. "SSR").

I've been maintaining (thanks to this team and Headless Chrome) a convenience API based on this feature. Some additional features:

  * React checksums for v14 and v15 (v16 no longer uses checksums)
  * preboot integration for clean Angular server->client transition
  * support for Webpack code splitting
  * automatic caching of XHR content
https://www.prerender.cloud/

and for the crawling or to delegate your single-page app hosting and server-side rendering entirely https://www.roast.io/

Re: Puppeteer: Headless Chrome Node API

#73
post #47

Does anyone know if it's possible to take a screenshot of a specific DOM element? (instead of the entire page)

Yes using the `clip` option of screenshot(), you can get these dimensions from an element's getBoundingClientRect().

full example of screenshoting a DOM element:

https://github.com/GoogleChrome/puppeteer/issues/306#issueco...

Re: Puppeteer: Headless Chrome Node API

#74
post #67

How can this work on Cloud Functions/Amazon Lambda/Azure Functions without installing the dependencies each time it has to run? Haven't done anything before with those serverless approaches.

It probably will not run on AWS Lambda as the version of Node required by Puppeteer is too recent.

From puppeteer readme[1]

> Puppeteer requires Node version 7.10 or greater

From AWS website[2]

> AWS Lambda supports the following runtime versions:

> Node.js – v4.3.2 and 6.10.3

[1] https://github.com/GoogleChrome/puppeteer/blob/master/README...

[2] http://docs.aws.amazon.com/lambda/latest/dg/current-supporte...

Re: Puppeteer: Headless Chrome Node API

#75
post #47

Does anyone know if it's possible to take a screenshot of a specific DOM element? (instead of the entire page)

Yes using the `clip` option of screenshot(), you can get these dimensions from an element's getBoundingClientRect().

Thank you. That's perfect.

Re: Puppeteer: Headless Chrome Node API

#76
post #37

It's funny how open the market for browser automation is. Everyone needs to switch off phantomJS in the next few years and is looking for the easiest option. Sadly, there's probably no money on the line. But you will get your buggy software used by huge corporations for years to come!

I'm not super familiar with this space, can you explain further why everyone needs to switch from PhantomJS?

Re: Puppeteer: Headless Chrome Node API

#77
post #22
post #9

So first there was Selenium's JSON Wire protocol, then came the W3C WebDriver spec and now we're back to browser-specific implementations? As someone who's tried/is trying to automate Firefox/Chrome/Safari/IE in a consistent fashion, my only question is: WHY?

Based on a quick read of the API, my interpretation is that this is not targeting people who are trying to automate every browser, but those who need to automate any browser. In that context, it's dead-simple to use, and someone with very little experience should be able to get a working prototype in under 5 minutes. For my use case, it's closer to "wget/curl with JS processing" than "automating a user's browsing exp…

+1 to this

The primary use-case for headless-chrome is to support stuff like scraping/crawling JavaScript-dependent sites and services, and emulating user workflows to retrieve data or trigger side effects that couldn't otherwise be achieved with something more low-level (curl, manual HTTP requests w/ Node's HTTP/S API etc).

headless-chrome would be used for the functionality of a server-side microservice, rather than for automated testing of UI/UX, there are already more appropriate projects to achieve that.

Re: Puppeteer: Headless Chrome Node API

#78
post #67

How can this work on Cloud Functions/Amazon Lambda/Azure Functions without installing the dependencies each time it has to run? Haven't done anything before with those serverless approaches.

It probably will not run on AWS Lambda as the version of Node required by Puppeteer is too recent. From puppeteer readme[1] > Puppeteer requires Node version 7.10 or greater From AWS website[2] > AWS Lambda supports the following runtime versions: > Node.js – v4.3.2 and 6.10.3 [1] https://github.com/GoogleChrome/puppeteer/blob/master/README... [2] http://docs.aws.amazon.com/lambda/latest/dg/current-supporte...

sight... I checked Azure Functions and Cloud Functions and they are running 6.x versions of node as well.

Re: Puppeteer: Headless Chrome Node API

#79
post #37

It's funny how open the market for browser automation is. Everyone needs to switch off phantomJS in the next few years and is looking for the easiest option. Sadly, there's probably no money on the line. But you will get your buggy software used by huge corporations for years to come!

I'm not super familiar with this space, can you explain further why everyone needs to switch from PhantomJS?

Core developer stepped down: https://news.ycombinator.com/item?id=14105489
Post reply on HN