Newton's Programmatic Measurements

    red-snapper

    1.2.0 • Public • Published

    Red Snapper

    NPM Version NPM Downloads

    Red Snapper is a simple module that takes a screenshot of a webpage using headless Chrome and the Chrome Debugging Protocol.

    Important: This has only been tested on macOS Sierra, El Capitan, and Ubuntu 16.04 LTS

    Usage

    In the following example, Red Snapper will take a 300px by 600px screenshot of github.com. If content is outside of that area it is cropped.

    const fs = require('fs');
    const snap = require('red-snapper');
    
    snap({
    	url: 'https://github.com/',
    	width: 300,
    	height: 600,
    	delay: 500,
    	format: 'png'
    }).then((data) => {
    	fs.writeFileSync('screenshot.png', Buffer.from(data, 'base64'));
    }).catch((error) => {
    	console.error(error);
    });

    To take multiple screenshots specify an array of delays. The delays happen sequentially. So for example if you want screenshots at 1 second, 5 seconds, and 8 seconds from a page load use an array with values of [1000,4000,3000]; The return object then becomes an array of buffers.

    snap({
    	url: 'https://github.com/',
    	width: 300,
    	height: 600,
    	delay: [1000,4000,3000],
    	format: 'png'
    }).then((data) => {
    	for(let i = 0; i < data.length; i++) {
    		fs.writeFileSync('screenshot'+i+'.png', Buffer.from(data[i], 'base64'));
    	}
    }).catch((error) => {
    	console.error(error);
    });

    Parameters

    • url (string) - Path to website to screenshot. Use file:/// to load a local file.
    • width (integer) - Width of the browser. Defaults to 1024px. (optional)
    • height (integer) - Height of the browser. Defaults to 768px. (optional)
    • delay (integer|array) - Number of milliseconds to wait after page load before taking a screenshot. If an array is specified several screenshots will be taken with delays taking place sequentially. (optional)
    • format (string) - File format of the screenshot. Acceptable values are "png" or "jpeg". Defaults to PNGs. (optional)
    • quality (integer) - Value between [0..100] and only used when format is jpeg. Defaults to 80. (optional)
    • fullPage (boolean) - When set to true the height of the image will grow to expand the content of the page. Defaults to false. (optional)

    Install

    npm i red-snapper

    DownloadsWeekly Downloads

    11

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    7.46 kB

    Total Files

    8

    Last publish

    Collaborators

    • jmisavage