@browserless/errors

中文文档
14.0.22发布于 2026/10/13MITCommonJS近 30 天下载 2万

Enhanced error handling for headless browser automation. Provides detailed, actionable error messages for debugging Puppeteer issues.

原始使用文档
文档目录9 节
  1. Install
  2. About
  3. What this package does
  4. Error Types
  5. Usage
  6. Error properties
  7. How it fits in the monorepo
  8. Dependencies
  9. License
browserless browserless

Powered by microlink.io Last version Coverage Status NPM Status

@browserless/errors: A collection of qualified errors for Puppeteer.

Install

Using npm:

npm install @browserless/errors --save

About

This package provides standardized, qualified error types for Puppeteer and browserless operations. It normalizes raw browser errors into consistent, typed errors with unique error codes for easier debugging and error handling.

What this package does

The @browserless/errors package allows you to:

  • Create typed errors with consistent structure and error codes
  • Normalize raw errors from Puppeteer into qualified BrowserlessError instances
  • Identify error types programmatically using error codes
  • Debug errors with built-in serialization and logging

Error Types

Error FactoryCodeDescription
browserTimeoutEBRWSRTIMEOUTPromise or navigation timed out
protocolErrorEPROTOCOLChrome DevTools Protocol error
evaluationFailedEINVALEVALPage evaluation/script execution failed
contextDisconnectedEBRWSRCONTEXTCONNRESETBrowser context connection was reset
pageRangeEPAGERANGEprintToPDF was given a page range starting past the end of the document

Codes carry retryability: the core retries EPROTOCOL and EBRWSRCONTEXTCONNRESET, and nothing else. EPAGERANGE exists because an unsatisfiable page range is the one protocol failure that is deterministic — retrying it burns the caller's budget and surfaces a timeout instead of the real reason.

Usage

const errors = require('@browserless/errors')

// Create a timeout error
const timeoutError = errors.browserTimeout({ timeout: 30000 })
// => BrowserlessError: EBRWSRTIMEOUT, Promise timed out after 30000 milliseconds

// Create a protocol error
const protocolError = errors.protocolError({ message: 'Printing failed' })
// => BrowserlessError: EPROTOCOL, Printing failed

// Create an evaluation error
const evalError = errors.evaluationFailed({ message: 'foo is not defined' })
// => BrowserlessError: EINVALEVAL, foo is not defined

// Normalize a raw error from Puppeteer (page target gone mid-evaluate)
const rawError = { message: 'Protocol error (Runtime.evaluate): Target closed' }
const normalizedError = errors.ensureError(rawError)
// => BrowserlessError: EBRWSRCONTEXTCONNRESET, The browser context is not connected.

// Normalize a page range Chrome cannot satisfy
const rangeError = errors.ensureError({
  message: 'Protocol error (Page.printToPDF): Page range exceeds page count'
})
// => BrowserlessError: EPAGERANGE, Page range exceeds page count

// Check if an error is a BrowserlessError
if (errors.isBrowserlessError(normalizedError)) {
  console.log('Error code:', normalizedError.code)
}

Two predicates are exported for classifying a raw error before it is normalized:

errors.isContextDestroyed(rawError)    // frame torn down mid-flight — transient
errors.isPageRangeOvershoot(rawError)  // range starts past the last page — deterministic

Error properties

All BrowserlessError instances include:

PropertyDescription
nameAlways 'BrowserlessError'
codeUnique error code (e.g., EBRWSRTIMEOUT)
messageHuman-readable error message prefixed with the code

How it fits in the monorepo

This is a foundational utility package used throughout the browserless ecosystem:

ConsumerPurpose
browserless (core)Wraps operations with timeout errors, normalizes caught errors
@browserless/gotoHandles navigation and protocol errors
@browserless/screenshotHandles screenshot capture errors
@browserless/pdfHandles PDF generation errors

Dependencies

PackagePurpose
whoopsError factory for creating typed errors with codes
ensure-errorEnsures values are proper Error instances
serialize-errorSerializes errors for debug logging
debug-logfmtStructured debug logging

License

@browserless/errors © 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/errors 共发布 76 个版本,首次发布于 2020/03/03;过去 12 个月发布了 22 个版本。

版本发布日期距今
14.0.22latest2026/10/1326 天前
14.0.02026/10/081 个月前
13.9.232026/09/141 个月前
13.9.112026/09/062 个月前
13.9.102026/09/022 个月前
13.6.102026/07/283 个月前

关于 @browserless/errors 的常见问题

@browserless/errors 是什么?

Enhanced error handling for headless browser automation. Provides detailed, actionable error messages for debugging Puppeteer issues.

如何安装 @browserless/errors?

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

@browserless/errors 支持 TypeScript 吗?

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

@browserless/errors 支持 ESM 还是 CommonJS?

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

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

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

@browserless/errors 可以商用吗?

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

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

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

@browserless/errors 还在维护吗?

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