@accesslint/chrome

中文文档
0.2.0发布于 2026/06/02MITES Module构建来源已验证近 30 天下载 3250

Ensure a debuggable Chrome that serves the CDP HTTP discovery API, and manage its lifecycle. Launches detached so it outlives the launcher process; exposes ensure/stop/status.

原始使用文档
文档目录7 节
  1. Why a separate package
  2. Usage
  3. Commands
  4. Options
  5. Environment
  6. Library API
  7. License

@accesslint/chrome

Ensure a debuggable Chrome that AccessLint's live-DOM audits can drive, and manage its lifecycle.

The AccessLint CLI (@accesslint/cli) is a pure CDP client: give it a debug endpoint and a URL, and it injects @accesslint/core and audits. It does not launch Chrome. This package fills that gap — and launches Chrome detached so it outlives the one-shot launcher process that started it.

Why a separate package

chrome-launcher's launch() ties Chrome's lifetime to the calling process, which is wrong for a npx-style one-shot: when the command exits, Chrome would die before the audit connects. So this package spawns Chrome detached, records its pid + throwaway profile to a state file, and exposes explicit stop.

It also encodes the HTTP-discovery trap: a Chrome opened via the DevTools checkbox (or chrome-devtools-mcp) holds the debug port open but serves only a WebSocket — chrome-remote-interface can't drive it. This package treats a Chrome as usable only when /json/version answers, never on a bare TCP probe. When you pin a port (--port or ACCESSLINT_CDP_PORT) it fails if that port is squatted, so callers stay pointed at the port they asked for; an unpinned ensure steps to the next free port instead.

Usage

# Get-or-launch a driveable Chrome; prints its endpoint as JSON.
npx @accesslint/chrome ensure
# → {"ok":true,"mode":"launched","host":"127.0.0.1","port":9222,"pid":1234,"managed":true,...}

# Idempotent: a second ensure attaches to the running one.
npx @accesslint/chrome ensure        # → {"mode":"attached",...}

# Tear it down.
npx @accesslint/chrome stop --all

Commands

CommandWhat it does
ensureAttach to a driveable Chrome on the port, or launch a detached one.
stopKill a managed instance (--port) or all of them (--all) and clean up.

Options

-p, --port <n>   CDP port to attach to / launch on (default 9222)
    --headed     Launch a visible Chrome instead of headless (ensure)
    --download   Download a managed Chrome for Testing if none is installed (ensure)
    --all        Stop every managed instance (stop)

If the default port is occupied by an undriveable Chrome (checkbox mode), an unpinned ensure steps to a free port and reports the actual one — read port from its JSON output. If you pinned that port with --port, ensure fails instead; free the port or pass a different one.

By default ensure uses the system Chrome (CHROME_PATH or a platform search) and fails if none is found. Pass --download (or set ACCESSLINT_CHROME_DOWNLOAD=1) to fall back to a pinned Chrome for Testing build fetched via @puppeteer/browsers into a cache dir. The download (~170MB) happens once on first use; later runs reuse the cached binary. A system Chrome, when present, always wins — the download is only a fallback.

Environment

ACCESSLINT_CDP_PORT         default port
CHROME_PATH                 override Chrome binary discovery
ACCESSLINT_CHROME_DOWNLOAD   1/true to enable the Chrome for Testing fallback
ACCESSLINT_CHROME_CACHE_DIR  where downloaded Chrome is cached (default ~/.cache/accesslint-chrome)

Library API

import { ensure, stop } from "@accesslint/chrome";

const chrome = await ensure({ port: 9222 }); // { mode, host, port, pid, managed, ... }
// … run an audit against chrome.host:chrome.port …
await stop({ port: chrome.port });

License

MIT

版本与发布记录

@accesslint/chrome 共发布 4 个版本,首次发布于 2026/06/02;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/06/025 个月前
0.1.22026/06/025 个月前
0.1.12026/06/025 个月前
0.1.02026/06/025 个月前

关于 @accesslint/chrome 的常见问题

@accesslint/chrome 是什么?

Ensure a debuggable Chrome that serves the CDP HTTP discovery API, and manage its lifecycle. Launches detached so it outlives the launcher process; exposes ensure/stop/status.

如何安装 @accesslint/chrome?

在项目目录运行 npm install @accesslint/chrome,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 accesslint-chrome,可以用 npx accesslint-chrome 直接运行。

@accesslint/chrome 支持 TypeScript 吗?

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

@accesslint/chrome 支持 ESM 还是 CommonJS?

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

@accesslint/chrome 可以商用吗?

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

@accesslint/chrome 的下载量有多少?

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

@accesslint/chrome 还在维护吗?

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