npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

screenkitten

v1.0.0

Published

A cross-platform Node.js library for taking screenshots on iOS simulators and Android devices/emulators

Readme

Screenkitten 📱📸

A cross-platform Node.js library for taking screenshots on iOS simulators and Android devices/emulators.

Features

  • 🍎 iOS Simulator Support - Take screenshots using xcrun simctl
  • 🤖 Android Device/Emulator Support - Take screenshots using adb
  • 🔄 Cross-platform - Unified API for both platforms
  • 📁 Flexible Output - Save to custom paths or auto-generate temp files
  • AbortController Support - Cancel operations gracefully
  • 🎯 TypeScript - Full type safety and IntelliSense
  • 🔧 Configurable - Extensive options for both platforms
  • 🚨 Rich Error Handling - Detailed error types with proper inheritance

Installation

npm install screenkitten

Quick Start

iOS Simulator

import { screenkitten } from 'screenkitten';

const ios = screenkitten({
  platform: 'ios',
  deviceId: 'booted', // Default: 'booted'
  type: 'png', // Default: 'png'
  outputPath: '/path/to/screenshot.png' // Optional: auto-generated if not provided
});

const screenshotPath = await ios.takeScreenshot();
console.log(`Screenshot saved to: ${screenshotPath}`);

Android Device/Emulator

import { screenkitten } from 'screenkitten';

const android = screenkitten({
  platform: 'android',
  deviceId: 'emulator-5554', // Optional: uses 'booted' by default
  outputPath: '/path/to/screenshot.png' // Optional: auto-generated if not provided
});

const screenshotPath = await android.takeScreenshot();
console.log(`Screenshot saved to: ${screenshotPath}`);

API Reference

Factory Function

screenkitten(options: ScreenkittenOptions)

Creates a platform-specific screenshot instance.

Parameters:

  • options - Configuration object (see platform-specific options below)

Returns: ScreenkittenIOS or ScreenkittenAndroid instance

iOS Options

interface ScreenkittenOptionsIOS {
  platform: 'ios';
  deviceId?: string;        // Default: 'booted'
  xcrunPath?: string;       // Default: '/usr/bin/xcrun'
  type?: 'png' | 'jpeg';    // Default: 'png'
  display?: 'internal' | 'external'; // Default: 'internal'
  mask?: 'ignored' | 'alpha' | 'black'; // Default: 'ignored'
  outputPath?: string;      // Auto-generated if not provided
  abortSignal?: AbortSignal;
  onError?: OnErrorHandler;
}

Android Options

interface ScreenkittenOptionsAndroid {
  platform: 'android';
  deviceId?: string;        // Default: 'booted'
  adbPath?: string;         // Default: 'adb'
  outputPath?: string;      // Auto-generated if not provided
  abortSignal?: AbortSignal;
  onError?: OnErrorHandler;
}

Error Handling

You can control error behavior using the onError option:

type OnErrorHandler = 'throw' | 'ignore' | ((error: Error) => void);

Options:

  • 'throw' (default) - Throws the error
  • 'ignore' - Suppresses the error and returns the output path
  • function - Custom error handler function
// Custom error handling
const ios = screenkitten({
  platform: 'ios',
  onError: (error) => {
    console.error('Screenshot failed:', error.message);
    // Custom logging, reporting, etc.
  }
});

Instance Methods

takeScreenshot(options?: Partial<ScreenkittenOptionsBase>): Promise<string>

Takes a screenshot and returns the path to the saved file.

Parameters:

  • options - Optional override options for this specific screenshot

Returns: Promise that resolves to the screenshot file path

Example:

// Use instance defaults
const path1 = await ios.takeScreenshot();

// Override specific options for this screenshot
const path2 = await ios.takeScreenshot({
  outputPath: '/custom/path.png',
  deviceId: 'specific-device'
});

Abort Controller Support

Cancel screenshot operations gracefully:

const controller = new AbortController();

const ios = screenkitten({
  platform: 'ios',
  abortSignal: controller.signal
});

// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000);

try {
  const path = await ios.takeScreenshot();
  console.log('Screenshot saved:', path);
} catch (error) {
  if (error.name === 'ScreenkittenOperationAbortedError') {
    console.log('Screenshot was cancelled');
  }
}

Error Types

Screenkitten provides specific error types for different failure scenarios:

import {
  ScreenkittenError,                    // Base error class
  ScreenkittenDeviceNotFoundError,      // Device/simulator not found
  ScreenkittenXcrunNotFoundError,       // xcrun tool not found (iOS)
  ScreenkittenAdbNotFoundError,         // adb tool not found (Android)
  ScreenkittenIOSSimulatorError,        // iOS simulator not available
  ScreenkittenAndroidDeviceError,       // Android device not available
  ScreenkittenFileWriteError,           // Failed to write screenshot file
  ScreenkittenOperationAbortedError,    // Operation was aborted
  ScreenkittenScreenshotFailedError,    // Generic screenshot failure
  ScreenkittenInvalidTypeError          // Invalid screenshot type (iOS)
} from 'screenkitten';

All errors extend the base ScreenkittenError class, which extends the standard Error class.

Requirements

iOS

  • macOS with Xcode and iOS Simulator
  • xcrun tool (usually available at /usr/bin/xcrun)

Android

  • Android SDK with adb tool
  • Android device connected or emulator running

CommonJS Support

Screenkitten supports both ES modules and CommonJS:

// ES modules
import { screenkitten } from 'screenkitten';

// CommonJS
const { screenkitten } = require('screenkitten');

License

MIT

Contributing

Contributions are welcome! Please read our Contributing Guide and Code of Conduct.