@browserless/ai
v13.13.1
Published
Run Chrome Built-in AI APIs (Prompt, Summarizer, Translator, Language Detector) from Node.js using browserless.
Maintainers
Readme
@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 --saveRequires 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.
| Method | Create options |
|--------|----------------|
| prompt / extract | temperature, topK, initialPrompts, expectedInputs, expectedOutputs |
| summarize | type, format, length, sharedContext, expectedInputLanguages, outputLanguage, expectedContextLanguages |
| translate | sourceLanguage, targetLanguage (required) |
| detectLanguage | expectedInputLanguages |
Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| dir | string | BROWSERLESS_AI_DIR | Unpacked model tree (nano/, prompt/, summarize/, detect/) |
| timeout | number | 300000 | Launch 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 -- --uploadWrites /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.comMethods
| Method | Chrome API | Chrome |
|--------|------------|--------|
| prompt | LanguageModel | 148 |
| extract | LanguageModel + schema / responseConstraint | 148 |
| summarize | Summarizer | 138 |
| detectLanguage | LanguageDetector | 138 |
| translate | Translator | 138 |
| capabilities | feature 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
