screenshot-stream 
> Capture screenshot of a website and return it as a stream
Install
$ npm install --save screenshot-stream
Usage
const fs = require('fs');
const screenshot = require('screenshot-stream');
const stream = screenshot('http://google.com', '1024x768', {crop: true});
stream.pipe(fs.createWriteStream('google.com-1024x768.png'));
API
screenshot(url, size, [options])
url
Type: string
Add page to capture.
size
Type: string
Set viewport size.
options
Type: Object
Define options to be used.
crop
Type: Boolean
Default: false
Crop to the set height.
delay
Type: number (seconds)
Default: 0
Delay capturing the screenshot. Useful when the site does things after load that you want to capture.
timeout
Type: number (seconds)
Default: 60
Number of seconds after which PhantomJS aborts the request.
selector
Type: string
Capture a specific DOM element.
css
Type: string
Apply custom CSS to the webpage. Specify some CSS or the path to a CSS file.
script
Type: string
Apply custom JavaScript to the webpage. Specify some JavaScript or the path to a file.
hide
Type: Array
Hide an array of DOM elements.
headers
Type: Object
Default: {}
Set custom headers.
cookies
Type: Array or Object
A string with the same format as a browser cookie or an object of what phantomjs.addCookie accepts.
username
Type: string
Username for authenticating with HTTP auth.
password
Type: string
Password for authenticating with HTTP auth.
format
Type: string
Default: png
Set format to render the image as. Supported formats are png and jpg.
scale
Type: number
Default: 1
Scale webpage n times.
userAgent
Type: string
Set a custom user agent.
transparent
Type: Boolean
Default: false
Set background color to transparent instead of white if no background is set.
.on('error', callback)
Type: Function
PhantomJS errors.
.on('warning', callback)
Type: Function
Warnings with for example page errors.
CLI
See the pageres CLI.
License
MIT © Kevin Mårtensson
Source
| 1 | # screenshot-stream [](https://travis-ci.org/kevva/screenshot-stream) |
| 2 | |
| 3 | > Capture screenshot of a website and return it as a stream |
| 4 | |
| 5 | |
| 6 | ## Install |
| 7 | |
| 8 | ``` |
| 9 | $ npm install --save screenshot-stream |
| 10 | ``` |
| 11 | |
| 12 | |
| 13 | ## Usage |
| 14 | |
| 15 | ```js |
| 16 | const fs = require('fs'); |
| 17 | const screenshot = require('screenshot-stream'); |
| 18 | |
| 19 | const stream = screenshot('http://google.com', '1024x768', {crop: true}); |
| 20 | |
| 21 | stream.pipe(fs.createWriteStream('google.com-1024x768.png')); |
| 22 | ``` |
| 23 | |
| 24 | |
| 25 | ## API |
| 26 | |
| 27 | ### screenshot(url, size, [options]) |
| 28 | |
| 29 | #### url |
| 30 | |
| 31 | Type: `string` |
| 32 | |
| 33 | Add page to capture. |
| 34 | |
| 35 | #### size |
| 36 | |
| 37 | Type: `string` |
| 38 | |
| 39 | Set viewport size. |
| 40 | |
| 41 | #### options |
| 42 | |
| 43 | Type: `Object` |
| 44 | |
| 45 | Define options to be used. |
| 46 | |
| 47 | ##### crop |
| 48 | |
| 49 | Type: `Boolean`<br> |
| 50 | Default: `false` |
| 51 | |
| 52 | Crop to the set height. |
| 53 | |
| 54 | ##### delay |
| 55 | |
| 56 | Type: `number` *(seconds)*<br> |
| 57 | Default: `0` |
| 58 | |
| 59 | Delay capturing the screenshot. Useful when the site does things after load that you want to capture. |
| 60 | |
| 61 | ##### timeout |
| 62 | |
| 63 | Type: `number` *(seconds)*<br> |
| 64 | Default: `60` |
| 65 | |
| 66 | Number of seconds after which PhantomJS aborts the request. |
| 67 | |
| 68 | ##### selector |
| 69 | |
| 70 | Type: `string` |
| 71 | |
| 72 | Capture a specific DOM element. |
| 73 | |
| 74 | ##### css |
| 75 | |
| 76 | Type: `string` |
| 77 | |
| 78 | Apply custom CSS to the webpage. Specify some CSS or the path to a CSS file. |
| 79 | |
| 80 | ##### script |
| 81 | |
| 82 | Type: `string` |
| 83 | |
| 84 | Apply custom JavaScript to the webpage. Specify some JavaScript or the path to a file. |
| 85 | |
| 86 | ##### hide |
| 87 | |
| 88 | Type: `Array` |
| 89 | |
| 90 | Hide an array of DOM elements. |
| 91 | |
| 92 | ##### headers |
| 93 | |
| 94 | Type: `Object`<br> |
| 95 | Default: `{}` |
| 96 | |
| 97 | Set custom headers. |
| 98 | |
| 99 | ##### cookies |
| 100 | |
| 101 | Type: `Array` or `Object` |
| 102 | |
| 103 | A string with the same format as a [browser cookie](http://en.wikipedia.org/wiki/HTTP_cookie) or an object of what [`phantomjs.addCookie`](http://phantomjs.org/api/phantom/method/add-cookie.html) accepts. |
| 104 | |
| 105 | ##### username |
| 106 | |
| 107 | Type: `string` |
| 108 | |
| 109 | Username for authenticating with HTTP auth. |
| 110 | |
| 111 | ##### password |
| 112 | |
| 113 | Type: `string` |
| 114 | |
| 115 | Password for authenticating with HTTP auth. |
| 116 | |
| 117 | ##### format |
| 118 | |
| 119 | Type: `string`<br> |
| 120 | Default: `png` |
| 121 | |
| 122 | Set format to render the image as. Supported formats are `png` and `jpg`. |
| 123 | |
| 124 | ##### scale |
| 125 | |
| 126 | Type: `number`<br> |
| 127 | Default: `1` |
| 128 | |
| 129 | Scale webpage `n` times. |
| 130 | |
| 131 | ##### userAgent |
| 132 | |
| 133 | Type: `string` |
| 134 | |
| 135 | Set a custom user agent. |
| 136 | |
| 137 | ##### transparent |
| 138 | |
| 139 | Type: `Boolean`<br> |
| 140 | Default: `false` |
| 141 | |
| 142 | Set background color to `transparent` instead of `white` if no background is set. |
| 143 | |
| 144 | #### .on('error', callback) |
| 145 | |
| 146 | Type: `Function` |
| 147 | |
| 148 | PhantomJS errors. |
| 149 | |
| 150 | #### .on('warning', callback) |
| 151 | |
| 152 | Type: `Function` |
| 153 | |
| 154 | Warnings with for example page errors. |
| 155 | |
| 156 | |
| 157 | ## CLI |
| 158 | |
| 159 | See the [pageres](https://github.com/sindresorhus/pageres#usage) CLI. |
| 160 | |
| 161 | |
| 162 | ## License |
| 163 | |
| 164 | MIT © [Kevin Mårtensson](https://github.com/kevva) |