Skip to content

feat(sdk): expose Browserbase search and fetch - #2828

Open
miguelg719 wants to merge 9 commits into
mainfrom
miguelgonzalez/ap-2921-export-browserbasesearch-and-browserbasefetch-through
Open

feat(sdk): expose Browserbase search and fetch#2828
miguelg719 wants to merge 9 commits into
mainfrom
miguelgonzalez/ap-2921-export-browserbasesearch-and-browserbasefetch-through

Conversation

@miguelg719

@miguelg719 miguelg719 commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • expose Browserbase Search and Fetch through the TypeScript and Python browserbase facades
  • add equivalent SearchBrowserbase and FetchBrowserbase APIs to Go using the existing Browserbase HTTP transport
  • normalize response models across SDKs and document usage

Testing

  • pnpm --filter @browserbasehq/stagehand build
  • pnpm --filter @browserbasehq/stagehand test:unit (199 passed)
  • Python Ruff, ty, and pytest (460 passed, 1 skipped)
  • Go package tests (passed)

Summary by cubic

Exposes Browserbase Search and Fetch through the browserbase facade in TypeScript, Python, and Go (AP-2921), letting callers search and fetch page content without launching a browser.

  • Adds search and fetch to the TypeScript and Python facades, plus SearchBrowserbase/FetchBrowserbase in Go.
  • Normalizes response models across SDKs, documents usage in READMEs, adds a parity test that keeps option and result models in sync, and relaxes the parity scan timeouts.
  • Validates required fields and value ranges, including numResults 1–25 and the fetch format enum.
  • Rebuilds the Go SDK's embedded extension, reports built/embedded hashes when it drifts, and renames the zip timestamp to invalidate the stale extension build cache.

Written for commit 02bfead. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 02bfead

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@browserbasehq/stagehand-python Minor
@browserbasehq/stagehand-go Minor
@browserbasehq/stagehand Minor
@browserbasehq/stagehand-integrations Patch
@browserbasehq/stagehand-integrations-example-eve-facade Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 19 files

Architecture diagram
sequenceDiagram
    participant User as SDK User
    participant TS as TypeScript SDK<br/>(browserbase facade)
    participant Py as Python SDK<br/>(browserbase facade)
    participant Go as Go SDK<br/>(SearchBrowserbase/FetchBrowserbase)
    participant BB as Browserbase API

    Note over TS,Go: Search Flow

    User->>TS: browserbase.search({apiKey, query, numResults})
    TS->>TS: Validate options (zod: query min 1,<br/>numResults 1-25, strictObject)
    TS->>BB: POST /v1/search with X-BB-API-Key
    BB-->>TS: Search results (query, requestId, results[])
    TS->>TS: Parse/validate response schema
    TS-->>User: BrowserbaseSearchResult

    User->>Py: browserbase.search(api_key, query, num_results)
    Py->>Py: Validate options (pydantic: query min 1,<br/>num_results 1-25)
    Py->>BB: AsyncBrowserbase.search.web()
    BB-->>Py: Search results
    Py->>Py: Normalize publishedDate to ISO format
    Py-->>User: BrowserbaseSearchResult

    User->>Go: SearchBrowserbase(ctx, BrowserbaseSearchOptions)
    Go->>Go: Validate options (query required,<br/>numResults 1-25)
    Go->>Go: Create HTTP client with API key
    Go->>BB: POST /v1/search with X-BB-API-Key
    BB-->>Go: Search response JSON
    Go->>Go: Validate required response fields<br/>(query, requestId, results)
    Go-->>User: BrowserbaseSearchResult

    Note over TS,Go: Fetch Flow

    User->>TS: browserbase.fetch({apiKey, url, format})
    TS->>TS: Validate options (zod: url valid,<br/>format enum raw/json/markdown)
    TS->>BB: POST /v1/fetch with X-BB-API-Key
    BB-->>TS: Fetch result (id, content, contentType,<br/>encoding, headers, statusCode)
    TS->>TS: Parse/validate response schema
    TS-->>User: BrowserbaseFetchResult

    User->>Py: browserbase.fetch(api_key, url, format)
    Py->>Py: Validate options (pydantic: url valid,<br/>format enum, schema alias)
    Py->>BB: AsyncBrowserbase.fetch_api.create()
    BB-->>Py: Fetch result
    Py->>Py: Normalize response fields
    Py-->>User: BrowserbaseFetchResult

    User->>Go: FetchBrowserbase(ctx, BrowserbaseFetchOptions)
    Go->>Go: Validate options (url http/https,<br/>format enum)
    Go->>Go: Create HTTP client with API key
    Go->>BB: POST /v1/fetch with X-BB-API-Key
    BB-->>Go: Fetch response JSON
    Go->>Go: Validate required fields +<br/>decode content (string or object)
    Go-->>User: BrowserbaseFetchResult

    Note over BB: All requests require<br/>X-BB-API-Key header
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/sdk-ts/src/clientSchemas.ts Outdated
Comment thread packages/sdk-ts/src/browser/browserbaseServices.ts
Comment thread packages/sdk-python/README.md Outdated
Comment thread packages/sdk-go/README.md Outdated
Comment thread packages/sdk-go/browserbase_services.go Outdated
Comment thread packages/sdk-python/tests/test_browser.py
@miguelg719
miguelg719 marked this pull request as draft August 27, 2026 02:28
@miguelg719
miguelg719 marked this pull request as ready for review August 27, 2026 03:18

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found and verified against the latest diff

Confidence score: 3/5

  • packages/sdk-go/README.md indexes results.Results[0] without handling a valid empty search response, so the documented example can panic; check the result length and return a useful error.
  • packages/sdk-go/browserbase_services.go does not validate individual search results, allowing items missing id, title, or url to reach callers with empty fields; validate each result before returning it.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/sdk-go/README.md">

<violation number="1" location="packages/sdk-go/README.md:159">
P2: When the search returns no matches, this example panics at `results.Results[0]` instead of handling a valid empty response. Check `len(results.Results)` before indexing and return a useful error.</violation>
</file>

<file name="packages/sdk-go/browserbase_services.go">

<violation number="1" location="packages/sdk-go/browserbase_services.go:146">
P2: When a search response contains an item missing `id`, `title`, or `url`, `SearchBrowserbase` returns that item with empty fields because `validate` never validates individual results. Validate each result item before constructing the public result.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/sdk-go/README.md
Comment on lines +159 to +167
fetched, err := stagehand.FetchBrowserbase(ctx, stagehand.BrowserbaseFetchOptions{
APIKey: os.Getenv("BROWSERBASE_API_KEY"),
URL: results.Results[0].URL,
Format: stagehand.BrowserbaseFetchFormatMarkdown,
})
if err != nil {
return err
}
fmt.Println(fetched.Content)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When the search returns no matches, this example panics at results.Results[0] instead of handling a valid empty response. Check len(results.Results) before indexing and return a useful error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/sdk-go/README.md, line 159:

<comment>When the search returns no matches, this example panics at `results.Results[0]` instead of handling a valid empty response. Check `len(results.Results)` before indexing and return a useful error.</comment>

<file context>
@@ -144,6 +144,29 @@ func run(ctx context.Context) (err error) {
+if err != nil {
+	return err
+}
+fetched, err := stagehand.FetchBrowserbase(ctx, stagehand.BrowserbaseFetchOptions{
+	APIKey: os.Getenv("BROWSERBASE_API_KEY"),
+	URL: results.Results[0].URL,
</file context>
Suggested change
fetched, err := stagehand.FetchBrowserbase(ctx, stagehand.BrowserbaseFetchOptions{
APIKey: os.Getenv("BROWSERBASE_API_KEY"),
URL: results.Results[0].URL,
Format: stagehand.BrowserbaseFetchFormatMarkdown,
})
if err != nil {
return err
}
fmt.Println(fetched.Content)
if len(results.Results) == 0 {
return errors.New("search returned no results")
}
fetched, err := stagehand.FetchBrowserbase(ctx, stagehand.BrowserbaseFetchOptions{
APIKey: os.Getenv("BROWSERBASE_API_KEY"),
URL: results.Results[0].URL,
Format: stagehand.BrowserbaseFetchFormatMarkdown,
})
if err != nil {
return err
}
fmt.Println(fetched.Content)

Results *[]BrowserbaseSearchResultItem `json:"results"`
}

func (response browserbaseSearchResponse) validate() error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a search response contains an item missing id, title, or url, SearchBrowserbase returns that item with empty fields because validate never validates individual results. Validate each result item before constructing the public result.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/sdk-go/browserbase_services.go, line 146:

<comment>When a search response contains an item missing `id`, `title`, or `url`, `SearchBrowserbase` returns that item with empty fields because `validate` never validates individual results. Validate each result item before constructing the public result.</comment>

<file context>
@@ -0,0 +1,224 @@
+	Results   *[]BrowserbaseSearchResultItem `json:"results"`
+}
+
+func (response browserbaseSearchResponse) validate() error {
+	return requireBrowserbaseResponseFields(map[string]bool{
+		"query":     response.Query != nil,
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant