@molecule/api-screenshots-puppeteer

Provider bond · screenshots · API (Node) · v1.1.1 · Apache-2.0

Puppeteer screenshot capture provider for molecule.dev

npm install @molecule/api-screenshots-puppeteer

npm · Source on GitHub · Implements @molecule/api-screenshots

How it works

@molecule/api-screenshots-puppeteer is a provider bond on the API (Node) side: it implements the screenshots core interface (@molecule/api-screenshots) with a concrete vendor or library behind it.

Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.

Works with: @molecule/api-screenshots

Reference

Puppeteer screenshot capture provider for molecule.dev

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Type

provider

Installation

npm install @molecule/api-screenshots-puppeteer @molecule/api-screenshots puppeteer

API

Interfaces

PuppeteerScreenshotsConfig

Options for createProvider(). Every field falls back to its default.

interface PuppeteerScreenshotsConfig {
  /** Path to a Chrome/Chromium executable. Defaults to Puppeteer's own download. */
  executablePath?: string

  /** Extra Chrome launch arguments. Defaults to `['--no-sandbox', '--disable-setuid-sandbox']`. */
  launchArgs?: string[]

  /** Run Chrome headless. Defaults to `true`. */
  headless?: boolean

  /** Per-navigation / per-screenshot timeout in milliseconds. Defaults to `30_000`. */
  timeout?: number

  /**
   * Keep one browser instance across captures instead of launching Chrome per
   * capture. Defaults to `true`.
   */
  reuseBrowser?: boolean
}

Functions

imageDimensions(bytes)

Reads the image dimensions out of encoded PNG bytes (the IHDR chunk) or JPEG bytes (the first start-of-frame marker), so a caller can size the result without a decoding dependency.

function imageDimensions(
  bytes: Buffer<ArrayBufferLike>,
): { width: number; height: number } | undefined
  • bytes — The encoded image.

Returns: Width and height in pixels, or undefined when the bytes are not a decodable PNG/JPEG.

createProvider(config)

Creates a Puppeteer-backed screenshot provider.

function createProvider(config?: PuppeteerScreenshotsConfig): ScreenshotProvider
  • config — Optional provider configuration (executable path, launch args, timeout).

Returns: A ScreenshotProvider backed by Puppeteer.

Constants

provider

The provider implementation (wire with setProvider).

const provider: ScreenshotProvider

SCREENSHOT_LIMITS

Per-capture limits, enforced before Chrome is asked for anything.

const SCREENSHOT_LIMITS: {
  readonly minViewport: 16
  readonly maxViewport: 3840
  readonly maxScale: 3
  readonly maxQuality: 100
  readonly maxDelayMs: 5000
  readonly maxUrlChars: 2048
  readonly maxHtmlChars: 2000000
  readonly maxFullPageHeight: 20000
  readonly maxPixels: 25000000
}

Core Interface

Implements @molecule/api-screenshots interface.

Bond Wiring

Setup function to register this provider with the core interface:

import { setProvider } from '@molecule/api-screenshots'
import { provider } from '@molecule/api-screenshots-puppeteer'

export function setupScreenshotsPuppeteer(): void {
  setProvider(provider)
}

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-screenshots ^1.0.0

Runtime Dependencies

  • @molecule/api-screenshots
  • puppeteer