Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

node-screenshots

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-screenshots

`node-screenshots` is a native node.js screenshot library that supports Mac, Windows, and Linux systems without any dependencies.

Source
npmnpm
Version
0.1.9
Version published
Weekly downloads
17K
23.73%
Maintainers
1
Weekly downloads
 
Created
Source

📸 node-screenshots

node-screenshots is a native node.js screenshot library that supports Mac, Windows, and Linux systems without any dependencies.

English | 简体中文

Support Matrix

Operating System

Operating Systemnode14node16node18
Windows x64
Windows x32
Windows arm64
macOS x64
macOS arm64
Linux x64 gnu
Linux x64 musl

Example

const fs = require("fs");
const { Screenshots } = require("node-screenshots");

let capturer = Screenshots.fromPoint(100, 100);

console.log(capturer, capturer.id);

// Synchronous capture
let image = capturer.captureSync();
fs.writeFileSync("./a.png", image);

// Asynchronous capture
capturer.capture().then((data) => {
    console.log(data);
    fs.writeFileSync(`${capturer.id}.png`, data);
});

// Get all screen captures
let all = Screenshots.all() ?? [];

all.forEach((capturer) => {
    console.log({
        id: capturer.id,
        x: capturer.x,
        y: capturer.y,
        width: capturer.width,
        height: capturer.height,
        rotation: capturer.rotation,
        scaleFactor: capturer.scaleFactor,
        isPrimary: capturer.isPrimary,
    });
    capturer.captureSync(true);
});

API

  • Screenshots.fromPoint(x, y): Get a screenshot from the specified coordinates
  • Screenshots.all(): Get all screenshots
  • screenshots.capture(copyOutputData): Asynchronously capture full screen
  • screenshots.captureSync(copyOutputData): Synchronously capture full screen
  • screenshots.captureArea(x, y, width, height, copyOutputData): Asynchronously capture the specified area
  • screenshots.captureAreaSync(x, y, width, height, copyOutputData): Synchronously capture the specified area

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:

apt-get install libxcb1 libxrandr2 libdbus-1-3

Alpine:

apk add libxcb libxrandr dbus

FAQs

Package last updated on 02 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts