Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
64e7170
feat: upload method
udaysvc Aug 27, 2025
38d2a3b
refactor: streamline file upload process and enhance error handling
udaysvc Aug 28, 2025
448ff2f
quick tune
udaysvc Aug 28, 2025
318aef5
chore: add environment configuration for Stagehand
udaysvc Aug 28, 2025
0ff9eb5
greptile comment fixes
udaysvc Aug 28, 2025
5bcbcb1
add changeset for upload method feature
udaysvc Aug 28, 2025
ecd7798
clean
udaysvc Aug 28, 2025
ca9ab89
Merge branch 'browserbase:main' into uday/upload
udaysvc Aug 29, 2025
cb4ebfb
Merge remote-tracking branch 'origin/main' into uday/upload
udaysvc Sep 2, 2025
3d4f29e
Merge branch 'browserbase:main' into uday/upload
udaybuilds47 Sep 3, 2025
4fc2fac
Merge branch 'browserbase:main' into uday/upload
udaybuilds47 Sep 6, 2025
196fc0b
Merge branch 'browserbase:main' into uday/upload
udaysvc Sep 10, 2025
9daa584
add playwright arguments to agent (#1066)
tkattkat Sep 10, 2025
cf0438c
Merge branch 'browserbase:main' into uday/upload
udaysvc Sep 11, 2025
f6f05b0
[docs] add info on not needing project id in browserbase session para…
chrisreadsf Sep 11, 2025
bce40bc
Merge branch 'browserbase:main' into uday/upload
udaysvc Sep 12, 2025
c886544
Export aisdk (#1058)
chrisreadsf Sep 15, 2025
87505a3
docs: update fingerprint settings to reflect the new session create c…
Kylejeong2 Sep 15, 2025
5bb68b9
Resolve merge conflict in lib/index.ts: export both LLMProvider and a…
udaysvc Sep 15, 2025
3c39a05
[docs] export aisdk (#1074)
chrisreadsf Sep 16, 2025
bf2d0e7
Fix zod peer dependency support (#1032)
miguelg719 Sep 16, 2025
7f38b3a
add stagehand agent to api (#1077)
tkattkat Sep 16, 2025
3a0dc58
add playwright screenshot option for browserbase env (#1070)
derekmeegan Sep 17, 2025
b7be89e
add webbench, chrome-based OS world, and ground truth to web voyager …
filip-michalsky Sep 18, 2025
df76f7a
Fix python installation instructions (#1087)
rsbryan Sep 19, 2025
b9c8102
update xpath in `observe_vantechjournal` (#1088)
seanmcguire12 Sep 20, 2025
536f366
Fix session create logs on api (#1089)
miguelg719 Sep 21, 2025
8ff5c5a
Improve failed act logs (#1090)
miguelg719 Sep 21, 2025
569e444
[docs] add aisdk workaround before npm release + add versions to work…
chrisreadsf Sep 22, 2025
72a3a4d
Merge branch 'browserbase:main' into uday/upload
udaysvc Sep 22, 2025
8c0fd01
pass stagehand, instead of stagehandPage to agent (#1082)
tkattkat Sep 22, 2025
dc2d420
img diff algo for screenshots (#1072)
filip-michalsky Sep 23, 2025
f89b13e
Eval metadata (#1092)
miguelg719 Sep 23, 2025
86ee6c3
Merge branch 'browserbase:main' into uday/upload
udaysvc Sep 24, 2025
108de3c
update evals cli docs (#1096)
miguelg719 Sep 26, 2025
e0e6b30
adding support for new claude 4.5 sonnet agent model (#1099)
Kylejeong2 Sep 29, 2025
889cb6c
properly convert custom / mcp tools to anthropic cua format (#1103)
tkattkat Oct 1, 2025
a99aa48
Add current date and page url to agent context (#1102)
miguelg719 Oct 1, 2025
a1ad06c
Additional agent logging (#1104)
miguelg719 Oct 1, 2025
a5be4c9
Merge branch 'browserbase:main' into uday/upload
udaybuilds47 Oct 3, 2025
0791404
Include import statements in extract code examples (#1105)
victlue Oct 4, 2025
3ccf335
fix: missing URLs for `extract()` with array schema (#1107)
seanmcguire12 Oct 6, 2025
dda52f1
Support for new Gemini Computer Use Models (#1110)
miguelg719 Oct 7, 2025
9a29937
google cua docs (#1111)
jay-sahnan Oct 7, 2025
34da7d3
Version Packages (#1062)
github-actions[bot] Oct 7, 2025
ec5317c
Fix Python example in observe.mdx (#1113)
rsbryan Oct 7, 2025
c0fbc51
set default viewport when running on browserbase (#1114)
seanmcguire12 Oct 8, 2025
7da5b55
Version Packages (#1115)
github-actions[bot] Oct 8, 2025
00a8897
Merge branch 'browserbase:main' into uday/upload
udaysvc Oct 8, 2025
89f9237
Fix Quickstart Guide link in README (#1119)
renl Oct 10, 2025
a137da5
Merge branch 'browserbase:main' into uday/upload
udaysvc Oct 10, 2025
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
66 changes: 66 additions & 0 deletions .changeset/chubby-experts-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
"@browserbasehq/stagehand-examples": minor
"@browserbasehq/stagehand-lib": minor
"@browserbasehq/stagehand": minor
---

add upload method with file input + url/buffer support

## New Features

### 🚀 File Upload Method
- **`stagehand.upload(hint: string, file: FileSpec)`** - New method for AI-powered file uploads
- **Natural language hints** - Use descriptive text to locate file inputs (e.g., "Upload resume", "Upload cover letter")
- **Multiple file sources** - Support for URLs, local paths, and in-memory buffers
- **AI-powered detection** - Leverages Stagehand's `observe()` method for intelligent element finding

### 🔧 Enhanced Type System
- **`FileSpec`** - Discriminated union type for flexible file specification
- **`UploadResult`** - Structured response with upload status and metadata
- **Type safety** - Proper validation of file input combinations

### 🌐 Environment Support
- **LOCAL environment** - Works with local Playwright browsers
- **BROWSERBASE environment** - Compatible with cloud-managed browser sessions
- **Cross-platform** - Consistent behavior across different environments

## Technical Details

### Upload Strategies
1. **Direct input** - Attach files directly to `<input type="file">` elements
2. **File chooser** - Trigger file choosers by clicking associated controls
3. **Heuristic search** - Find file inputs near/within hinted elements

### File Processing
- **URL downloads** - Automatic fetching and MIME type detection
- **Memory efficient** - No temporary file creation
- **Buffer handling** - Direct support for in-memory file data

### Integration
- **History tracking** - Upload events logged to Stagehand history
- **Error handling** - Graceful fallbacks with detailed error reporting
- **Performance** - Optimized for minimal DOM queries and efficient file processing

## Usage Examples

```typescript
// Upload from URL
await stagehand.upload("Upload resume", "https://example.com/resume.pdf");

// Upload from buffer
await stagehand.upload("Upload document", {
name: "document.pdf",
mimeType: "application/pdf",
buffer: pdfBuffer
});

// Multiple uploads
await stagehand.upload("Upload resume", resumeFileUrl);
await stagehand.upload("Upload cover letter", letterFileUrl);
```

## Breaking Changes
None - This is a purely additive feature that maintains backward compatibility.

## Migration
No migration required - existing code continues to work unchanged.
103 changes: 103 additions & 0 deletions examples/upload_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Import directly from local dist to ensure latest build is used
import { Stagehand } from "../dist";
import type { Page as PlaywrightPage } from "playwright";
import StagehandConfig from "../stagehand.config";

// Load environment variables
import dotenv from "dotenv";
dotenv.config({ path: "../.env" });

async function main() {
// Accept file URL as command line argument or use default
const fileUrl = process.argv[2] || "https://www.orimi.com/pdf-test.pdf";
const targetPage =
process.argv[3] || "https://ps.uci.edu/~franklin/doc/file_upload.html";

console.log(`File URL: ${fileUrl}`);
console.log(`Target page: ${targetPage}`);

const stagehand = new Stagehand({
...StagehandConfig,
env: "BROWSERBASE",
verbose: 1,
modelName: "openai/gpt-4o-mini",
});
await stagehand.init();
const page = stagehand.page;

try {
// Navigate to the target page
await page.goto(targetPage, {
waitUntil: "domcontentloaded",
});

// Debug: check presence of file inputs before calling upload
const count = await page.locator('input[type="file"]').count();
console.log("file input count:", count);

// Debug: log accessibility tree (full)
try {
const ax = await page.evaluate(() => {
if (typeof window.getComputedStyle !== 'undefined') {
return document.querySelector('body')?.innerHTML || 'No body content';
}
return 'Accessibility snapshot not available';
});
console.log("Page content:");
console.log(ax);
} catch (e) {
console.log("Failed to get page content:", e);
}

// Upload using the new helper - let observe find the right input
// Now we can pass the URL directly since upload() handles URLs
const result = await stagehand.upload("Upload this file", fileUrl);
console.log("upload result:", result);

// Try to submit the form using observe to find the submit button
try {
const [submitAction] = await page.observe(
"Find and click the submit or send button",
);
if (submitAction?.selector) {
console.log(
`Found submit button with selector: ${submitAction.selector}`,
);

// Avoid mixed-content warning by upgrading http action → https when possible
try {
await page.evaluate(() => {
const form = document.querySelector(
"form",
) as HTMLFormElement | null;
if (
form &&
typeof form.action === "string" &&
form.action.startsWith("http://")
) {
form.action = form.action.replace("http://", "https://");
}
});
} catch {
// ignore non-fatal submit upgrade errors
}

await page.act(submitAction);
console.log("Form submitted successfully");
} else {
console.log("No submit button found via observe");
}
} catch (e) {
console.log("Failed to find submit button via observe:", e);
}

await page.waitForTimeout(1500);
} finally {
await stagehand.close();
}
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
Loading