Skip to content

Commit

Permalink
[0.5.0] Docs updated + Ability to not specify callbackName
Browse files Browse the repository at this point in the history
  • Loading branch information
ashubham committed Jan 15, 2018
1 parent 1b56961 commit f2a5e7f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist: trusty
addons:
chrome: stable
language: node_js
node_js:
- "8.8"
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# webshot-factory
[![Build Status](https://travis-ci.org/ashubham/webshot-factory.svg?branch=master)](https://travis-ci.org/ashubham/webshot-factory)
[![npm version](https://badge.fury.io/js/webshot-factory.svg)](https://badge.fury.io/js/webshot-factory)

<img src="https://github.com/ashubham/webshot-factory/raw/master/assets/webshot-factory.png" align="right" alt="Webshot Factory" />

screenshots at scale based on headless chrome

## Installation

```
npm i webshot-factory
```

## Usage

```javascript
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.
callbackName: 'callPhantom',

// 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 => {
console.log(buffer);
});
```

## Status Page

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

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

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


Binary file added assets/webshot-factory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let ip;
internalIp.v4().then(_ip => ip = _ip);

export interface Config extends shotPool.PoolConfig {

webshotDebugPort: string;
}

let defaultConfig: Config = {
Expand All @@ -20,14 +20,19 @@ let defaultConfig: Config = {
warmerUrl: '',
width: 800,
height: 600,
timeout: 60000
timeout: 60000,
webshotDebugPort: process.env.webshotDebugPort
};

let passedConfig : Config;

export async function init(options: Config) {
options = Object.assign({}, defaultConfig, options);
return shotPool.create(
passedConfig = options;
await shotPool.create(
options
);
return shotPool;
}

export function getShot(url: string): PromiseLike<Buffer> {
Expand Down Expand Up @@ -85,4 +90,4 @@ app.get('/status', (req, res) => {
`)
});

app.listen(parseInt(process.env.webshotDebugPort), ip);
app.listen(parseInt(passedConfig.webshotDebugPort), ip);
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"name": "webshot-factory",
"version": "0.3.2",
"version": "0.3.3",
"description": "screenshots at scale based on headless chrome",
"main": "dist/index.js",
"types": "dist/declarations/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "npm run build",
"build": "tsc -p .",
"prepublish": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ashubham/webshot-factory.git"
},
"keywords": [
"webshot",
"headless",
"chrome",
"screenshot"
],
"author": "[email protected]",
"license": "ISC",
"bugs": {
Expand All @@ -27,7 +33,7 @@
"internal-ip": "^3.0.0",
"lodash": "^4.17.4",
"log4js": "^1.1.1",
"puppeteer": "^0.11.0"
"puppeteer": "^1.0.0"
},
"devDependencies": {
"@types/bluebird": "^3.5.11",
Expand Down

0 comments on commit f2a5e7f

Please sign in to comment.