Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions oxlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineConfig } from "oxlint";
import { stagehandRuleConfig } from "./rules/oxlint/stagehand-plugin.ts";

export default defineConfig({
// These standalone projects retain their own SDK generations and dependencies.
// Lint them with packages/examples/oxlint.examples.config.ts after copying or editing.
ignorePatterns: ["packages/examples/**"],
jsPlugins: [{ name: "stagehand", specifier: "./rules/oxlint/stagehand-plugin.ts" }],
rules: {
"no-console": "error",
Expand Down
13 changes: 13 additions & 0 deletions packages/examples/.gitignore
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
5 changes: 5 additions & 0 deletions packages/examples/1password-extension/.env.example
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=
7 changes: 7 additions & 0 deletions packages/examples/1password-extension/README.md
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.

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: After npm run upload-extension, the generated ID must be written to .env before npm start; otherwise Stagehand starts without the uploaded extension. Document copying .env.example to .env, supplying the initial values, and inserting the printed EXTENSION_ID between the two commands.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/examples/playbook/1password-extension/README.md, line 5:

<comment>After `npm run upload-extension`, the generated ID must be written to `.env` before `npm start`; otherwise Stagehand starts without the uploaded extension. Document copying `.env.example` to `.env`, supplying the initial values, and inserting the printed `EXTENSION_ID` between the two commands.</comment>

<file context>
@@ -0,0 +1,5 @@
+
+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.
</file context>

26 changes: 26 additions & 0 deletions packages/examples/1password-extension/node/createExtension.ts
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();
35 changes: 35 additions & 0 deletions packages/examples/1password-extension/node/stagehand.ts
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();
})();
19 changes: 19 additions & 0 deletions packages/examples/1password-extension/package.json
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"
}
}
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 packages/examples/1password-extension/python/run_stagehand.py
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())
7 changes: 7 additions & 0 deletions packages/examples/LICENSE
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.
Loading
Loading