Git Product home page Git Product logo

screenshot-nodejs's People

Contributors

vojtechvitek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

screenshot-nodejs's Issues

Client.Do() to return io.Reader

	resp, body, err := c.Do(req)

	if err != nil {
		return nil, err
	}

	if resp.StatusCode != 200 {
		return nil, errors.New("Couldn't take png screenshot")
	}
	reader := bytes.NewReader(body)

You can pass resp.Body (which is io.Reader itself) down to the callers right away.

resp, err := c.Do(req)

// return nil, error

// return resp.Body, nil

Docker base image

I noticed we're using node:8-slim as a base image. That's fine, and will work great.

But I wonder, if we could potentially switch to

  • Alpine-based image (ie. 9.2-alpine)
  • Node 9.2 (or do we have to stick with Node 8 because of Puppeteer?)

Restructure the Golang client project repo

screen shot 2017-12-12 at 4 53 26 pm

In golang, we usually put the client pkg into the top-level directory (unless the project is too big and has multiple clients, of course). Imho you can get rid of the lib/ subdirectory :)

If you wanted to implement CLI (a terminal program that downloads screenshots from a remote server), it'd live in /cmd/screenshot/main.go.

When the client pkg is in the top-level directory, the imports are as easy as

import (
     "github.com/pressly/screenshot"
)

func main() {
   screenshot, _ := screenshot.New(...)

   // ... 
}

Docker image doesn't work

Error -
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to launch chrome!
/app/node_modules/puppeteer/.local-chromium/linux-515411/chrome-linux/chrome: error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory

Things are still working outside of docker.

Even the example puppeteer code on puppeteer's github doesn't seem to work, so it seems like a puppeteer / chromium issue. Can't figure out if it's just on my computer or if it's legit right now.

REST API query arguments

GET localhost:{port}/png?url=https://www.google.com&window=500x500&crop=75x80&x=350&y=190

  1. Do we assume that the URL is url_encoded?
  2. Or is localhost:{port}/png?window=500x500&crop=75x80&x=350&y=190&url=https://www.google.com?some=third&party=arguments gonna work?
  3. Can we document this in the README and let the url argument to be the last one in all the examples?

Feedback on cmd/screenshot and the Golang client API

https://github.com/pressly/screenshot/blob/master/cmd/screenshot/main.go#L15-L39

  • Always check the error, never ignore it (Golang is very explicit about errors)
  • Replace var window [2]int https://github.com/pressly/screenshot/blob/master/cmd/screenshot/main.go#L16-L18 with WindowWidth int and WindowHeight int on the ScreenshotOptions{} struct
  • Can we rename ScreenshotOptions to Page or Options?
  • PdfOptions - I'm fine with a single argument to PDF() as long as the PdfOptions embed the above ScreenshotOptions{}
  • well need to use io.ReadCloser, so the consumer can close the Body

[long term] Use Chrome headless API directly, get rid of Puppetteer

This would allow us to get rid of the Node.js server wrapper. And we could write the whole service in Go only, effectively reimplement the Puppetteer.

Pros:

  • HTTP throttling would be super easy
  • Managing Headless processes would be much easier too, ie we could spin up a pool of Headless "workers" in the server, and throttle incoming requests to each available worker.
  • Zero overhead
  • HTTP/2 for free, potentially generate a GRPC client for many languages

Chrome DevTools Protocol

I'll look into feasibility of this option.

Golang client for accessing the REST API

Create a Golang HTTP client for accessing the screenshot endpoints.

screenshot, err := screenshot.New("https://screenshot-api.example.com:8787")

/*io.Reader, error*/
pngBytesReader, err := screenshot.PNG(ctx, websiteUrl, screenshot.Page{/*Headers, Window, Crop, X, Y, WaitUntil */})

jpegBytesReader, err := screenshot.JPEG(ctx, websiteUrl, screenshot.Page{/*Headers, Window, Crop, X, Y, WaitUntil */}, 80 /*JPEG quality .. 0-100*/)

pdfBytesReader, err := screenshot.PDF(ctx, websiteUrl, screenshot.Page{/*Headers, Window, Crop, X, Y*/}, screenshot.PDFOptions{/*Format etc. */}) // see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions

@MarcelRusu do you prefer a separate repository for client(s) and server?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.