GithubHelp home page GithubHelp logo

micahstubbs / screenshot-service Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 130 KB

services to create a screenshot of a web page. optimized for screenshotting interactive data graphics.

JavaScript 87.64% Shell 12.36%

screenshot-service's Introduction

screenshot-service

screenshot-service's People

Contributors

micahstubbs avatar

Watchers

James Cloos avatar  avatar

screenshot-service's Issues

dedicated screenshot server

spin up a server that runs a headless browser to take screenshots

(and perhaps generate pdfs as well ๐Ÿค” )

features

future work

  • upgrade auth to use jwt token #10
  • cache in redis (ephemeral, faster than reading from gcp bucket probably) speed up screenshot serving from cache #11
  • generate a pdf #13
  • size presets and dimension parameters #14

speed up screenshot serving from cache

speed up screenshot serving from cache

perhaps use an in-memory store like redis to speed up access to cached screenshots?

current process is to make two API calls to GCP

  1. to check if the screenshot is in the bucket
  2. to fetch the screenshot image from the bucket if it is there

viewport and resize parameters for controlling screenshot dimensions

feature idea:

support screenshot size presets like

preview 960px by 500px
thumbnail 230px by 120px

as well as caller-specified screenshot dimensions.

could fix the crop to originate at the top-left 0,0 point, or could also support an xy translate param as well to set the origin point for the crop ๐Ÿค”


per @curran #9 (comment)

Some snippets that may be useful (from the thumbnail generation of datavis.tech):

const setThumbnail = require('../../db/actions/setThumbnail')
const generateThumbnailBuffer = require('./generateThumbnailBuffer')

module.exports = async (browser, sandbox, shareDbDoc) => {
  const html = await sandbox({id: shareDbDoc.id})
  const page = await browser.newPage()
  const thumbnailBuffer = await generateThumbnailBuffer(page, html)
  const thumbnail = thumbnailBuffer.toString('base64')
  setThumbnail(shareDbDoc, thumbnail)
}
const sharp = require('sharp')

module.exports = async generateThumbnailBuffer(page, html) => {
  await page.setViewport({width: 960, height: 500})
  await page.setContent(html)
  await page.waitFor(5000)

  const buffer = await page.screenshot()
  await page.close()

  return sharp(buffer)
    .resize(230, 120)
    .toBuffer()
}
const browser = await puppeteer.launch({args: ['--no-sandbox']})

improve scale performance

improve scale performance

better handle concurrency for

  • many puppeteer + headless chrome instances
  • many network requests to GCP Storage to upload images to the specified bucket

handle puppeteer page crash

Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]: (node:29770) UnhandledPromiseRejectionWarning: Error: Page crashed!
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Page._onTargetCrashed (/home/ubuntu/screenshot-service/dedicated-server/node_modules/puppeteer/lib/Page.js:102:24)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Session.Page.client.on.event (/home/ubuntu/screenshot-service/dedicated-server/node_modules/puppeteer/lib/Page.js:97:56)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at emitOne (events.js:116:13)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Session.emit (events.js:211:7)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Session._onMessage (/home/ubuntu/screenshot-service/dedicated-server/node_modules/puppeteer/lib/Connection.js:210:12)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Connection._onMessage (/home/ubuntu/screenshot-service/dedicated-server/node_modules/puppeteer/lib/Connection.js:105:19)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at emitOne (events.js:116:13)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at WebSocket.emit (events.js:211:7)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Receiver._receiver.onmessage (/home/ubuntu/screenshot-service/dedicated-server/node_modules/ws/lib/WebSocket.js:141:47)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]:     at Receiver.dataMessage (/home/ubuntu/screenshot-service/dedicated-server/node_modules/ws/lib/Receiver.js:389:14)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]: (node:29770) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Oct 31 19:22:17 screenshot-bot screenshot-bot[29770]: (node:29770) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
image

screen shot 2018-10-31 at 12 22 25 pm

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.