Capture screenshots of websites, with puppeteer-core
npm install capture-website-coreForked from capture-website.
capture-website uses puppeteer and always downloads Chromium when install, which takes time and disk space.
capture-website-core uses puppeteer-core and avoids downloading Chromium as long as compatible browsers found in your system:
1. Chrome
2. MS Edge
3. Cached Chromium
4. Download Chromium
---
> Capture screenshots of websites
It uses Puppeteer (Chrome) under the hood.
See capture-website-cli for the command-line tool.
``sh`
npm install capture-website
Note to Linux users: If you get a sandbox-related error, you need to enable system sandboxing.
`js
import captureWebsite from 'capture-website';
await captureWebsite.file('https://sindresorhus.com', 'screenshot.png');
`
Capture a screenshot of the given input and save it to the given outputFilePath.
Intermediate directories are created for you if they do not exist.
Returns a Promise that resolves when the screenshot is written.
Capture a screenshot of the given input.
Returns a Promise with the screenshot as binary.
Capture a screenshot of the given input.
Returns a Promise with the screenshot as Base64.
#### input
Type: string
The URL, file URL, data URL, local file path to the website, or HTML.
`js
import captureWebsite from 'capture-website';
await captureWebsite.file('index.html', 'local-file.png');
`
#### options
Type: object
##### inputType
Type: string\'url'
Default: \'url' | 'html'
Values:
Set it to html to treat input as HTML content.
`js
import captureWebsite from 'capture-website';
await captureWebsite.file('
##### width
Type:
number\
Default: 1280Page width.
##### height
Type:
number\
Default: 800Page height.
##### type
Type:
string\
Values: 'png' | 'jpeg' | 'webp'\
Default: 'png'Image type.
##### quality
Type:
number\
Values: 0...1\
Default: 1Image quality. Only for
{type: 'jpeg'} and {type: 'webp'}.##### scaleFactor
Type:
number\
Default: 2Scale the webpage
n times.The default is what you would get if you captured a normal screenshot on a computer with a retina (High DPI) screen.
##### emulateDevice
Type:
string\
Values: Devices (Use the name property)Make it look like the screenshot was taken on the specified device.
This overrides the
width, height, scaleFactor, and userAgent options.`js
import captureWebsite from 'capture-website';await captureWebsite.file('https://sindresorhus.com', 'screenshot.png', {
emulateDevice: 'iPhone X'
});
`##### fullPage
Type:
boolean\
Default: falseCapture the full scrollable page, not just the viewport.
##### defaultBackground
Type:
boolean\
Default: trueInclude the default white background.
Disabling this lets you capture screenshots with transparency.
##### timeout
Type:
number (seconds)\
Default: 60The number of seconds before giving up trying to load the page.
Specify
0 to disable the timeout.##### delay
Type:
number (seconds)\
Default: 0The number of seconds to wait after the page finished loading before capturing the screenshot.
This can be useful if you know the page has animations that you like it to finish before capturing the screenshot.
##### waitForElement
Type:
stringWait for a DOM element matching the given CSS selector to appear in the page and to be visible before capturing the screenshot. It times out after
options.timeout seconds.##### element
Type:
stringCapture the DOM element matching the given CSS selector. It will wait for the element to appear in the page and to be visible. It times out after
options.timeout seconds. Any actions performed as part of options.beforeScreenshot occur before this.##### hideElements
Type:
string[]Hide DOM elements matching the given CSS selectors.
Can be useful for cleaning up the page.
visibility: hidden on the matched elements.`js
import captureWebsite from 'capture-website';await captureWebsite.file('https://sindresorhus.com', 'screenshot.png', {
hideElements: [
'#sidebar',
'img.ad'
]
});
`##### removeElements
Type:
string[]Remove DOM elements matching the given CSS selectors.
display: none on the matched elements, so it could potentially break the website layout.##### clickElement
Type:
stringClick the DOM element matching the given CSS selector.
##### scrollToElement
Type:
string | objectScroll to the DOM element matching the given CSS selector.
###### element
Type:
stringA CSS selector.
###### offsetFrom
Type:
string\
Values: 'top' | 'right' | 'bottom' | 'left'Offset origin.
###### offset
Type:
numberOffset in pixels.
##### disableAnimations
Type:
boolean\
Default: falseDisable CSS animations and transitions.
##### blockAds
Type:
boolean\
Default: true##### isJavaScriptEnabled
Type:
boolean\
Default: trueWhether JavaScript on the website should be executed.
This does not affect the
scripts and modules options.##### modules
Type:
string[]Inject JavaScript modules into the page.
Accepts an array of inline code, absolute URLs, and local file paths (must have a
.js extension).`js
import captureWebsite from 'capture-website';await captureWebsite.file('https://sindresorhus.com', 'screenshot.png', {
modules: [
'https://sindresorhus.com/remote-file.js',
'local-file.js',
]
});
`##### scripts
Type:
string[]Same as the
modules option, but instead injects the code as