The official JavaScript/TypeScript SDK for BabelWrap — the web, as an API, for your agents.
npm install babelwrapimport { BabelWrap } from "babelwrap";
const bw = new BabelWrap({ apiKey: process.env.BABELWRAP_API_KEY! });
const session = await bw.createSession();
try {
// Navigate to a page
const snap = await session.navigate("https://news.ycombinator.com");
console.log(snap.title); // "Hacker News"
// Extract structured data
const stories = await session.extract("top 5 story titles and their URLs");
console.log(stories);
} finally {
await session.close();
}import { BabelWrap } from "babelwrap";
const bw = new BabelWrap({ apiKey: process.env.BABELWRAP_API_KEY! });
await using session = await bw.createSession();
await session.navigate("https://example.com");
await session.fill("Email field", "user@example.com");
await session.fill("Password field", "secret");
await session.submit();
const data = await session.extract("the user profile information");const bw = new BabelWrap({
apiKey: "bw_...", // Required
baseUrl: "https://...", // Default: https://api.babelwrap.com
timeout: 60000, // Default: 60s
maxRetries: 3, // Default: 3
});Methods:
createSession(options?)— Create a new browser sessionusage()— Get current usage statshealth()— Health checkmapSite(url, cookies?)— Map a website and generate typed toolslistSites()— List mapped sitessiteTools(siteId)— Get tools for a mapped siteexecuteTool(siteId, toolName, params?)— Execute a site tool
All methods return a Snapshot (attribute-accessible page state) unless noted.
navigate(url)— Navigate to URLclick(target)— Click element by descriptionfill(target, value)— Fill form fieldsubmit(target?)— Submit formextract(query)— Extract structured data (returnsobject[] | object)press(key)— Press keyboard keyscroll(direction?, amount?)— Scroll pagehover(target)— Hover over elementscreenshot()— Take screenshot (returns base64 string)upload(target, file, filename?)— Upload fileback()/forward()— Browser historysnapshot()— Read current page statewaitFor(options)— Wait for conditionhistory()— Get action historybatch(actions, continueOnError?)— Execute multiple actionsclose()— Close session
Attribute-accessible wrapper for page state:
const snap = await session.navigate("https://example.com");
snap.url; // "https://example.com"
snap.title; // "Example Domain"
snap.inputs; // Snapshot[] of form inputs
snap.inputs[0].label; // "Email address"
snap.get("missing", "default"); // "default"
snap.toDict(); // Plain object- Node.js 18+ (uses global
fetch) - Zero runtime dependencies