cross-capture

Capture screenshots programmatically. Cross-platform, with support for MacOS (Darwin), Windows, and Linux.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
$ npm install --save cross-capture
Usage
import {
capture,
captureLinux,
captureDarwin,
captureWindows
} from 'cross-capture';
const result = await capture({
cursor: true
format: 'png',
window: { interactive: true }
})
Requirements
- macOS: Built-in support
- Linux: One of:
- grim + slurp (Wayland)
- maim (X11)
- ImageMagick (import command)
- Windows: PowerShell 5.0+
API
capture
Take a screenshot with the specified options. Returns a Promise that resolves to a base64-encoded image or an error object.
import { capture } from 'cross-capture';
const result = await capture();
console.log(result.data);
const region = await capture({
region: { x: 0, y: 0, width: 800, height: 600 }
});
captureDarwin
macOS-specific screenshot function using the screencapture command. Supports window capture by ID or title and includes interactive window selection.
import { captureDarwin } from 'cross-capture';
const screenshot = await captureDarwin({
window: { interactive: true },
cursor: true
});
const terminal = await captureDarwin({
window: { title: 'Terminal' }
});
const byId = await captureDarwin({
window: { id: '12345' }
});
captureLinux
Linux-specific screenshot function that automatically detects and uses the appropriate tools:
- Wayland: Uses
grim for capture and slurp for selection
- X11: Uses
maim for capture and xdotool for window management
import { captureLinux } from 'cross-capture';
const browser = await captureLinux({
window: { title: 'Firefox' }
});
const region = await captureLinux({
cursor: true,
region: {
x: 100,
y: 100,
width: 500,
height: 300
}
});
const selected = await captureLinux();
captureWindows
Windows-specific screenshot function using PowerShell and Windows Forms. Interactive selection is implemented via a semi-transparent form overlay. Window capture requires exact window title match.
import { captureWindows } from 'cross-capture';
const region = await captureWindows();
const notepad = await captureWindows({
window: { title: 'Untitled - Notepad' }
});
const jpg = await captureWindows({
format: 'jpg',
region: {
x: 0,
y: 0,
width: 1920,
height: 1080
}
});
Options
The following options can be passed to the capture functions:
interactive
Type: boolean
Default: false
Enable interactive selection mode (where supported).
const screenshot = await capture({ interactive: true });
cursor
Type: boolean
Default: false
Include the cursor in the screenshot.
const withCursor = await capture({ cursor: true });
format
Type: string
Default: 'png'
Output format for the screenshot. Supported values: 'png', 'jpg'.
const jpgScreenshot = await capture({ format: 'jpg' });
quality
Type: number
Default: 100
JPEG quality (0-100) when using format: 'jpg'.
const compressed = await capture({
format: 'jpg',
quality: 80
});
region
Type: object
Capture a specific region of the screen.
Properties:
x (number): X coordinate
y (number): Y coordinate
width (number): Width of region
height (number): Height of region
const region = await capture({
region: {
x: 100,
y: 100,
width: 500,
height: 300
}
});
window
Type: object
Capture a specific window.
Properties:
title (string): Window title to match
id (string): Window ID (macOS only)
interactive (boolean): Interactive window selection
const window = await capture({
window: { title: 'Terminal' }
});
const selected = await capture({
window: { interactive: true }
});
tempFile
Type: string
Custom temporary file path for the screenshot.
const custom = await capture({
tempFile: '/tmp/my-screenshot.png'
});
Release History
v1.0.0
- Initial release with cross-platform support
- Basic screenshot capabilities
- Window and region capture support
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Author
Jon Schlinkert
License
Copyright © 2025, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on April 13, 2025.