capture-all
Flexible utility to get screenshots from Web pages
Install
$ npm i capture-all
$ yarn add capture-all
Example
const { captureAll } = require('capture-all')
const fs = require('fs')
captureAll([
{
url: 'https://www.google.com/',
target: 'body',
hidden: ['#gb', '#fbar'],
viewport: {
width: 1024,
height: 800
}
}
]).then(results => {
results.forEach((result, i) => {
fs.writeFileSync(`result-${i}.png`, result.image)
})
})
API
captureAll(targets: CaptureTarget[], options?: CaptureOptions): Promise<CaptureResult[]>
Capture screenshots of Web pages which specified by targets
and return an array of CaptureResult
object including captured image buffer.
CaptureTarget
may have the following properties:
url
: Web page URL which will be captured (required)target
: a selector for capturing elementhidden
: an array of selector to hide matched elements from captured imageviewport
: viewport size of browser
CaptureOptions
may have the following properties:
concurrency
: a number of process which will be created for capturepuppeteer
: an object passed to puppeteer.launch
CaptureResult
has the following properties:
image
: captured image bufferurl
: captured Web page URLtarget
: a selector of captured elementhidden
: an array of selector which is hidden from captured imageviewport
: viewport size of browser
createCaptureStream(targets: CaptureTarget[], options?: CaptureOptions): ReadableStream<CaptureResult>
Similar to captureAll
but returns readable stream of CaptureResult
instead.
License
MIT