不依赖零。一个原生的 nodejs 屏幕截图库,适用于 Mac、Windows 和 Linux。
node-screenshots is a native node.js screenshot library based on XCap, It supports Mac, Windows, and Linux systems without any dependencies. node-screenshots supports screenshot and video recording (to be implemented).
English | 简体中文
| 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 | ✓ | ✓ | ✓ |
……Full typeScript type definition: index.d.ts
static all(): Array: Get all monitorstatic fromPoint(x: number, y: number): Monitor | null: Get a monitor from the specified coordinatescaptureImageSync(): Image: Synchronously capture imagecaptureImage(): Promise: Asynchronously capture imagestatic all(): Array: Get all windowcaptureImageSync(): Image: Synchronously capture imagecaptureImage(): Promise: Asynchronously capture imagecropSync(x: number, y: number, width: number, height: number): Image: Synchronously crop imagecrop(x: number, y: number, width: number, height: number): Promise: Asynchronously crop imagetoPngSync(copyOutputData?: boolean | undefined | null): Buffer:Synchronously Convert to pngtoPng(copyOutputData?: boolean | undefined | null): Promise: Asynchronously Convert to pngtoJpegSync(copyOutputData?: boolean | undefined | null): Buffer: Synchronously Convert to jpegtoJpeg(copyOutputData?: boolean | undefined | null): Promise: Asynchronously Convert to jpegtoBmpSync(copyOutputData?: boolean | undefined | null): Buffer: Synchronously Convert to bmptoBmp(copyOutputData?: boolean | undefined | null): Promise: Asynchronously Convert to bmptoRawSync(copyOutputData?: boolean | undefined | null): Buffer: Synchronously Convert to raw(RGBA data)toRaw(copyOutputData?: boolean | undefined | null): Promise: 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
On Linux, you need to install libxcb, libxrandr, and dbus.
Debian / Ubuntu:
apt-get install libxcb1 libxrandr2 libdbus-1-3Alpine:
apk add libxcb libxrandr dbus暂无开放 Issues,或尚未同步最近议题。