# node-screenshots

> Zero-dependent. A native nodejs screenshots library for Mac、Windows、Linux.

Latest version **0.2.8** (published 2026-02-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install node-screenshots
pnpm add node-screenshots
yarn add node-screenshots
bun add node-screenshots
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.8 |
| Published | 2026-02-07 |
| First published | 2022-01-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 12.22.0 < 13 \|\| >= 14.17.0 < 15 \|\| >= 15.12.0 < 16 \|\| >= 16.0.0 |
| Dependencies | 0 |
| Unpacked size | 34.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 383 |
| Maintainers | nashaofu |
| Keywords | napi-rs, NAPI, N-API, xcap, screenshot, screen-capture |

## Links

- npm: https://www.npmjs.com/package/node-screenshots
- Repository: https://github.com/nashaofu/node-screenshots
- Homepage: https://github.com/nashaofu/node-screenshots#readme
- Issues: https://github.com/nashaofu/node-screenshots/issues
- npm.io page: https://npm.io/package/node-screenshots

## Recent versions

- 0.2.8 (latest) — 2026-02-07
- 0.2.7 (next) — 2026-02-07
- 0.2.6 — 2026-01-30
- 0.2.5 — 2025-12-31
- 0.2.4 — 2025-04-12
- 0.2.3 — 2025-02-04
- 0.2.2 — 2024-08-25
- 0.2.1 — 2024-08-11
- 0.2.0 — 2024-05-01
- 0.1.9 — 2023-11-02
- 0.1.8 — 2023-10-04
- 0.1.7 — 2023-09-29
- 0.1.6 — 2023-07-27
- 0.1.5 — 2023-07-27
- 0.1.4 — 2023-04-19
- … 18 more at https://npm.io/package/node-screenshots/versions

## README

# 📸 node-screenshots

`node-screenshots` is a native node.js screenshot library based on [XCap](https://github.com/nashaofu/xcap), It supports Mac, Windows, and Linux systems without any dependencies. `node-screenshots` supports screenshot and video recording (to be implemented).

English | [简体中文](README-zh_CN.md)

## Support Matrix

### Operating System

| Operating System  | node16 | node18 | node20 |
| ----------------- | ------ | ------ | ------ |
| Windows x64       | ✓      | ✓      | ✓      |
| Windows x32       | ✓      | ✓      | ✓      |
| Windows arm64     | ✓      | ✓      | ✓      |
| macOS x64         | ✓      | ✓      | ✓      |
| macOS arm64       | ✓      | ✓      | ✓      |
| Linux x64 gnu     | ✓      | ✓      | ✓      |
| Linux x64 musl    | ✓      | ✓      | ✓      |
| Linux arm64 gnu   | ✓      | ✓      | ✓      |
| Linux loongarch64 | ✓      | ✓      | ✓      |

## Example

### Monitor

```ts
const fs = require('fs')
const { Monitor } = require('node-screenshots')

let monitor = Monitor.fromPoint(100, 100)

console.log(monitor, monitor.id())

let image = monitor.captureImageSync()
fs.writeFileSync(`${monitor.id()}-sync.png`, image.toPngSync())

monitor.captureImage().then((data) => {
  console.log(data)
  fs.writeFileSync(`${monitor.id()}.jpeg`, data.toJpegSync())
})

const monitors = Monitor.all()

monitors.forEach((item) => {
  console.log(
    'Monitor:',
    item.id(),
    item.name(),
    [item.x(), item.y(), item.width(), item.height()],
    item.rotation(),
    item.scaleFactor(),
    item.frequency(),
    item.isPrimary(),
  )
})
```

### Window

```ts
const fs = require('fs')
const { Window } = require('node-screenshots')

let windows = Window.all()

windows.forEach((item) => {
  console.log({
    id: item.id(),
    x: item.x(),
    y: item.y(),
    y: item.z(),
    width: item.width(),
    height: item.height(),
    rotation: item.rotation(),
    scaleFactor: item.scaleFactor(),
    isPrimary: item.isPrimary(),
  })

  let image = item.captureImageSync()
  fs.writeFileSync(`${item.id()}-sync.bmp`, image.toBmpSync())

  item.captureImage().then(async (data) => {
    console.log(data)
    let newImage = await data.crop(10, 10, 10, 10)
    fs.writeFileSync(`${item.id()}.png`, await newImage.toPng())
  })
})
```

## API

Full typeScript type definition: [index.d.ts](./index.d.ts)

### Monitor

- `static all(): Array<Monitor>`: Get all monitor
- `static fromPoint(x: number, y: number): Monitor | null`: Get a monitor from the specified coordinates
- `captureImageSync(): Image`: Synchronously capture image
- `captureImage(): Promise<Image>`: Asynchronously capture image

### Window

- `static all(): Array<Window>`: Get all window
- `captureImageSync(): Image`: Synchronously capture image
- `captureImage(): Promise<Image>`: Asynchronously capture image

### Image

- `cropSync(x: number, y: number, width: number, height: number): Image`: Synchronously crop image
- `crop(x: number, y: number, width: number, height: number): Promise<Image>`: Asynchronously crop image
- `toPngSync(copyOutputData?: boolean | undefined | null): Buffer`:Synchronously Convert to png
- `toPng(copyOutputData?: boolean | undefined | null): Promise<Buffer>`: Asynchronously Convert to png
- `toJpegSync(copyOutputData?: boolean | undefined | null): Buffer`: Synchronously Convert to jpeg
- `toJpeg(copyOutputData?: boolean | undefined | null): Promise<Buffer>`: Asynchronously Convert to jpeg
- `toBmpSync(copyOutputData?: boolean | undefined | null): Buffer`: Synchronously Convert to bmp
- `toBmp(copyOutputData?: boolean | undefined | null): Promise<Buffer>`: Asynchronously Convert to bmp
- `toRawSync(copyOutputData?: boolean | undefined | null): Buffer`: Synchronously Convert to raw(RGBA data)
- `toRaw(copyOutputData?: boolean | undefined | null): Promise<Buffer>`: Asynchronously Convert to raw(RGBA data)

`copyOutputData`: pass related parameters in electron, otherwise electron will crash, nodejs does not pass or passes false, performance will be better, for more information refer to https://github.com/napi-rs/napi-rs/issues/1346

## Linux System Requirements

On Linux, you need to install `libxcb`, `libxrandr`, and `dbus`.

Debian / Ubuntu:

```sh
apt-get install libxcb1 libxrandr2 libdbus-1-3
```

Alpine:

```sh
apk add libxcb libxrandr dbus
```

## Related Repositories

- [xcap](https://github.com/nashaofu/xcap) - XCap is a cross-platform screen capture library written in Rust

---
_Source: https://npm.io/package/node-screenshots · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
