Giter Club home page Giter Club logo

webshot-factory's Introduction

webshot-factory

Build Status npm version

Webshot Factory

screenshots at scale based on headless chrome.

Basic Concept

  • Webshot-factory creates a number of headless-chrome worker instances which take screenshots in round robin. Thus, can be horizontally scaled to provide good throughput.
  • Includes a debug status page to monitor the worker instances.
  • Can be used for batch report generation.
  • Or to take a number of screenshots in general.
  • Written in Typescript (types bundled).

Installation

npm i webshot-factory

Usage

import * as shotFactory from 'webshot-factory';

await shotFactory.init({
    // Number of worker threads (chrome instances) to run.
    // A shot is assigned to a worker in round robin.
    concurrency: 10,

    // The callback method to be exposed on the window, 
    // which would be called by the application
    // Shot will be taken when callback is called.
    // This was 'callPhantom' in PhantomJS.
    callbackName: '',

    // A cache warmer url, 
    // so that workers can cache the webpage scripts.
    warmerUrl: 'http://google.com',
    width: 1000, // shot width
    height: 600, // shot height
    timeout: 60000, // timeout (millis) to wait for shot.
    webshotDebugPort: 3030 // Port where the status page is served.
});

// Once initialized, just call getShot and
// a shot will be scheduled on a worker
// chrome instance.
shotFactory.getShot('http://yahoo.com').then(buffer => {
    // Do whatever with the buffer, can be used to email to recipients.
    console.log(buffer);
    // Or can be saved to a file.
    // Using the `fs` module.
    fs.createWriteStream('shot.png')
        .write(buffer)
        .end();
});

Status Page

Webshot-factory includes a status page to check the status of the running chrome instance workers.

Visit: http://<host>:<webshotDebugPort>/status

Note: The default port is 3030.

To check the status and debug any problems. The page looks like this:

Webshot Factory status

webshot-factory's People

Contributors

ashubham avatar

Watchers

athiwatp avatar

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.