Skip to content

Commit c92295d

Browse files
authored
Clean up deprecated fields from stagehand.ts and allow CDP parameterization (#609)
1 parent 84f810b commit c92295d

21 files changed

+247
-337
lines changed

Diff for: .changeset/shaggy-mails-march.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": minor
3+
---
4+
5+
Removed deprecated fields and methods from Stagehand constructor and added cdpUrl to localBrowserLaunchOptions for custom CDP URLs support.

Diff for: evals/deterministic/stagehand.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const StagehandConfig: ConstructorParams = {
77
...DefaultStagehandConfig,
88
env: "LOCAL" /* Environment to run Stagehand in */,
99
verbose: 1 /* Logging verbosity level (0=quiet, 1=normal, 2=verbose) */,
10-
headless: true /* Run browser in headless mode */,
1110
browserbaseSessionCreateParams: {
1211
projectId: process.env.BROWSERBASE_PROJECT_ID,
1312
},
1413
enableCaching: false /* Enable caching functionality */,
14+
localBrowserLaunchOptions: {
15+
headless: true /* Run browser in headless mode */,
16+
},
1517
};
1618
export default StagehandConfig;
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { test, expect } from "@playwright/test";
2+
import { Stagehand } from "@/dist";
3+
import StagehandConfig from "@/evals/deterministic/stagehand.config";
4+
import Browserbase from "@browserbasehq/sdk";
5+
6+
test.describe("Browserbase Sessions", () => {
7+
let browserbase: Browserbase;
8+
let sessionId: string;
9+
let bigStagehand: Stagehand;
10+
11+
test.beforeAll(async () => {
12+
browserbase = new Browserbase({
13+
apiKey: process.env.BROWSERBASE_API_KEY,
14+
});
15+
bigStagehand = new Stagehand({
16+
...StagehandConfig,
17+
env: "BROWSERBASE",
18+
browserbaseSessionCreateParams: {
19+
projectId: process.env.BROWSERBASE_PROJECT_ID,
20+
keepAlive: true,
21+
},
22+
});
23+
await bigStagehand.init();
24+
await bigStagehand.page.goto(
25+
"https://docs.stagehand.dev/get_started/introduction",
26+
);
27+
sessionId = bigStagehand.browserbaseSessionID;
28+
if (!sessionId) {
29+
throw new Error("Failed to get browserbase session ID");
30+
}
31+
});
32+
test.afterAll(async () => {
33+
await bigStagehand.close();
34+
});
35+
test("resumes a session via sessionId", async () => {
36+
const stagehand = new Stagehand({
37+
...StagehandConfig,
38+
env: "BROWSERBASE",
39+
browserbaseSessionID: sessionId,
40+
});
41+
await stagehand.init();
42+
43+
const page = stagehand.page;
44+
45+
expect(page.url()).toBe(
46+
"https://docs.stagehand.dev/get_started/introduction",
47+
);
48+
await stagehand.close();
49+
});
50+
test("resumes a session via CDP URL", async () => {
51+
const session = await browserbase.sessions.retrieve(sessionId);
52+
const stagehand = new Stagehand({
53+
...StagehandConfig,
54+
env: "LOCAL",
55+
localBrowserLaunchOptions: {
56+
headless: true,
57+
cdpUrl: session.connectUrl,
58+
},
59+
});
60+
await stagehand.init();
61+
const page = stagehand.page;
62+
63+
expect(page.url()).toBe(
64+
"https://docs.stagehand.dev/get_started/introduction",
65+
);
66+
});
67+
});

Diff for: evals/deterministic/tests/local/create.test.ts

+14-72
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,11 @@ import path from "path";
44
import fs from "fs";
55
import os from "os";
66
import type { Cookie } from "@playwright/test";
7+
import StagehandConfig from "../../stagehand.config";
78

89
test.describe("Local browser launch options", () => {
910
test("launches with default options when no localBrowserLaunchOptions provided", async () => {
10-
const stagehand = new Stagehand({
11-
env: "LOCAL",
12-
verbose: 1,
13-
headless: true,
14-
debugDom: true,
15-
domSettleTimeoutMs: 30_000,
16-
enableCaching: true,
17-
modelName: "gpt-4o",
18-
modelClientOptions: {
19-
apiKey: process.env.OPENAI_API_KEY,
20-
},
21-
});
11+
const stagehand = new Stagehand(StagehandConfig);
2212
await stagehand.init();
2313

2414
const context = stagehand.context;
@@ -32,18 +22,10 @@ test.describe("Local browser launch options", () => {
3222
const customUserDataDir = path.join(os.tmpdir(), "custom-user-data");
3323

3424
const stagehand = new Stagehand({
35-
env: "LOCAL",
36-
verbose: 1,
37-
headless: true,
38-
debugDom: true,
39-
domSettleTimeoutMs: 30_000,
40-
enableCaching: true,
41-
modelName: "gpt-4o",
42-
modelClientOptions: {
43-
apiKey: process.env.OPENAI_API_KEY,
44-
},
25+
...StagehandConfig,
4526
localBrowserLaunchOptions: {
4627
userDataDir: customUserDataDir,
28+
headless: true,
4729
},
4830
});
4931
await stagehand.init();
@@ -60,17 +42,9 @@ test.describe("Local browser launch options", () => {
6042
const customViewport = { width: 1920, height: 1080 };
6143

6244
const stagehand = new Stagehand({
63-
env: "LOCAL",
64-
verbose: 1,
65-
headless: true,
66-
debugDom: true,
67-
domSettleTimeoutMs: 30_000,
68-
enableCaching: true,
69-
modelName: "gpt-4o",
70-
modelClientOptions: {
71-
apiKey: process.env.OPENAI_API_KEY,
72-
},
45+
...StagehandConfig,
7346
localBrowserLaunchOptions: {
47+
...StagehandConfig.localBrowserLaunchOptions,
7448
viewport: customViewport,
7549
},
7650
});
@@ -99,17 +73,9 @@ test.describe("Local browser launch options", () => {
9973
];
10074

10175
const stagehand = new Stagehand({
102-
env: "LOCAL",
103-
verbose: 1,
104-
headless: true,
105-
debugDom: true,
106-
domSettleTimeoutMs: 30_000,
107-
enableCaching: true,
108-
modelName: "gpt-4o",
109-
modelClientOptions: {
110-
apiKey: process.env.OPENAI_API_KEY,
111-
},
76+
...StagehandConfig,
11277
localBrowserLaunchOptions: {
78+
...StagehandConfig.localBrowserLaunchOptions,
11379
cookies: testCookies,
11480
},
11581
});
@@ -133,17 +99,9 @@ test.describe("Local browser launch options", () => {
13399
};
134100

135101
const stagehand = new Stagehand({
136-
env: "LOCAL",
137-
verbose: 1,
138-
headless: true,
139-
debugDom: true,
140-
domSettleTimeoutMs: 30_000,
141-
enableCaching: true,
142-
modelName: "gpt-4o",
143-
modelClientOptions: {
144-
apiKey: process.env.OPENAI_API_KEY,
145-
},
102+
...StagehandConfig,
146103
localBrowserLaunchOptions: {
104+
...StagehandConfig.localBrowserLaunchOptions,
147105
geolocation: customGeolocation,
148106
permissions: ["geolocation"],
149107
},
@@ -174,17 +132,9 @@ test.describe("Local browser launch options", () => {
174132

175133
test("applies custom timezone and locale", async () => {
176134
const stagehand = new Stagehand({
177-
env: "LOCAL",
178-
verbose: 1,
179-
headless: true,
180-
debugDom: true,
181-
domSettleTimeoutMs: 30_000,
182-
enableCaching: true,
183-
modelName: "gpt-4o",
184-
modelClientOptions: {
185-
apiKey: process.env.OPENAI_API_KEY,
186-
},
135+
...StagehandConfig,
187136
localBrowserLaunchOptions: {
137+
...StagehandConfig.localBrowserLaunchOptions,
188138
locale: "ja-JP",
189139
timezoneId: "Asia/Tokyo",
190140
},
@@ -210,17 +160,9 @@ test.describe("Local browser launch options", () => {
210160
fs.mkdirSync(videoDir, { recursive: true });
211161

212162
const stagehand = new Stagehand({
213-
env: "LOCAL",
214-
verbose: 1,
215-
headless: true,
216-
debugDom: true,
217-
domSettleTimeoutMs: 30_000,
218-
enableCaching: true,
219-
modelName: "gpt-4o",
220-
modelClientOptions: {
221-
apiKey: process.env.OPENAI_API_KEY,
222-
},
163+
...StagehandConfig,
223164
localBrowserLaunchOptions: {
165+
...StagehandConfig.localBrowserLaunchOptions,
224166
recordVideo: {
225167
dir: videoDir,
226168
size: { width: 800, height: 600 },

Diff for: evals/tasks/expect_act_timeout.ts

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const expect_act_timeout: EvalFunction = async ({
1616
const result = await stagehand.page.act({
1717
action: "search for 'Stagehand'",
1818
timeoutMs: 1_000,
19-
slowDomBasedAct: true,
2019
});
2120

2221
await stagehand.close();

Diff for: evals/tasks/expect_act_timeout_global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const expect_act_timeout_global: EvalFunction = async ({
1717

1818
const result = await stagehand.page.act({
1919
action: "search for 'Stagehand'",
20-
slowDomBasedAct: true,
20+
timeoutMs: 1_000,
2121
});
2222
console.log("RESULT", result);
2323

Diff for: evals/tasks/extract_zillow.ts

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export const extract_zillow: EvalFunction = async ({
1111
modelName,
1212
logger,
1313
domSettleTimeoutMs: 3000,
14-
configOverrides: {
15-
debugDom: false,
16-
},
1714
});
1815

1916
const { debugUrl, sessionUrl } = initResponse;

Diff for: evals/tasks/nextChunk.ts

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const nextChunk: EvalFunction = async ({ modelName, logger }) => {
1313
await stagehand.page.goto("https://www.apartments.com/san-francisco-ca/");
1414
await stagehand.page.act({
1515
action: "click on the all filters button",
16-
slowDomBasedAct: false,
1716
});
1817

1918
const { initialScrollTop, chunkHeight } = await stagehand.page.evaluate(
@@ -36,7 +35,6 @@ export const nextChunk: EvalFunction = async ({ modelName, logger }) => {
3635

3736
await stagehand.page.act({
3837
action: "scroll down one chunk on the filters modal",
39-
slowDomBasedAct: false,
4038
});
4139

4240
await new Promise((resolve) => setTimeout(resolve, 2000));

Diff for: evals/tasks/prevChunk.ts

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const prevChunk: EvalFunction = async ({ modelName, logger }) => {
3232
await new Promise((resolve) => setTimeout(resolve, 2000));
3333
await stagehand.page.act({
3434
action: "scroll up one chunk",
35-
slowDomBasedAct: false,
3635
});
3736

3837
await new Promise((resolve) => setTimeout(resolve, 5000));

Diff for: evals/tasks/scroll_50.ts

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const scroll_50: EvalFunction = async ({ modelName, logger }) => {
1212
await stagehand.page.goto("https://aigrant.com/");
1313
await stagehand.page.act({
1414
action: "Scroll 50% down the page",
15-
slowDomBasedAct: false,
1615
});
1716

1817
await new Promise((resolve) => setTimeout(resolve, 5000));

Diff for: evals/tasks/scroll_75.ts

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export const scroll_75: EvalFunction = async ({ modelName, logger }) => {
1212
await stagehand.page.goto("https://aigrant.com/");
1313
await stagehand.page.act({
1414
action: "Scroll 75% down the page",
15-
slowDomBasedAct: false,
1615
});
1716

1817
await new Promise((resolve) => setTimeout(resolve, 5000));

Diff for: examples/2048.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ async function example() {
66
const stagehand = new Stagehand({
77
env: "LOCAL",
88
verbose: 1,
9-
debugDom: true,
109
domSettleTimeoutMs: 100,
1110
});
1211
try {

Diff for: examples/debugUrl.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ async function debug(url: string) {
44
const stagehand = new Stagehand({
55
env: "LOCAL",
66
verbose: 2,
7-
debugDom: true,
7+
localBrowserLaunchOptions: {
8+
headless: true,
9+
},
810
});
911
await stagehand.init();
1012
await stagehand.page.goto(url);

Diff for: examples/parameterizeApiKey.ts

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ async function example() {
1515
const stagehand = new Stagehand({
1616
env: "LOCAL",
1717
verbose: 1,
18-
debugDom: true,
1918
enableCaching: false,
2019
modelName: "gpt-4o",
2120
modelClientOptions: {

0 commit comments

Comments
 (0)