Convert Figma logo to code with AI

sindresorhus logopageres

Capture website screenshots

9,670
746
9,670
22

Top Related Projects

88,205

JavaScript API for Chrome and Firefox

46,847

Fast, easy and reliable testing for anything that runs in a browser.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

30,518

A browser automation framework and ecosystem.

Automated auditing, performance metrics, and best practices for the web.

29,463

Scriptable Headless Browser

Quick Overview

Pageres is a powerful Node.js library and command-line tool for capturing screenshots of websites. It allows users to generate screenshots of web pages at various resolutions and device sizes, making it useful for responsive design testing, visual regression testing, and creating website previews.

Pros

  • Supports multiple resolutions and device emulation
  • Can capture full-page screenshots, including content below the fold
  • Offers both a CLI tool and a programmable API
  • Highly customizable with options for delay, CSS injection, and more

Cons

  • Requires Node.js and additional dependencies to be installed
  • May encounter issues with some dynamic or JavaScript-heavy websites
  • Limited support for handling authentication or complex user interactions
  • Performance can be slow when capturing multiple screenshots or large pages

Code Examples

  1. Basic usage to capture a single screenshot:
import pageres from 'pageres';

(async () => {
    await new pageres({delay: 2})
        .src('https://github.com', ['1280x1024', '1920x1080'])
        .dest(__dirname)
        .run();

    console.log('Screenshots captured');
})();
  1. Capturing multiple websites with custom options:
import pageres from 'pageres';

(async () => {
    await new pageres({delay: 2, timeout: 60})
        .src('https://github.com', ['480x320', '1024x768', '1920x1080'])
        .src('https://sindresorhus.com', ['1280x1024', '1920x1080'])
        .dest(__dirname)
        .run();

    console.log('Multiple screenshots captured');
})();
  1. Using CSS injection to modify the page before capturing:
import pageres from 'pageres';

(async () => {
    await new pageres()
        .src('https://github.com', ['1280x1024'], {
            css: 'body { background: red; }'
        })
        .dest(__dirname)
        .run();

    console.log('Screenshot with modified CSS captured');
})();

Getting Started

To use Pageres in your project, follow these steps:

  1. Install Pageres using npm:

    npm install pageres
    
  2. Import and use Pageres in your JavaScript file:

    import pageres from 'pageres';
    
    (async () => {
        await new pageres()
            .src('https://example.com', ['1280x1024'])
            .dest(__dirname)
            .run();
    
        console.log('Screenshot captured');
    })();
    
  3. Run your script using Node.js:

    node your-script.js
    

This will capture a screenshot of the specified website at the given resolution and save it in the current directory.

Competitor Comparisons

88,205

JavaScript API for Chrome and Firefox

Pros of Puppeteer

  • More comprehensive browser automation capabilities beyond just capturing screenshots
  • Supports a wider range of browser interactions and manipulations
  • Actively maintained with frequent updates and a large community

Cons of Puppeteer

  • Steeper learning curve due to more complex API and features
  • Heavier resource usage, as it requires a full browser instance
  • May be overkill for simple screenshot tasks

Code Comparison

Pageres:

const Pageres = require('pageres');

(async () => {
    await new Pageres({delay: 2})
        .src('https://github.com', ['1280x1024', '1920x1080'])
        .dest(__dirname)
        .run();
})();

Puppeteer:

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://github.com');
    await page.screenshot({path: 'github.png'});
    await browser.close();
})();

Pageres is more focused on capturing screenshots with various dimensions, while Puppeteer offers a broader range of browser automation capabilities. Pageres provides a simpler API for screenshot tasks, whereas Puppeteer requires more setup but offers greater flexibility for complex web interactions.

46,847

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • More comprehensive end-to-end testing framework
  • Real-time reloading and debugging capabilities
  • Extensive documentation and active community support

Cons of Cypress

  • Steeper learning curve for beginners
  • Limited cross-browser testing (primarily focused on Chrome)
  • Slower test execution compared to lightweight screenshot tools

Code Comparison

Pageres (capturing a screenshot):

const Pageres = require('pageres');

(async () => {
    await new Pageres({delay: 2})
        .src('https://example.com', ['1280x1024', '1920x1080'])
        .dest(__dirname)
        .run();
})();

Cypress (writing a simple test):

describe('My First Test', () => {
  it('Visits the example page', () => {
    cy.visit('https://example.com')
    cy.contains('Welcome').should('be.visible')
  })
})

Summary

While Pageres is a lightweight tool focused on capturing screenshots, Cypress is a full-featured testing framework. Pageres excels in simplicity and quick screenshot generation, whereas Cypress offers robust end-to-end testing capabilities with real-time feedback. The choice between the two depends on the specific needs of the project, with Pageres being ideal for simple screenshot tasks and Cypress better suited for comprehensive web application testing.

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Pros of Playwright

  • Supports multiple browser engines (Chromium, Firefox, WebKit)
  • Offers more comprehensive web automation and testing capabilities
  • Provides a unified API for cross-browser automation

Cons of Playwright

  • Steeper learning curve due to more extensive features
  • Larger package size and potentially higher resource usage
  • May be overkill for simple screenshot tasks

Code Comparison

Pageres:

const Pageres = require('pageres');

(async () => {
    await new Pageres()
        .src('https://github.com', ['1280x1024', '1920x1080'])
        .dest(__dirname)
        .run();
})();

Playwright:

const { chromium } = require('playwright');

(async () => {
    const browser = await chromium.launch();
    const page = await browser.newPage();
    await page.goto('https://github.com');
    await page.screenshot({ path: 'screenshot.png' });
    await browser.close();
})();

Pageres is focused on capturing screenshots with various resolutions, while Playwright offers a more comprehensive set of web automation tools, including screenshot capabilities. Pageres is simpler to use for basic screenshot tasks, whereas Playwright provides more flexibility and control over browser interactions.

30,518

A browser automation framework and ecosystem.

Pros of Selenium

  • Supports multiple programming languages (Java, Python, C#, Ruby, etc.)
  • Offers comprehensive browser automation capabilities beyond screenshot capture
  • Widely adopted with extensive community support and documentation

Cons of Selenium

  • More complex setup and configuration required
  • Heavier resource usage due to full browser automation
  • Steeper learning curve for beginners

Code Comparison

Pageres (JavaScript):

const pageres = require('pageres');

(async () => {
    await pageres()
        .src('https://example.com', ['1280x1024', '1920x1080'])
        .dest(__dirname)
        .run();
})();

Selenium (Python):

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://example.com")
driver.save_screenshot("screenshot.png")
driver.quit()

Summary

Pageres is a lightweight, focused tool for capturing screenshots, while Selenium is a comprehensive browser automation framework. Pageres offers simplicity and ease of use for screenshot tasks, whereas Selenium provides more extensive capabilities for web testing and automation across multiple programming languages.

Automated auditing, performance metrics, and best practices for the web.

Pros of Lighthouse

  • Comprehensive web performance auditing tool with multiple categories (Performance, Accessibility, SEO, etc.)
  • Integrated with Chrome DevTools and available as a CLI, making it versatile for different use cases
  • Provides detailed reports with actionable insights and recommendations

Cons of Lighthouse

  • More complex to set up and use compared to Pageres
  • Primarily focused on performance auditing rather than capturing screenshots
  • May require more system resources due to its extensive analysis capabilities

Code Comparison

Pageres:

const Pageres = require('pageres');

(async () => {
    await new Pageres({delay: 2})
        .src('https://example.com', ['480x320', '1024x768'], {crop: true})
        .dest(__dirname)
        .run();
})();

Lighthouse:

const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');

(async () => {
    const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
    const options = {logLevel: 'info', output: 'json', onlyCategories: ['performance'], port: chrome.port};
    const runnerResult = await lighthouse('https://example.com', options);
    console.log('Report is done for', runnerResult.lhr.finalUrl);
    await chrome.kill();
})();
29,463

Scriptable Headless Browser

Pros of PhantomJS

  • More versatile: Can be used for various web automation tasks beyond capturing screenshots
  • Supports complex JavaScript execution and interaction with web pages
  • Has a larger ecosystem and community support

Cons of PhantomJS

  • No longer actively maintained, with the last release in 2018
  • Heavier and slower compared to Pageres
  • More complex setup and usage for simple screenshot tasks

Code Comparison

PhantomJS:

var page = require('webpage').create();
page.open('https://example.com', function() {
  page.render('example.png');
  phantom.exit();
});

Pageres:

const Pageres = require('pageres');

(async () => {
  await new Pageres().src('https://example.com', ['1280x1024']).dest(__dirname).run();
})();

Key Differences

  • PhantomJS is a full-fledged headless browser, while Pageres is focused specifically on capturing screenshots
  • Pageres offers a simpler API for screenshot capture, making it easier to use for this specific task
  • PhantomJS provides more control over page rendering and interaction, but requires more setup and code
  • Pageres is actively maintained and updated, whereas PhantomJS development has ceased

Use Cases

  • Choose PhantomJS for complex web automation tasks or when you need extensive control over page rendering
  • Opt for Pageres when you primarily need to capture screenshots quickly and easily, especially in Node.js projects

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

pageres

Coverage Status XO code style

Capture screenshots of websites in various resolutions. A good way to make sure your websites are responsive. It's speedy and generates 100 screenshots from 10 different websites in just over a minute. It can also be used to render SVG images.

See pageres-cli for the command-line tool.

Install

npm install pageres

Note to Linux users: If you get a "No usable sandbox!" error, you need to enable system sandboxing.

Usage

import Pageres from 'pageres';

await new Pageres({delay: 2})
	.source('https://github.com/sindresorhus/pageres', ['480x320', '1024x768'], {crop: true})
	.source('https://sindresorhus.com', ['1280x1024', '1920x1080'])
	.source('data:text/html,<h1>Awesome!</h1>', ['1024x768'])
	.destination('screenshots')
	.run();

console.log('Finished generating screenshots!');

API

Pageres(options?)

options

Type: object

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 the request is aborted.

crop

Type: boolean
Default: false

Crop to the set height.

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.

cookies

Type: Array<string | object>

A string with the same format as a browser cookie or an object.

Tip: Go to the website you want a cookie for and copy-paste it from DevTools.

filename

Type: string
Default: '<%= url %>-<%= size %><%= crop %>'

Define a customized filename using Lo-Dash templates.
For example: <%= date %> - <%= url %>-<%= size %><%= crop %>.

Available variables:

  • url: The URL in slugified form, eg. http://yeoman.io/blog/ becomes yeoman.io!blog
  • size: Specified size, eg. 1024x1000
  • width: Width of the specified size, eg. 1024
  • height: Height of the specified size, eg. 1000
  • crop: Outputs -cropped when the crop option is true
  • date: The current date (YYYY-MM-DD), eg. 2015-05-18
  • time: The current time (HH-mm-ss), eg. 21-15-11
incrementalName

Type: boolean
Default: false

When a file exists, append an incremental number.

selector

Type: string

Capture a specific DOM element matching a CSS selector.

hide

Type: string[]

Hide an array of DOM elements matching CSS selectors.

username

Type: string

Username for authenticating with HTTP auth.

password

Type: string

Password for authenticating with HTTP auth.

scale

Type: number
Default: 1

Scale webpage n times.

format

Type: string
Default: png
Values: 'png' | 'jpg'

Image format.

userAgent

Type: string

Custom user agent.

headers

Type: object

Custom HTTP request headers.

transparent

Type: boolean
Default: false

Set background color to transparent instead of white if no background is set.

darkMode

Type: boolean
Default: false

Emulate preference of dark color scheme.

launchOptions

Type: object
Default: {}

Options passed to puppeteer.launch().

beforeScreenshot

Type: Function

The specified function is called right before the screenshot is captured, as well as before any bounding rectangle is calculated as part of options.element. It receives the Puppeteer Page instance as the first argument and the browser instance as the second argument. This gives you a lot of power to do custom stuff. The function can be async.

Note: Make sure to not call page.close() or browser.close().

import Pageres from 'pageres';

await new Pageres({
	delay: 2,
	beforeScreenshot: async (page, browser) => {
		await checkSomething();
		await page.click('#activate-button');
		await page.waitForSelector('.finished');
	}
})
	.source('https://github.com/sindresorhus/pageres', ['480x320', '1024x768', 'iphone 5s'], {crop: true})
	.destination('screenshots')
	.run();

console.log('Finished generating screenshots!');

pageres.source(url, sizes, options?)

Add a page to screenshot.

url

Required
Type: string

URL or local path to the website you want to screenshot. You can also use a data URI.

sizes

Required
Type: string[]

Use a <width>x<height> notation or a keyword.

A keyword is a version of a device from this list.

You can also pass in the w3counter keyword to use the ten most popular resolutions from w3counter.

options

Type: object

Options set here will take precedence over the ones set in the constructor.

pageres.destination(directory)

Set the destination directory.

directory

Type: string

pageres.run()

Run pageres.

Returns Promise<Uint8Array[]>.

Task runners

Check out grunt-pageres if you're using Grunt.

For Gulp and Broccoli, just use the API directly. No need for a wrapper plugin.

Built with Pageres

  • Break Shot - Desktop app for capturing screenshots of responsive websites.

Related

NPM DownloadsLast 30 Days