JSPM

  • Created
  • Published
  • Downloads 564959
  • Score
    100M100P100Q189160F
  • License MIT

Browserbase JS SDK

Package Exports

  • @browserbasehq/sdk
  • @browserbasehq/sdk/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@browserbasehq/sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Browserbase logo

Documentation  ·  Playground


Browserbase JS SDK

Browserbase is the best developer platform to reliably run, manage, and monitor headless browsers.

Get browsers' full control and leverage Browserbase's Infrastructure, Stealth Mode, and Session Debugger to power your automation, test suites, and LLM data retrievals.

Installation and setup

1. Install the SDK:

npm install -S @browserbasehq/sdk

2. Get your Browserbase API Key and Project ID:

Usage

import { Browserbase } from '@browserbasehq/sdk'

// Init the SDK
const browserbase = new Browserbase()

// Load a webpage
const rawHtml = await browserbase.load('https://www.browserbase.com')

// Load multiple webpages (returns iterator)
const rawHtmls = browserbase.loadURLs([
  'https://www.browserbase.com',
  'https://docs.browserbase.com',
])

for await (let rawHtml of rawHtmls) {
  // ...
}

// Text-only mode
const text = await browserbase.load('https://www.browserbase.com', {
  textContent: true,
})

// Screenshot (returns bytes)
const result = await browserbase.screenshot('https://www.browserbase.com', {
  textContent: true,
})

Vercel AI SDK Integration

Install the additional dependencies:

npm i ai openai zod
import OpenAI from 'openai'
import { Browserbase, BrowserbaseAISDK } from '@browserbasehq/sdk'
import {
  OpenAIStream,
  StreamingTextResponse,
  generateText,
} from 'ai'

// Create new OpenAI client
const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
})

// Init the Browserbase SDK
const browserbase = new Browserbase()

// Init the tool
const browserTool = BrowserbaseAISDK(browserbase, { textContent: true })

// Load completions
const result = await generateText({
  model: openai.chat('gpt-3.5-turbo'),
  tools: {
    browserTool,
  },
  prompt: 'What is the weather in San Francisco?',
})

Further reading