Skip to content

Commit 99c3ecf

Browse files
committed
updated automations with stagehand tools + new svg + better tool organization
1 parent 1915055 commit 99c3ecf

File tree

11 files changed

+1834
-350
lines changed

11 files changed

+1834
-350
lines changed

examples/integrations/n8n/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

examples/integrations/n8n/LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2022 n8n
1+
Copyright 2025 Browserbase, Inc.
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of
44
this software and associated documentation files (the "Software"), to deal in
Lines changed: 152 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# n8n-nodes-Browserbase
22

3-
This is an n8n community node. It lets you use Browserbase cloud browsers in your n8n workflows.
3+
This is an n8n community node. It lets you use Browserbase cloud browsers in your n8n workflows with both traditional browser automation and AI-powered operations.
44

55
Browserbase is a platform for running headless browsers in the cloud. It provides a simple API for controlling browsers, useful features for managing browser sessions, and scalable infrastructure for web automation tasks like scraping, testing, and user interaction simulation.
66

@@ -22,17 +22,25 @@ Follow the [installation guide](https://docs.n8n.io/integrations/community-nodes
2222
This node supports two main resources:
2323

2424
### Browser Session Management
25-
- **Create Session** - Create a new browser session with configurable options
25+
- **Create Session** - Create a new browser session with configurable options (keep-alive, proxies, viewport settings)
2626
- **Get Sessions** - List all browser sessions for your project
2727
- **Get Session** - Get details of a specific session by ID
2828
- **Delete Session** - Delete a browser session by ID
2929

30-
### Browser Actions (Coming Soon)
30+
### Browser Actions
31+
The node provides both traditional browser automation and AI-powered operations:
32+
33+
#### Traditional Browser Operations
3134
- **Navigate** - Navigate to a specific URL within a session
32-
- **Take Screenshot** - Capture screenshots of pages or elements
33-
- **Get Page Content** - Extract text content from page elements
35+
- **Take Screenshot** - Capture full page or element screenshots
36+
- **Get Page Content** - Extract text content from page elements using CSS selectors
3437
- **Click Element** - Click on page elements using CSS selectors
35-
- **Type Text** - Type text into input fields
38+
- **Type Text** - Type text into input fields using CSS selectors
39+
40+
#### AI-Powered Operations (Stagehand Integration)
41+
- **Act** - Perform actions using natural language instructions (e.g., "click the login button", "fill out the contact form")
42+
- **Observe** - Get insights about the page using natural language queries (e.g., "what products are available?", "is the user logged in?")
43+
- **Extract** - Extract structured data using natural language instructions and Zod schemas
3644

3745
## Credentials
3846

@@ -41,20 +49,22 @@ To use this node, you need:
4149
1. **Browserbase Account**: Sign up at [browserbase.com](https://browserbase.com)
4250
2. **API Key**: Get your API key from the Browserbase dashboard
4351
3. **Project ID**: Create a project and note the Project ID
52+
4. **AI API Key** (for Stagehand operations): OpenAI or Anthropic API key
4453

4554
### Setting up credentials in n8n:
4655
1. In n8n, go to **Settings****Credentials**
4756
2. Click **Add Credential** and search for "Browserbase"
4857
3. Enter your:
4958
- **Browserbase API Key**: Your API key from the dashboard
5059
- **Browserbase Project ID**: Your project ID from the dashboard
60+
- **AI API Key**: Your OpenAI or Anthropic API key (for AI operations)
5161
4. Test the connection and save
5262

5363
## Compatibility
5464

5565
- **Minimum n8n version**: 0.227.0
5666
- **Tested against**: n8n v1.0+
57-
- **Node.js version**: 18+ (required for Browserbase SDK)
67+
- **Node.js version**: 18+ (required for Playwright and Stagehand dependencies)
5868

5969
## Usage
6070

@@ -67,7 +77,7 @@ To use this node, you need:
6777
- Keep Alive: `true` to maintain the session
6878
- Proxies: `true` to use rotating proxies
6979
- Fingerprint: `true` for browser fingerprinting
70-
- Viewport dimensions
80+
- Viewport dimensions (width/height)
7181

7282
2. **List Sessions**
7383
- Resource: `Browser Session`
@@ -84,63 +94,153 @@ To use this node, you need:
8494
- Operation: `Delete Session`
8595
- Session ID: `ses_1234567890`
8696

87-
### Advanced Configuration
88-
89-
When creating sessions, you can configure:
90-
91-
- **Keep Alive**: Whether to keep the session active after operations
92-
- **Browser Settings**:
93-
- Viewport Width/Height for consistent rendering
94-
- **Proxies**: Enable rotating proxies for IP diversity
95-
- **Fingerprinting**: Enable browser fingerprinting for stealth
96-
97-
### Browser Actions (Implementation Required)
98-
99-
The Browser Action resource provides operations that require additional implementation using the Browserbase SDK. Each operation returns instructions for executing the action:
100-
101-
1. **Navigate to URL**
102-
- Session ID: Use an existing session
103-
- URL: Target website
104-
- Wait for Load: Optional page load waiting
105-
106-
2. **Take Screenshot**
107-
- Session ID: Use an existing session
108-
- Screenshot Options: Full page or element-specific
109-
110-
3. **Interact with Elements**
111-
- Session ID: Use an existing session
112-
- Selector: CSS selector for target elements
113-
- Text: For typing operations
97+
### Traditional Browser Automation
98+
99+
#### Navigate to a Page
100+
```
101+
Resource: Browser Action
102+
Operation: Navigate
103+
Session ID: ses_1234567890
104+
URL: https://example.com
105+
```
106+
107+
#### Take Screenshot
108+
```
109+
Resource: Browser Action
110+
Operation: Screenshot
111+
Session ID: ses_1234567890
112+
Screenshot Options:
113+
- Full Page: true/false
114+
- Format: png/jpeg
115+
```
116+
117+
#### Extract Content
118+
```
119+
Resource: Browser Action
120+
Operation: Get Content
121+
Session ID: ses_1234567890
122+
Selector: .product-title (CSS selector)
123+
```
124+
125+
#### Click Elements
126+
```
127+
Resource: Browser Action
128+
Operation: Click
129+
Session ID: ses_1234567890
130+
Selector: button[type="submit"]
131+
```
132+
133+
#### Type Text
134+
```
135+
Resource: Browser Action
136+
Operation: Type
137+
Session ID: ses_1234567890
138+
Selector: input[name="email"]
139+
140+
```
141+
142+
### AI-Powered Operations (Stagehand)
143+
144+
#### Act with Natural Language
145+
```
146+
Resource: Browser Action
147+
Operation: Act
148+
Session ID: ses_1234567890
149+
Instructions: "Click the login button and fill in the email field with [email protected]"
150+
AI Options:
151+
- Model: gpt-4o
152+
- API Key: (from credentials)
153+
```
154+
155+
#### Observe Page State
156+
```
157+
Resource: Browser Action
158+
Operation: Observe
159+
Session ID: ses_1234567890
160+
Instructions: "What products are currently displayed on this page?"
161+
AI Options:
162+
- Model: claude-3-5-sonnet-20241022
163+
- API Key: (from credentials)
164+
```
165+
166+
#### Extract Structured Data
167+
```
168+
Resource: Browser Action
169+
Operation: Extract
170+
Session ID: ses_1234567890
171+
Instructions: "Extract all product information from this page"
172+
Schema: {
173+
"type": "object",
174+
"properties": {
175+
"products": {
176+
"type": "array",
177+
"items": {
178+
"type": "object",
179+
"properties": {
180+
"name": {"type": "string"},
181+
"price": {"type": "string"},
182+
"description": {"type": "string"}
183+
}
184+
}
185+
}
186+
}
187+
}
188+
AI Options:
189+
- Model: gpt-4o-mini
190+
```
191+
192+
### Session Flow Between Operations
193+
194+
The node automatically handles session IDs between operations:
195+
196+
1. **Create Session** → Returns `sessionId`
197+
2. **Use sessionId** in subsequent Browser Action operations
198+
3. **Session persists** across multiple operations
199+
4. **Delete Session** when workflow completes
200+
201+
### AI Model Support
202+
203+
Supported AI models for Stagehand operations:
204+
- **OpenAI**: `gpt-4o`, `gpt-4o-mini`
205+
- **Anthropic**: `claude-3-5-sonnet-20241022`
114206

115207
### Error Handling
116208

117-
The node provides detailed error information including:
118-
- Status codes from the Browserbase API
119-
- Error descriptions
120-
- Additional debugging details
209+
The node provides comprehensive error handling:
210+
- Detailed error messages for API failures
211+
- Browser automation error context
212+
- AI operation error details
213+
- Session management error handling
121214

122-
Enable "Continue on Error" in the node settings to handle failures gracefully.
215+
Enable "Continue on Error" in node settings for graceful failure handling.
123216

124217
### Tips for Production Use
125218

126-
1. **Session Management**: Create sessions at the start of workflows and reuse them for multiple operations
127-
2. **Error Handling**: Always implement error handling for network and browser issues
128-
3. **Rate Limiting**: Be mindful of Browserbase rate limits for session creation
129-
4. **Cleanup**: Delete sessions when workflows complete to manage costs
219+
1. **Session Management**: Create sessions at workflow start and reuse across operations
220+
2. **AI Operations**: Use specific, clear instructions for better AI performance
221+
3. **Traditional vs AI**: Use traditional operations for precise control, AI operations for complex interactions
222+
4. **Error Handling**: Always implement error handling for network and browser issues
223+
5. **Rate Limiting**: Be mindful of both Browserbase and AI API rate limits
224+
6. **Cleanup**: Delete sessions when workflows complete to manage costs
225+
7. **Schema Design**: For extract operations, design clear Zod schemas for consistent data structure
130226

131-
## Declarative Style Implementation
227+
## Implementation Architecture
132228

133-
This node follows n8n's declarative style pattern similar to the HttpBin node:
229+
This node uses a programmatic approach with:
134230

135-
- Uses `requestDefaults` for base API configuration
136-
- Leverages routing for API endpoint definitions
137-
- Provides structured parameter validation
138-
- Implements proper authentication flow
231+
- **Playwright Integration**: Real browser automation via Chrome DevTools Protocol
232+
- **Stagehand AI**: Natural language browser interactions
233+
- **Session Management**: Automatic session ID flow between operations
234+
- **Error Handling**: Comprehensive error catching and reporting
235+
- **Flexible Configuration**: Support for various browser and AI options
139236

140237
## Resources
141238

142239
* [n8n community nodes documentation](https://docs.n8n.io/integrations/#community-nodes)
143240
* [Browserbase Documentation](https://docs.browserbase.com/)
144241
* [Browserbase API Reference](https://docs.browserbase.com/reference/)
145-
* [Browserbase SDK Documentation](https://docs.browserbase.com/reference/sdk/)
146-
* [CSS Selector Guide](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors)
242+
* [Stagehand Documentation](https://docs.browserbase.com/stagehand)
243+
* [Playwright Documentation](https://playwright.dev/)
244+
* [Zod Schema Documentation](https://zod.dev/)
245+
* [OpenAI API Documentation](https://platform.openai.com/docs/)
246+
* [Anthropic API Documentation](https://docs.anthropic.com/)

examples/integrations/n8n/credentials/Browserbase.credentials.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ export class Browserbase implements ICredentialType {
2727
type: 'string',
2828
default: '',
2929
required: true,
30-
description: 'The Project ID for your Browserbase project. You can find this in your Browserbase dashboard.',
30+
description:
31+
'The Project ID for your Browserbase project. You can find this in your Browserbase dashboard.',
32+
},
33+
{
34+
displayName: 'OpenAI API Key (Optional)',
35+
name: 'aiApiKey',
36+
type: 'string',
37+
typeOptions: {
38+
password: true,
39+
},
40+
default: '',
41+
required: false,
42+
description:
43+
'Default AI API key for Stagehand operations. OpenAI keys start with "sk-". Can be overridden per operation.',
3144
},
3245
];
3346

@@ -46,9 +59,9 @@ export class Browserbase implements ICredentialType {
4659
baseURL: 'https://api.browserbase.com/v1',
4760
url: '/sessions',
4861
method: 'GET',
49-
headers: {
50-
'X-BB-API-Key': '={{$credentials.apiKey}}',
51-
},
62+
headers: {
63+
'X-BB-API-Key': '={{$credentials.apiKey}}',
64+
},
5265
},
5366
};
54-
}
67+
}

examples/integrations/n8n/index.js

Whitespace-only changes.

0 commit comments

Comments
 (0)