@browserless/screenshot

中文文档
14.1.6发布于 2026/11/07MITCommonJS近 30 天下载 2.4万

Capture high-quality screenshots of websites with overlay support, device emulation, and automated image optimization.

原始使用文档
文档目录15 节
  1. Install
  2. About
  3. What this package does
  4. Usage
  5. Options
  6. Browser Overlay
  7. Element Screenshots
  8. Full Page Screenshots
  9. Code Syntax Highlighting
  10. Smart Content Detection
  11. Examples
  12. Architecture
  13. How it fits in the monorepo
  14. Dependencies
  15. License
browserless browserless

Powered by microlink.io Last version Coverage Status NPM Status

@browserless/screenshot: Take a clean screenshot of any website.

See the screenshot section on our website for more information.

Install

Using npm:

npm install @browserless/screenshot --save

About

This package provides advanced screenshot capture with smart defaults, browser frame overlays, gradient backgrounds, and automatic code syntax highlighting. It wraps Puppeteer's page.screenshot() with features optimized for production use.

What this package does

The @browserless/screenshot package allows you to:

  • Capture screenshots with device emulation and smart waiting
  • Add browser frame overlays (dark or light theme)
  • Apply gradient or image backgrounds for social media-ready images
  • Auto-detect blank screenshots and retry until content renders
  • Syntax highlight code (JSON, text) with Prism.js themes
  • Capture specific elements using CSS selectors
  • Take full-page screenshots with lazy-loaded content support

Usage

const createScreenshot = require('@browserless/screenshot')
const createGoto = require('@browserless/goto')

const goto = createGoto({ timeout: 30000 })
const screenshot = createScreenshot({ goto })

// With browserless
const browserless = await browser.createContext()
const buffer = await browserless.screenshot('https://example.com')

// With overlay
const buffer = await browserless.screenshot('https://example.com', {
  overlay: {
    browser: 'dark',
    background: 'linear-gradient(45deg, #FF057C 0%, #8D0B93 50%, #321575 100%)'
  }
})

Options

OptionTypeDefaultDescription
typestring'png'Image format: 'png', 'jpeg', 'webp'
qualitynumber—Quality (0-100) for JPEG/WebP
fullPagebooleanfalseCapture full scrollable page
elementstring—CSS selector for element screenshot
codeSchemestring'atom-dark'Prism.js theme for code highlighting
waitUntilstring'auto'When to consider navigation done
isPageReadyfunction({ isWhite }) => !isWhiteCustom readiness predicate for retry loop
overlayobject{}Browser overlay options

All Puppeteer page.screenshot() options are supported.

Browser Overlay

Add a browser frame around your screenshot for a polished look:

const buffer = await browserless.screenshot(url, {
  overlay: {
    // Browser frame theme: 'dark' or 'light'
    browser: 'dark',

    // Background: color, gradient, or image URL
    background: 'linear-gradient(225deg, #FF057C 0%, #8D0B93 50%, #321575 100%)',

    // Margin around the screenshot (default: 0.2 = 20%)
    margin: 0.2
  }
})

Background Options

// Solid color
overlay: { background: '#c1c1c1' }

// CSS gradient
overlay: { background: 'linear-gradient(45deg, #12c2e9, #c471ed, #f64f59)' }

// Image URL
overlay: { background: 'https://picsum.photos/1920/1080' }

Element Screenshots

Capture a specific DOM element:

const buffer = await browserless.screenshot(url, {
  element: '.hero-section'
})

// The package waits for the element to be visible
const buffer = await browserless.screenshot(url, {
  element: '#main-content'
})

Full Page Screenshots

Capture the entire scrollable page with lazy-loaded content:

const buffer = await browserless.screenshot(url, {
  fullPage: true
})

The package automatically:

  1. Waits for DOM stability
  2. Scrolls through the page to trigger lazy-loaded images
  3. Scrolls back to top
  4. Takes the screenshot

Code Syntax Highlighting

When the response is JSON or plain text, the package automatically renders it with syntax highlighting:

// Screenshot of a JSON API response
const buffer = await browserless.screenshot('https://api.example.com/data', {
  codeScheme: 'atom-dark'  // or any Prism.js theme
})

Available themes from automad-prism-themes and prism-themes. When a theme exists in both, the automad version is used.

ThemeSource
a11y-darkprism-themes
atom-darkautomad
atom-one-darkautomad
atom-one-lightautomad
aura-darkautomad
automad-darkautomad
automad-lightautomad
ayu-darkautomad
ayu-lightautomad
ayu-mirageautomad
baseautomad
base16-ateliersulphurpool.lightprism-themes
bearded-arc-blueberryautomad
bearded-vivid-lightautomad
boola-darkautomad
boola-lightautomad
catppuccin-frappeautomad
catppuccin-latteautomad
catppuccin-macchiatoautomad
catppuccin-mochaautomad
cbprism-themes
coldark-coldautomad
coldark-darkautomad
coy-without-shadowsprism-themes
darculaprism-themes
dark-frostautomad
dark-spaceautomad
draculaautomad
duotone-darkautomad
duotone-earthautomad
duotone-forestautomad
duotone-lightautomad
duotone-seaautomad
duotone-spaceautomad
ghcolorsprism-themes
github-darkautomad
github-lightautomad
gruvbox-darkautomad
gruvbox-lightautomad
holi-themeprism-themes
hopscotchprism-themes
laserwaveautomad
lucarioprism-themes
material-darkprism-themes
material-lightprism-themes
material-oceanicprism-themes
night-owlautomad
night-owl-lightautomad
nightfallautomad
nordautomad
one-darkprism-themes
one-lightprism-themes
pandaautomad
poimandresautomad
pojoaqueprism-themes
rose-pineautomad
rose-pine-dawnautomad
sakura-sunautomad
sea-shells-darkautomad
serendipity-midnightautomad
serendipity-morningautomad
serendipity-sunsetautomad
shades-of-purpleautomad
solarized-dark-atomautomad
synthwave84automad
tailwind-iceautomad
tailwind-moon-blueautomad
tokyo-nightautomad
tokyo-night-lightautomad
tokyo-night-stormautomad
verdandiautomad
verdandi-alterautomad
violet-dreamautomad
vsprism-themes
vsc-dark-plusautomad
xonokaiprism-themes
z-touchprism-themes

Some themes also offer light/dark combo variants that bundle both modes in a single CSS file, switching automatically based on the page's dark mode class. Since screenshots render without a dark mode context, the light variant will always be used — prefer explicit themes like github-light or github-dark instead.

Available combo themes:

Combo themeLightDark
atom-one.light-darkatom-one-lightatom-one-dark
automad.light-darkautomad-lightautomad-dark
ayu.light-darkayu-lightayu-dark
ayu-mirage.light-darkayu-lightayu-mirage
bearded-arc-blueberry.light-darkbearded-vivid-lightbearded-arc-blueberry
boola.light-darkboola-lightboola-dark
catppuccin-frappe.light-darkcatppuccin-lattecatppuccin-frappe
catppuccin-macchiato.light-darkcatppuccin-lattecatppuccin-macchiato
catppuccin-mocha.light-darkcatppuccin-lattecatppuccin-mocha
coldark.light-darkcoldark-coldcoldark-dark
github.light-darkgithub-lightgithub-dark
gruvbox.light-darkgruvbox-lightgruvbox-dark
night-owl.light-darknight-owl-lightnight-owl
rose-pine.light-darkrose-pine-dawnrose-pine
serendipity-midnight.light-darkserendipity-morningserendipity-midnight
serendipity-sunset.light-darkserendipity-morningserendipity-sunset
tailwind-moon-blue.light-darktailwind-icetailwind-moon-blue
tokyo-night-storm.light-darktokyo-night-lighttokyo-night-storm
tokyo-night.light-darktokyo-night-lighttokyo-night
verdandi.light-darkverdandiverdandi-alter

Smart Content Detection

When waitUntil: 'auto' (the default), the package:

  1. Navigates to the page
  2. Waits for fonts to load
  3. Waits for images in viewport to decode
  4. Takes a screenshot
  5. If the screenshot is blank/white, retries with additional waiting

This ensures JavaScript-rendered content is fully loaded.

Examples

Social media card

const buffer = await browserless.screenshot('https://example.com', {
  device: 'iPhone 13',
  overlay: {
    browser: 'light',
    background: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
  }
})

API documentation screenshot

const buffer = await browserless.screenshot('https://api.example.com/docs', {
  fullPage: true,
  type: 'jpeg',
  quality: 85
})

Specific component

const buffer = await browserless.screenshot('https://example.com', {
  element: '[data-testid="pricing-table"]',
  type: 'png'
})

Architecture

@browserless/screenshot
├── src/
│   ├── index.js            → Main screenshot logic with smart waiting
│   ├── is-white-screenshot.js → Blank screenshot detection using Jimp
│   ├── time-span.js        → Timing utility
│   ├── overlay/
│   │   ├── index.js        → Browser frame and background composition
│   │   ├── dark.png        → Dark browser frame
│   │   └── light.png       → Light browser frame
│   └── pretty/
│       ├── index.js        → Code content detection and rendering
│       ├── html.js         → HTML template for code display
│       ├── prism.js        → Prism.js syntax highlighter
│       └── theme.js        → Prism theme loader
└── test/
    └── index.js            → Tests

How it fits in the monorepo

This is a core functionality package for screenshot capture:

ConsumerPurpose
browserless (core)Provides the .screenshot() method
@browserless/cliPowers the browserless screenshot command
@browserless/pdfUses waitForReady and isWhiteScreenshot

Dependencies

PackagePurpose
@browserless/gotoPage navigation with ad blocking
sharpImage composition for overlays; White/blank screenshot detection
automad-prism-themesSyntax highlighting themes
svg-gradientGenerate gradient backgrounds
gotFetch remote background images
is-html-contentDetect if content is HTML vs code

License

@browserless/screenshot © Microlink, released under the MIT License.
Authored and maintained by Microlink with help from contributors.

The logo has been designed by xinh studio.

microlink.io · GitHub microlinkhq · X @microlinkhq

版本与发布记录

@browserless/screenshot 共发布 486 个版本,首次发布于 2019/06/10;过去 12 个月发布了 107 个版本。

版本发布日期距今
14.1.6latest2026/11/071 天前
14.1.52026/11/062 天前
14.1.42026/11/062 天前
14.1.22026/11/035 天前
14.1.12026/11/026 天前
14.0.332026/10/2712 天前

关于 @browserless/screenshot 的常见问题

@browserless/screenshot 是什么?

Capture high-quality screenshots of websites with overlay support, device emulation, and automated image optimization.

如何安装 @browserless/screenshot?

在项目目录运行 npm install @browserless/screenshot,或使用 pnpm add / yarn add / bun add。

@browserless/screenshot 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/browserless__screenshot 是否存在。

@browserless/screenshot 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@browserless/screenshot 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@browserless/screenshot 可以商用吗?

@browserless/screenshot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@browserless/screenshot 的下载量有多少?

根据 npm 官方下载统计,@browserless/screenshot 在 2026/10/09 – 2026/11/07 这 30 天内被下载 24,257 次,日均约 809 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@browserless/screenshot 还在维护吗?

最新版本 14.1.6 发布于 2026/11/07(1 天前);至今共发布 486 个版本,其中过去 12 个月发布了 107 个;首次发布于 2019/06/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。