Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion skills/browserbase-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ Use this skill when the user wants to:
- fetch a page through Browserbase without opening a browser session
- search the web through Browserbase without opening a browser session

## The CLI is the preferred interface

For Browserbase API operations, try `bb` first before constructing curl commands:

- `bb search` instead of `curl ... /v1/search`
- `bb fetch` instead of `curl ... /v1/fetch`
- `bb functions invoke` instead of `curl ... /v1/functions/.../invoke`
- `bb sessions`, `bb contexts`, `bb extensions` instead of direct API calls

## When not to use this skill

- For interactive browsing, page inspection, screenshots, clicking, typing, or login flows, prefer the `browser` skill.
- For simple HTTP content retrieval where the user does not care about using the CLI specifically, the dedicated `fetch` skill is often a better fit.
- Use `bb browse ...` only when the user explicitly wants the CLI wrapper or is already working in a `bb`-centric workflow.

## Command selection
Expand Down
140 changes: 21 additions & 119 deletions skills/fetch/EXAMPLES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Browserbase Fetch API Examples

Common patterns for using the Browserbase Fetch API. Each example shows both cURL and SDK usage.
Common patterns for using the Browserbase Fetch API via the `bb` CLI.

## Safety Notes

Expand All @@ -10,154 +10,56 @@ Common patterns for using the Browserbase Fetch API. Each example shows both cUR

**User request**: "Get the HTML content of example.com"

### cURL

```bash
curl -X POST "https://api.browserbase.com/v1/fetch" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"url": "https://example.com"}'
```

### Node.js

```typescript
const response = await bb.fetchAPI.create({
url: "https://example.com",
});
console.log(response.content); // full HTML
```

### Python

```python
response = bb.fetch_api.create(url="https://example.com")
print(response.content) # full HTML
bb fetch https://example.com
bb fetch https://example.com --output page.html
```

## Example 2: Check HTTP Status and Headers

**User request**: "Check if example.com/api/health is responding and what headers it returns"

### cURL

```bash
curl -s -X POST "https://api.browserbase.com/v1/fetch" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"url": "https://example.com/api/health"}' | jq '{statusCode, headers}'
```

### Node.js

```typescript
const response = await bb.fetchAPI.create({
url: "https://example.com/api/health",
});

console.log(`Status: ${response.statusCode}`);
console.log(`Content-Type: ${response.headers["content-type"]}`);
console.log(`Server: ${response.headers["server"]}`);
bb fetch https://example.com/api/health
```

## Example 3: Fetch with Proxies

**User request**: "Scrape this page but it keeps blocking my IP"

### cURL

```bash
curl -X POST "https://api.browserbase.com/v1/fetch" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"url": "https://target-site.com/data", "proxies": true}'
```

### Node.js

```typescript
const response = await bb.fetchAPI.create({
url: "https://target-site.com/data",
proxies: true,
});

if (response.statusCode === 200) {
console.log("Success with proxy:", response.content);
}
bb fetch https://target-site.com/data --proxies
```

## Example 4: Batch Fetch Multiple URLs

**User request**: "Get the title from these 5 URLs"

### Node.js

```typescript
const urls = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3",
"https://example.com/page4",
"https://example.com/page5",
];

const results = await Promise.all(
urls.map(url => bb.fetchAPI.create({ url, allowRedirects: true }))
);

for (const res of results) {
const titleMatch = res.content.match(/<title>(.*?)<\/title>/);
console.log(titleMatch?.[1] ?? "No title");
}
```
**User request**: "Get the content of these 5 URLs"

### Python

```python
urls = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3",
]

# Sequential (sync SDK)
for url in urls:
response = bb.fetch_api.create(url=url, allow_redirects=True)
# Extract title from HTML
import re
match = re.search(r"<title>(.*?)</title>", response.content)
print(match.group(1) if match else "No title")
```bash
for url in \
"https://example.com/page1" \
"https://example.com/page2" \
"https://example.com/page3" \
"https://example.com/page4" \
"https://example.com/page5"; do
filename=$(echo "$url" | sed 's|https\?://||;s|/|_|g').html
bb fetch "$url" --allow-redirects --output "$filename"
echo "Saved: $filename"
done
```

## Example 5: Fetch API Endpoint (JSON)

**User request**: "Get data from this JSON API endpoint"

### cURL

```bash
curl -s -X POST "https://api.browserbase.com/v1/fetch" \
-H "Content-Type: application/json" \
-H "X-BB-API-Key: $BROWSERBASE_API_KEY" \
-d '{"url": "https://api.example.com/v1/data"}' | jq '.content | fromjson'
```

### Node.js

```typescript
const response = await bb.fetchAPI.create({
url: "https://api.example.com/v1/data",
});

const data = JSON.parse(response.content);
console.log(data);
bb fetch https://api.example.com/v1/data | jq '.content | fromjson'
```

## Tips

- **Use Fetch for static content**: It's faster and cheaper than spinning up a browser session
- **Use Fetch for static content** — it's faster and cheaper than spinning up a browser session
- **Check `statusCode`** to determine how to process the response before parsing `content`
- **Enable `allowRedirects`** by default when scraping — most sites use redirects
- **Use `proxies`** when you hit rate limits or geo-restrictions
- **Enable redirects** with `--allow-redirects` — most sites use redirects
- **Use proxies** with `--proxies` when you hit rate limits or geo-restrictions
- **Fall back to Browser skill** when Fetch returns empty `content` — the page likely requires JavaScript rendering
- **Batch requests** with `Promise.all` (Node.js) for concurrent fetching of multiple URLs
Loading