@agentproto/driver-browser

中文文档
0.4.1发布于 2026/11/01Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 5204

Browser provider kit: defineBrowser (manifest + launch), the BrowserInstance and BrowserDriver ports, a provider registry, a provider-kit lister, and a typed capability gate (browser:unsupported).

原始使用文档
文档目录7 节
  1. What is in the box
  2. Define a provider
  3. The capability gate
  4. Health
  5. Supervisor
  6. Conformance kit
  7. Scope

@agentproto/driver-browser

The browser provider kit. It gives every browser backend (a stealth Firefox behind REST, Playwright-managed Chromium, the system Chrome, a hosted browser service) one shape, so a host can list, launch, attach to and gate them the same way.

Spec: the BROWSER AIP (working title BROWSER.md, agentbrowser/v1), draft in agentproto/agentproto#53. The AIP number is provisional until the editors assign it.

What is in the box

PieceWhat it is
defineBrowserValidates a manifest (zod) and returns a frozen BrowserProvider. Built on createDoctype, like defineDriver. Pure construction, no I/O.
BrowserProviderManifest fields plus launch(opts, ctx), an idempotent ensure that returns a BrowserInstance.
BrowserInstanceid, endpoints {rest?, cdp?}, pid?, wasAlreadyRunning, health(), attach(opts), stop().
BrowserDriverThe page and tab control port (navigate, evaluate, click, fill, screenshot, network, raw CDP), with zod schemas for its option and result shapes.
BrowserCapabilitiesPage-level flags (canFullPageScreenshot, ...) and process-level flags (stealth, headless, cdp, downloads, recording, ...). All default to off.
createBrowserRegistryRegister, look up and list providers. A duplicate id throws.
makeBrowserProviderListerA standard @agentproto/provider-kit lister over a registry.
assertCapability, BrowserUnsupportedErrorThe capability gate.

Define a provider

import { defineBrowser } from "@agentproto/driver-browser"

export const camofox = defineBrowser({
  id: "camofox",
  name: "Camoufox (stealth Firefox)",
  description: "Stealth Firefox behind a local REST service.",
  version: "1.0.0",
  transport: "http", // sdk | http | cli
  location: "local", // local | remote (remote = a third party sees session data)
  capabilities: { stealth: true, downloads: true, headless: true, persistentProfile: true },
  async launch(opts, ctx) {
    // Return the running instance if one is healthy: wasAlreadyRunning: true.
    // Otherwise start one.
  },
})

The capability gate

A call that needs a capability the provider lacks fails with a typed error, not an opaque transport failure:

import { assertToolSupported, isBrowserUnsupportedError } from "@agentproto/driver-browser"

try {
  assertToolSupported(provider.capabilities, "browser.list_requests", provider.id)
} catch (err) {
  if (isBrowserUnsupportedError(err)) {
    err.code // "browser:unsupported" (stable)
    err.capability // "cdp"
    err.message // '"browser.list_requests" needs the "cdp" capability, which is not supported on provider "camofox"'
  }
}

BrowserUnsupportedError extends the AIP-14 ToolError, so toToolResult puts code and cause: { capability } into the standard envelope.

Health

BrowserInstance.health() returns { ok, reason?, lifecycle? }. lifecycle carries the fields a supervising host reads from a service /health, all optional (a server reports null for a field it has not set yet): bootId, startedAt, browserState (launching | running | idle | crash-looping), launchedAt, lastLaunchMs, lastRestartReason.

Supervisor

createBrowserSupervisor runs a provider under a health loop. Time and process access are injected (clock, orphanSweep.listProcesses/kill), so tests need no real sleeps or processes.

import { createBrowserSupervisor, browserInstanceMarker } from "@agentproto/driver-browser"

const supervisor = createBrowserSupervisor({
  provider,
  launchOptions: { label: "work" },
  healthIntervalMs: 10_000,
  launchBudgetMs: 120_000, // a slow launch inside the budget is not a failure
  crashLoop: { maxFailures: 3, windowMs: 300_000 },
  orphanSweep: { marker: browserInstanceMarker("work") },
  onBackendRestart: ({ previousBootId, bootId }) => {},
})
await supervisor.start()
  • Launch-loop detector. maxFailures failed starts inside windowMs (a launch over launchBudgetMs counts as one) flip the state to crash-looping. No further launch is attempted, by start() or by the health loop, until an explicit restart(), which clears the counters.
  • Health loop. Reads BrowserInstance.health(). A changed bootId means the backend restarted and fires onBackendRestart. browserState: "crash-looping" (even on a 503 with ok: false) is a state the supervisor reports, not "down": relaunching would not help. launching is not a failure. A plain ok: false for unhealthyThreshold probes in a row triggers a relaunch.
  • Orphan sweep. sweepOrphans signals only processes whose command carries the exact marker token (--agentproto-browser=<key>), from an injected process lister. It never matches by process name and never signals the current process. Pass the marker to the browser's argv when launching.
  • KeepAlivePolicy. An idle-tab reaper policy that never reaps the tabs of a keepAlive session, and an idle-browser-shutdown gate (shouldShutdownIdleBrowser) that refuses while any keepAlive session exists.

Conformance kit

import { createFakeBrowserProvider, runConformance } from "@agentproto/driver-browser"

const { provider } = createFakeBrowserProvider()
const report = await runConformance(provider, { levels: ["core", "interaction", "network"] })
report.ok // false if any check failed
report.failed // ["core/launch-idempotent", ...]

Levels: core (manifest, instance shape, idempotent launch, health, navigate, idempotent stop, remote providers report no local pid), interaction (evaluate, DOM, screenshot, click/fill with a fixture), network (needs cdp), download (needs downloads) and profile (needs persistentProfile). A level whose capability the provider does not declare is reported as skipped with the typed browser:unsupported, never as a failure; the network level still checks that the missing capability fails with browser:unsupported rather than an opaque error. The download level only checks that the declared capability is consistent with the tool gate for now, because the driver port has no download verb; add provider checks with extraChecks.

For location: "remote" providers pass launch: { baseUrl }. The kit ships startFakeRemoteBrowserServer() (local http, random port) and createFakeRemoteBrowserProvider() so remote conformance can be exercised without a third party. createFakeBrowserProvider({ faults }) builds deliberately broken variants.

Scope

This package holds the model, the supervisor and the conformance kit. Concrete providers and the runtime tool wiring live in other packages.

License: Apache-2.0.

版本与发布记录

@agentproto/driver-browser 共发布 8 个版本,首次发布于 2026/09/30;过去 12 个月发布了 8 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.1latest2026/11/014 天前
0.4.02026/10/279 天前
0.3.12026/10/1918 天前
0.3.02026/10/1819 天前
0.2.22026/10/1027 天前
0.2.12026/10/0928 天前

关于 @agentproto/driver-browser 的常见问题

@agentproto/driver-browser 是什么?

Browser provider kit: defineBrowser (manifest + launch), the BrowserInstance and BrowserDriver ports, a provider registry, a provider-kit lister, and a typed capability gate (browser:unsupported).

如何安装 @agentproto/driver-browser?

在项目目录运行 npm install @agentproto/driver-browser,或使用 pnpm add / yarn add / bun add。

@agentproto/driver-browser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agentproto/driver-browser 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agentproto/driver-browser 可以商用吗?

@agentproto/driver-browser 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@agentproto/driver-browser 的下载量有多少?

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

@agentproto/driver-browser 还在维护吗?

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