# barebrowse -- Integration Guide > For AI assistants and developers wiring barebrowse into a project. > v0.12.0 | Node.js >= 22 | 0 required deps | Apache-2.0 ## What this is barebrowse is a CDP-direct browsing library for autonomous agents (~3,600 lines in `src/` across 14 modules). URL in, pruned ARIA snapshot out. It launches the user's installed Chromium browser (or attaches to one already running), navigates, handles consent/permissions/cookies, walks iframes, captures downloads, and returns a token-efficient ARIA tree with `[ref=N]` markers for interaction. No Playwright. No bundled browser. No build step. Vanilla JS, ES modules. ``` npm install barebrowse ``` **TypeScript:** ships with `.d.ts` types generated from the source JSDoc, so autocomplete and type-checking work out of the box — no `@types/barebrowse` needed. The library itself is vanilla JS with no build step; the types are a publish-time artifact. Three integration paths: 1. **Library:** `import { browse, connect } from 'barebrowse'` -- one-shot or interactive session 2. **MCP server:** `barebrowse mcp` -- JSON-RPC over stdio for Claude Desktop, Cursor, etc. 3. **CLI session:** `barebrowse open` / `click` / `snapshot` / `close` -- shell commands, outputs to disk ## Which mode do I need? | Mode | What it does | When to use | |---|---|---| | `headless` (default) | Launches a fresh Chromium, no UI | Scraping, reading, fast automation | | `headed` | Auto-launches a visible Chromium window | Bot-detected sites, debugging, visual tasks | | `hybrid` | Tries headless first, headed fallback per-navigation (switches back to headless next time) | General-purpose agent browsing | | `connect({ port })` (attach) | Attaches to a Chromium *you* started with `--remote-debugging-port=N` — your real logged-in profile, no clone | When you need the user's real session (auth cookies, localStorage, IndexedDB). `close()` only kills the tab we opened, not the browser. | Attach mode skips three things vs. spawn modes: stealth patches (would persist via `addScriptToEvaluateOnNewDocument`), `Browser.setPermission` calls (browser-wide — would leak deny-states into the user's other tabs), and `Browser.setDownloadBehavior` (don't override the user's download preference). Stealth is unnecessary anyway because the user's real browser doesn't look headless. ## Minimal usage: one-shot browse ```javascript import { browse } from 'barebrowse'; // Defaults: headless, cookies injected, pruned, consent dismissed const snapshot = await browse('https://example.com'); // All options const snapshot = await browse('https://example.com', { mode: 'headless', // 'headless' | 'headed' | 'hybrid' cookies: true, // inject user's browser cookies browser: 'firefox', // cookie source: 'firefox' | 'chromium' (auto-detected) prune: true, // apply ARIA pruning (47-95% token reduction) pruneMode: 'act', // 'act' (interactive elements) | 'read' (all content) consent: true, // auto-dismiss cookie consent dialogs blockAds: true, // block 128 ad/tracker URL patterns (default on for owned browsers) blockUrls: [], // extra URL globs to block (merged with the default) timeout: 30000, // navigation timeout in ms }); ``` ## connect() API `connect(opts)` returns a page handle for interactive sessions. Same opts as `browse()` for mode. Supports `hybrid` mode — starts headless, auto-launches headed on bot detection (same as `browse()`). | Method | Args | Returns | Notes | |---|---|---|---| | `goto(url, timeout?)` | url: string, timeout: number (default 30000) | void | Navigate + wait for load + dismiss consent | | `goBack()` | -- | void | Navigate back in browser history | | `goForward()` | -- | void | Navigate forward in browser history | | `reload(opts?)` | { ignoreCache?: boolean, timeout?: number } | void | Reload the current page. Clears refMap (refs from pre-reload reject). | | `snapshot(pruneOpts?)` | false or { mode: 'act'\|'read' } | string | ARIA tree with `[ref=N]` markers. Pass `false` for raw. | | `readable()` | -- | object | Clean article text (Reader-View engine). `{ ok, title, byline, text, length, confidence: 'high'\|'low', readerable, hint? }` or `{ ok: false, hint }`. For *reading*, not interacting — see note below. | | `click(ref)` | ref: string | void | Scroll into view + mouse press+release at center | | `type(ref, text, opts?)` | ref: string, text: string, opts: { clear?, keyEvents? } | void | Focus + insert text. `clear: true` replaces existing. | | `press(key)` | key: string | void | Special key: Enter, Tab, Escape, Backspace, Delete, arrows, Home, End, PageUp, PageDown, Space | | `scroll(deltaY)` | deltaY: number | void | Mouse wheel. Positive = down, negative = up. MCP/bareagent also accept `direction: "up"/"down"`. | | `hover(ref)` | ref: string | void | Move mouse to element center | | `select(ref, value)` | ref: string, value: string | void | Set `