feat(sdk): expose Browserbase search and fetch - #2828
Conversation
🦋 Changeset detectedLatest commit: 02bfead The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
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 |
There was a problem hiding this comment.
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
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…1-export-browserbasesearch-and-browserbasefetch-through
There was a problem hiding this comment.
2 issues found and verified against the latest diff
Confidence score: 3/5
packages/sdk-go/README.mdindexesresults.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.godoes not validate individual search results, allowing items missingid,title, orurlto 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
| 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) |
There was a problem hiding this comment.
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>
| 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 { |
There was a problem hiding this comment.
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>
Summary
Testing
Summary by cubic
Exposes Browserbase Search and Fetch through the
browserbasefacade in TypeScript, Python, and Go (AP-2921), letting callers search and fetch page content without launching a browser.searchandfetchto the TypeScript and Python facades, plusSearchBrowserbase/FetchBrowserbasein Go.numResults1–25 and the fetch format enum.Written for commit 02bfead. Summary will update on new commits.