-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Consolidate Stagehand examples into a flat catalog and link skills #2934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
shrey150
wants to merge
5
commits into
main
Choose a base branch
from
consolidate/examples-and-skills
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ba5e2b
Consolidate reviewed Stagehand examples and link external skills
shrey150 2966776
Merge remote-tracking branch 'origin/main' into consolidate/examples-…
shrey150 67add60
Fix standalone examples lint configuration discovery
shrey150 65450b4
Keep standalone example lint config out of root discovery
shrey150 5f4478a
Flatten example catalog and reuse existing integrations
shrey150 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Local runtime output from standalone examples | ||
| .cache/ | ||
| __pycache__/ | ||
| .venv/ | ||
| .next/ | ||
| .convex/ | ||
| reports/ | ||
| screenshots/ | ||
| output/ | ||
| outputs/ | ||
| downloads/ | ||
| downloaded_files.zip | ||
| *.tsbuildinfo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| BROWSERBASE_API_KEY= | ||
| BROWSERBASE_PROJECT_ID= | ||
| EXTENSION_ZIP_PATH=./1password.zip | ||
| MODEL_API_KEY= | ||
| EXTENSION_ID= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # 1Password extension guide | ||
|
|
||
| Location in the Stagehand repository: `packages/examples/1password-extension`. | ||
|
|
||
| Stagehand opens an uploaded browser extension, starts interactive sign-in, and visits Browserbase. Supply your own extension archive and the values named in `.env.example`. No extension binary, account state, or credentials are bundled. | ||
|
|
||
| For the Node example, run `npm install`, then `npm run upload-extension` and `npm start`. This guide uses Stagehand v2. The Python files are preserved legacy `StagehandConfig` snippets: the source repo did not declare a compatible Python Stagehand dependency, so they require an SDK port before use with Stagehand v4. | ||
26 changes: 26 additions & 0 deletions
26
packages/examples/1password-extension/node/createExtension.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import Browserbase from "@browserbasehq/sdk"; | ||
| import { createReadStream } from "fs"; | ||
| import dotenv from "dotenv"; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| export async function createExtension(bb: Browserbase): Promise<string> { | ||
| const extensionPath = process.env.EXTENSION_ZIP_PATH!; | ||
| const extension = await bb.extensions.create({ | ||
| file: createReadStream(extensionPath), | ||
| }); | ||
| console.log("\n\n\n"); | ||
| console.log(`Extension uploaded with ID: ${extension.id}`); | ||
| console.log(`Load this extension into your .env file as EXTENSION_ID`); | ||
| console.log("\n\n\n"); | ||
| return extension.id; | ||
| } | ||
|
|
||
| async function main() { | ||
| const bb = new Browserbase({ | ||
| apiKey: process.env.BROWSERBASE_API_KEY!, | ||
| }); | ||
| await createExtension(bb); | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { ConstructorParams, Stagehand } from "@browserbasehq/stagehand"; | ||
| import dotenv from "dotenv"; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| const stagehandConfig = (): ConstructorParams => ({ | ||
| env: "BROWSERBASE", | ||
| modelName: "openai/gpt-4o-mini", | ||
| modelClientOptions: { apiKey: process.env.MODEL_API_KEY! }, | ||
| browserbaseSessionCreateParams: { | ||
| projectId: process.env.BROWSERBASE_PROJECT_ID!, | ||
| browserSettings: { | ||
| extensionId: process.env.EXTENSION_ID!, | ||
| }, | ||
| }, | ||
| }); | ||
| (async () => { | ||
| const stagehand = new Stagehand(stagehandConfig()); | ||
| await stagehand.init(); | ||
| const page = stagehand.page; | ||
|
|
||
| // log in to 1password | ||
| await page.goto("chrome-extension://aeblfdkhhhdcdjpifhhbdiojplfjncoa/app/app.html#/page/welcome"); | ||
| await page.act("click the Continue button"); | ||
| await page.act("click the Sign in button"); | ||
|
|
||
| // wait for enter in the terminal | ||
| await new Promise((resolve) => setTimeout(resolve, 10000)); | ||
|
|
||
| // log in to browserbase using the credentials from 1password | ||
| await page.goto("https://browserbase.com/sign-in"); | ||
| await page.waitForLoadState("networkidle"); | ||
|
|
||
| await page.close(); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "stagehand-example-1password-extension", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "start": "tsx node/stagehand.ts", | ||
| "upload-extension": "tsx node/createExtension.ts" | ||
| }, | ||
| "dependencies": { | ||
| "@browserbasehq/sdk": "^2.6.0", | ||
| "@browserbasehq/stagehand": "^2.2.1", | ||
| "dotenv": "^16.4.7" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^22.9.1", | ||
| "tsx": "^4.19.2", | ||
| "typescript": "^5.0.0" | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
packages/examples/1password-extension/python/create_extension.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import os | ||
| from browserbase import Browserbase | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
|
||
| def create_extension(bb: Browserbase) -> str: | ||
| extension_path = os.getenv("EXTENSION_ZIP_PATH") | ||
| if not extension_path: | ||
| raise ValueError("EXTENSION_ZIP_PATH environment variable is required") | ||
|
|
||
| with open(extension_path, 'rb') as file: | ||
| extension = bb.extensions.create(file=file) | ||
|
|
||
| print("\n\n\n") | ||
| print(f"Extension uploaded with ID: {extension.id}") | ||
| print("Load this extension into your .env file as EXTENSION_ID") | ||
| print("\n\n\n") | ||
| return extension.id | ||
|
|
||
| def main(): | ||
| api_key = os.getenv("BROWSERBASE_API_KEY") | ||
| if not api_key: | ||
| raise ValueError("BROWSERBASE_API_KEY environment variable is required") | ||
|
|
||
| bb = Browserbase(api_key=api_key) | ||
| create_extension(bb) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
41 changes: 41 additions & 0 deletions
41
packages/examples/1password-extension/python/run_stagehand.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import asyncio | ||
| import os | ||
| from stagehand import Stagehand, StagehandConfig | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
|
||
| async def main(): | ||
| config = StagehandConfig( | ||
| env="BROWSERBASE", | ||
| api_key=os.getenv("BROWSERBASE_API_KEY"), | ||
| project_id=os.getenv("BROWSERBASE_PROJECT_ID"), | ||
| model_name="gpt-4o", | ||
| model_api_key=os.getenv("MODEL_API_KEY"), | ||
| browserbase_session_create_params={ | ||
| "project_id": os.getenv("BROWSERBASE_PROJECT_ID"), | ||
| "browser_settings": { | ||
| "extension_id": os.getenv("EXTENSION_ID") | ||
| } | ||
| } | ||
| ) | ||
| stagehand = Stagehand(config) | ||
| try: | ||
| await stagehand.init() | ||
| page = stagehand.page | ||
|
|
||
| await page.goto("chrome-extension://aeblfdkhhhdcdjpifhhbdiojplfjncoa/app/app.html#/page/welcome") | ||
| await page.act("click the Continue button") | ||
| await page.act("click the Sign in button") | ||
|
|
||
| # wait 60 seconds | ||
| await asyncio.sleep(60) | ||
|
|
||
| await page.goto("https://browserbase.com/sign-in") | ||
| await asyncio.sleep(10) | ||
|
|
||
| finally: | ||
| await stagehand.close() | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Copyright 2025 Browserbase, Inc. | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: After
npm run upload-extension, the generated ID must be written to.envbeforenpm start; otherwise Stagehand starts without the uploaded extension. Document copying.env.exampleto.env, supplying the initial values, and inserting the printedEXTENSION_IDbetween the two commands.Prompt for AI agents