Skip to content

Commit 8c28647

Browse files
authored
Remove refreshPageFromApi (#925)
# why No longer necessary # what changed Removed `_refreshPageFromApi` that would get called after each api call, also fixed `heal_custom_dropdown` eval # test plan
1 parent c20adb9 commit 8c28647

File tree

5 files changed

+28
-61
lines changed

5 files changed

+28
-61
lines changed

.changeset/gold-gifts-marry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Remove \_refreshPageFromApi()

evals/deterministic/tests/page/livePageProxy.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ test.describe("StagehandPage - live page proxy", () => {
88
await stagehand.init();
99

1010
const page = stagehand.page;
11-
await page.goto("https://browserbase.github.io/stagehand-eval-sites/sites/five-tab/");
11+
await page.goto(
12+
"https://browserbase.github.io/stagehand-eval-sites/sites/five-tab/",
13+
);
1214
await page.locator("body > button").click();
13-
await new Promise(resolve => setTimeout(resolve, 1000));
14-
await page.waitForURL('**/page2.html', {waitUntil: "commit"});
15+
await new Promise((resolve) => setTimeout(resolve, 1000));
16+
await page.waitForURL("**/page2.html", { waitUntil: "commit" });
1517
// await new Promise(resolve => setTimeout(resolve, 1000));
1618
const currentURL = page.url();
17-
const expectedURL = "https://browserbase.github.io/stagehand-eval-sites/sites/five-tab/page2.html";
19+
const expectedURL =
20+
"https://browserbase.github.io/stagehand-eval-sites/sites/five-tab/page2.html";
1821

1922
expect(currentURL).toBe(expectedURL);
2023

@@ -26,9 +29,11 @@ test.describe("StagehandPage - live page proxy", () => {
2629
await stagehand.init();
2730

2831
const page = stagehand.page;
29-
await page.goto("https://browserbase.github.io/stagehand-eval-sites/sites/five-tab/");
32+
await page.goto(
33+
"https://browserbase.github.io/stagehand-eval-sites/sites/five-tab/",
34+
);
3035
await page.locator("body > button").click();
31-
await new Promise(resolve => setTimeout(resolve, 1000));
36+
await new Promise((resolve) => setTimeout(resolve, 1000));
3237

3338
const expectedNumPages = 2;
3439
const actualNumPages = stagehand.context.pages().length;

evals/tasks/heal_custom_dropdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const heal_custom_dropdown: EvalFunction = async ({
2222
);
2323

2424
await page.act({
25-
description: "The dropdown",
25+
description: "The 'Select a country' dropdown",
2626
selector: "/html/not-a-dropdown",
2727
arguments: [],
2828
method: "click",

lib/StagehandPage.ts

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { Browserbase } from "@browserbasehq/sdk";
21
import type { CDPSession, Page as PlaywrightPage, Frame } from "playwright";
3-
import { chromium } from "playwright";
42
import { z } from "zod";
53
import { Page, defaultExtractSchema } from "../types/page";
64
import {
@@ -23,7 +21,6 @@ import {
2321
StagehandNotInitializedError,
2422
StagehandEnvironmentError,
2523
CaptchaTimeoutError,
26-
BrowserbaseSessionNotFoundError,
2724
MissingLLMConfigurationError,
2825
HandlerNotInitializedError,
2926
StagehandDefaultError,
@@ -191,40 +188,6 @@ ${scriptContent} \
191188
}
192189
}
193190

194-
private async _refreshPageFromAPI() {
195-
if (!this.api) return;
196-
197-
const sessionId = this.stagehand.browserbaseSessionID;
198-
if (!sessionId) {
199-
throw new BrowserbaseSessionNotFoundError();
200-
}
201-
202-
const browserbase = new Browserbase({
203-
apiKey: this.stagehand["apiKey"] ?? process.env.BROWSERBASE_API_KEY,
204-
});
205-
206-
const sessionStatus = await browserbase.sessions.retrieve(sessionId);
207-
208-
const connectUrl = sessionStatus.connectUrl;
209-
const browser = await chromium.connectOverCDP(connectUrl);
210-
const context = browser.contexts()[0];
211-
const newPage = context.pages()[0];
212-
213-
const newStagehandPage = await new StagehandPage(
214-
newPage,
215-
this.stagehand,
216-
this.intContext,
217-
this.llmClient,
218-
this.userProvidedInstructions,
219-
this.api,
220-
).init();
221-
222-
this.intPage = newStagehandPage.page;
223-
224-
await this.intPage.waitForLoadState("domcontentloaded");
225-
await this._waitForSettledDom();
226-
}
227-
228191
/**
229192
* Waits for a captcha to be solved when using Browserbase environment.
230193
*
@@ -387,20 +350,17 @@ ${scriptContent} \
387350
}
388351
}
389352

390-
if (this.api) {
391-
await this._refreshPageFromAPI();
392-
} else {
393-
if (stagehand.debugDom) {
394-
this.stagehand.log({
395-
category: "deprecation",
396-
message:
397-
"Warning: debugDom is not supported in this version of Stagehand",
398-
level: 1,
399-
});
400-
}
401-
await target.waitForLoadState("domcontentloaded");
402-
await this._waitForSettledDom();
353+
if (this.stagehand.debugDom) {
354+
this.stagehand.log({
355+
category: "deprecation",
356+
message:
357+
"Warning: debugDom is not supported in this version of Stagehand",
358+
level: 1,
359+
});
403360
}
361+
await target.waitForLoadState("domcontentloaded");
362+
await this._waitForSettledDom();
363+
404364
return result;
405365
};
406366
}
@@ -655,7 +615,6 @@ ${scriptContent} \
655615
...observeResult,
656616
frameId: this.rootFrameId,
657617
});
658-
await this._refreshPageFromAPI();
659618
this.stagehand.addToHistory("act", observeResult, result);
660619
return result;
661620
}
@@ -688,7 +647,6 @@ ${scriptContent} \
688647
if (this.api) {
689648
const opts = { ...actionOrOptions, frameId: this.rootFrameId };
690649
const result = await this.api.act(opts);
691-
await this._refreshPageFromAPI();
692650
this.stagehand.addToHistory("act", actionOrOptions, result);
693651
return result;
694652
}

lib/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ export class Stagehand {
616616
this.llmClient = llmClient;
617617
this.logger({
618618
category: "init",
619-
message:
620-
"Custom LLM clients are currently not supported in API mode",
619+
message: "Custom LLM clients are currently not supported in API mode",
621620
level: 1,
622621
});
623622
this.usingAPI = false;

0 commit comments

Comments
 (0)