initial-rendering
v0.0.3
Published
Use Chrome headless screenshots for comparing the initial rendering
Downloads
6
Maintainers
Readme
initial-rendering
Use Chrome headless screenshots for comparing the following steps with the full loaded page:
- only the document is loaded
- the document without any style and script tags is loaded
The library uses puppeteer as wrapper for Chrome headless.
Install
npm install initial-rendering
Usage
The library returns a json object with the results. All images are passed as optimized base64 encoded pngs. imagemin-pngquant is used for optimizing the images. pixelmatch is used for comparing the images.
Here I wroten an article at medium.com about the library.
const initialRendering = require('initial-rendering');
initialRendering({
url: 'https://foo.bar',
puppeteerOptions: {}, // optional
device: 'Nexus 5X', // optional. default: Nexus 5X
returnScreenshots: true, // optional. default: true
waitFor: { // optional
1: 0, // optional. default: 0
2: 500, // optional. default: 0
3: 500 // optional. default: 0
}
}).then(data => {
// handle result
}).catch(err => {
// handle err
});
API
initialRendering(options)
Use Chrome headless screenshots for comparing the initial rendering and return all the informations as object
Parameters
options
object options (optional, default{}
)options.url
string url (optional, defaultfalse
)options.device
string device name which is supported by chromium (optional, defaultNexus5X
)options.puppeteerOptions
object additional options for puppeteer (optional, default{}
)options.auth
object http authentication (optional, default{}
)options.auth.username
string usernameoptions.auth.password
string password
options.returnScreenshots
boolean return screenshot as base64 image (optional, defaulttrue
)options.waitFor
object waitFor n ms after each step (optional, default{}
)options.waitFor.1
number delay after step 1options.waitFor.2
number delay after step 2options.waitFor.3
number delay after step 3
Returns promise<initialRenderingResult>
initialRenderingResult
Type: object
Properties
execution
number unix timestamp of execution in msurl
string urldevice
string device namewidth
number screenshot width in pxheight
number screenshot height in pxfull
string base64 png screenshot of fully loaded websitesteps
array<initialRenderingStep> loading stepsversion
string version tag
initialRenderingStep
Type: object
Properties
name
string step namenumDiffPixels
number number of diff pixelsratio
number ratio of diff pixelsscreenshot
string base64 png screenshot of loaded stepdiff
string base64 png screenshot of diff image
Examples
Screenshots
JSON result
{
"execution": 1527064733409,
"url": "https://www.buecher.de",
"device": "Nexus 5X",
"width": 1082,
"height": 1922,
"full": "data:image/png;base64,abc",
"steps": [{
"name": "initial",
"numDiffPixels": 627364,
"ratio": 30.17,
"screenshot": "data:image/png;base64,abc",
"diff": "data:image/png;base64,abc"
}, {
"name": "no-assets",
"numDiffPixels": 295434,
"ratio": 14.21,
"screenshot": "data:image/png;base64,abc",
"diff": "data:image/png;base64,abc"
}],
"version": "0.0.1"
}