https://github.com/browserbase/js-sdk
https://github.com/browserbase/js-sdk
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/browserbase/js-sdk
- Owner: browserbase
- License: mit
- Created: 2024-04-24T18:29:54.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T10:04:21.000Z (over 1 year ago)
- Last Synced: 2024-10-29T12:08:56.272Z (over 1 year ago)
- Language: TypeScript
- Size: 282 KB
- Stars: 68
- Watchers: 7
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# DEPRECATED. Please refer to v2.0.0 at [browserbase/sdk-node](https://github.com/browserbase/sdk-node)
## Browserbase JS SDK
Browserbase is the best developer platform to reliably run, manage, and monitor headless browsers.
Leverage Browserbase to power your automation, test suites, and LLM data retrievals.
## Installation and setup
### 1. Install the SDK:
```bash
npm install @browserbasehq/sdk
```
### 2. Get your Browserbase API Key and Project ID:
- [Create an account](https://www.browserbase.com/sign-up) or [log in to Browserbase](https://www.browserbase.com/sign-in)
- Copy your API Key and Project ID [from your Settings page](https://www.browserbase.com/settings)
## Usage
```js
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 install ai openai zod
```
```js
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
- [See how to leverage the Session Live View for faster development](https://docs.browserbase.com/features/session-live-view)
- [Sessions API Reference](https://docs.browserbase.com/reference/api/create-a-session)