@browserless/ai

中文文档
14.1.8发布于 2026/11/08MITCommonJS近 30 天下载 3844

Run Chrome Built-in AI APIs (Prompt, Summarizer, Translator, Language Detector) from Node.js using browserless.

原始使用文档
文档目录9 节
  1. Install
  2. About
  3. Usage
  4. Options
  5. Pack a model
  6. Example
  7. Methods
  8. How it fits in the monorepo
  9. License
browserless browserless

Powered by microlink.io Last version Coverage Status NPM Status

@browserless/ai: Run Chrome Built-in AI from Node.js.

See the ai section on our website for more information.

Install

Using npm:

npm install @browserless/ai --save

Requires Node.js 24+ and a browserless peer.

About

This package runs Chrome Built-in AI from Node.js. It evaluates Prompt, Summarizer, Translator, and Language Detector on a browserless page, so you can call those APIs from a script instead of a visible Chrome window.

Chrome for Testing does not download Gemini Nano for you. Pack a model on a machine that already has it, unpack it into one directory, then pass that dir to createAi / launch.

Chrome’s docs allow the foundation model on GPU (>4 GB VRAM) or CPU (16 GB RAM, 4+ cores) at runtime. The 22 GB profile-volume space and unmetered connection apply only when desktop Chrome first downloads Nano, not when you launch with a packed dir.

Usage

const createAi = require('@browserless/ai')

const { dir } = await createAi.unpack(createAi.download)
const ai = createAi({ dir })

await ai.capabilities()
await ai.detectLanguage('https://example.com', { text: 'Hello, how are you today?' })
await ai.summarize('https://example.com', { type: 'tldr' })
await ai.prompt('https://example.com', { prompt: 'What is this page about?' })
const schema = { type: 'object', properties: { title: { type: 'string' } } }
await ai.extract('https://example.com', { schema })
await ai.translate('https://example.com', { text: 'Hello', sourceLanguage: 'en', targetLanguage: 'es' })
await ai.close()

unpack accepts a local zip path or a download function. createAi.download is a signed R2 GetObject (R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY). The bucket and object key can live in R2_ENDPOINT (https://<account>.r2.cloudflarestorage.com/<bucket>/<key>), or in R2_BUCKET / R2_KEY. The function can return a path, Buffer, stream, or S3 GetObject result, or write to the dest path it receives. If the directory is already unpacked, unpack reuses it unless you pass { force: true }.

If you already have a browserless instance:

const createBrowser = require('browserless')
const createAi = require('@browserless/ai')

const browser = createBrowser(createAi.launch({ dir: process.env.BROWSERLESS_AI_DIR }))
const ai = createAi(async teardown => {
  const browserless = await browser.createContext()
  teardown(() => browserless.destroyContext())
  return browserless
})

Each page-processing method is (url, options). Pass options.text to use your own input; otherwise the package reads document.body.innerText after navigation. capabilities accepts { timeout, url } and supplies defaults.

MethodCreate options
prompt / extracttemperature, topK, initialPrompts, expectedInputs, expectedOutputs
summarizetype, format, length, sharedContext, expectedInputLanguages, outputLanguage, expectedContextLanguages
translatesourceLanguage, targetLanguage (required)
detectLanguageexpectedInputLanguages

Options

OptionTypeDefaultDescription
dirstringBROWSERLESS_AI_DIRUnpacked model tree (nano/, prompt/, summarize/, detect/)
timeoutnumber300000Launch and evaluate timeout (ms). protocolTimeout follows it

unpack(source, { dir, force }) writes to dir when you pass one. Otherwise it uses BROWSERLESS_AI_DIR, or ~/.cache/browserless-ai.

Pack a model

From a machine that already has Nano (desktop Chrome, or BROWSERLESS_AI_DIR):

pnpm --filter @browserless/ai pack-model
pnpm --filter @browserless/ai pack-model -- --upload

Writes /tmp/browserless-ai-nano.zip. --upload also pushes it to R2 (R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY; bucket/key may be in the endpoint URL). Tests run install-model first and download that object when the same variables are set.

Example

pnpm --filter @browserless/ai start
pnpm --filter @browserless/ai start https://example.com

Methods

MethodChrome APIChrome
promptLanguageModel148
extractLanguageModel + schema / responseConstraint148
summarizeSummarizer138
detectLanguageLanguageDetector138
translateTranslator138
capabilitiesfeature detect—

extract requires schema or responseConstraint. translate requires sourceLanguage and targetLanguage. Language Detector and Translator download separately from Gemini Nano. Prompt and Summarizer use Nano.

How it fits in the monorepo

This is an extended functionality package. It is not wired into browserless core — install @browserless/ai when you need Chrome Built-in AI from Node.js.

License

@browserless/ai © 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/ai 共发布 50 个版本,首次发布于 2026/08/24;过去 12 个月发布了 50 个版本。

版本发布日期距今
14.1.8latest2026/11/08今天
14.1.72026/11/071 天前
14.1.62026/11/071 天前
14.1.52026/11/062 天前
14.1.42026/11/062 天前
14.1.32026/11/044 天前

关于 @browserless/ai 的常见问题

@browserless/ai 是什么?

Run Chrome Built-in AI APIs (Prompt, Summarizer, Translator, Language Detector) from Node.js using browserless.

如何安装 @browserless/ai?

在项目目录运行 npm install @browserless/ai,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:browserless(>=13)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@browserless/ai 支持 TypeScript 吗?

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

@browserless/ai 支持 ESM 还是 CommonJS?

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

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

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

@browserless/ai 可以商用吗?

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

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

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

@browserless/ai 还在维护吗?

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