diff --git a/.changeset/six-lies-lie.md b/.changeset/six-lies-lie.md new file mode 100644 index 000000000..ecf06afb3 --- /dev/null +++ b/.changeset/six-lies-lie.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": patch +--- + +rm unused handlePossiblePageNavigation diff --git a/lib/handlers/actHandler.ts b/lib/handlers/actHandler.ts index 5241e8756..83174403a 100644 --- a/lib/handlers/actHandler.ts +++ b/lib/handlers/actHandler.ts @@ -1,4 +1,4 @@ -import { Locator, Page } from "@playwright/test"; +import { Locator } from "@playwright/test"; import { LogLine } from "../../types/log"; import { PlaywrightCommandException, @@ -495,110 +495,6 @@ export class StagehandActHandler { }); } - private async handlePossiblePageNavigation( - actionDescription: string, - xpath: string, - initialUrl: string, - domSettleTimeoutMs: number, - ): Promise { - // 1) Log that we’re about to check for page navigation - this.logger({ - category: "action", - message: `${actionDescription}, checking for page navigation`, - level: 1, - auxiliary: { - xpath: { - value: xpath, - type: "string", - }, - }, - }); - - // 2) Race against a new page opening in a tab or timing out - const newOpenedTab = await Promise.race([ - new Promise((resolve) => { - // TODO: This is a hack to get the new page. - // We should find a better way to do this. - this.stagehandPage.context.once("page", (page) => resolve(page)); - setTimeout(() => resolve(null), 1_500); - }), - ]); - - // 3) Log whether a new tab was opened - this.logger({ - category: "action", - message: `${actionDescription} complete`, - level: 1, - auxiliary: { - newOpenedTab: { - value: newOpenedTab ? "opened a new tab" : "no new tabs opened", - type: "string", - }, - }, - }); - - // 4) If new page opened in new tab, close the tab, then navigate our main page - if (newOpenedTab) { - this.logger({ - category: "action", - message: "new page detected (new tab) with URL", - level: 1, - auxiliary: { - url: { - value: newOpenedTab.url(), - type: "string", - }, - }, - }); - await newOpenedTab.close(); - await this.stagehandPage.page.goto(newOpenedTab.url()); - await this.stagehandPage.page.waitForLoadState("domcontentloaded"); - } - - // 5) Wait for the DOM to settle - await this.stagehandPage - ._waitForSettledDom(domSettleTimeoutMs) - .catch((e) => { - this.logger({ - category: "action", - message: "wait for settled DOM timeout hit", - level: 1, - auxiliary: { - trace: { - value: e.stack, - type: "string", - }, - message: { - value: e.message, - type: "string", - }, - }, - }); - }); - - // 6) Log that we finished waiting for possible navigation - this.logger({ - category: "action", - message: "finished waiting for (possible) page navigation", - level: 1, - }); - - // 7) If URL changed from initial, log the new URL - if (this.stagehandPage.page.url() !== initialUrl) { - this.logger({ - category: "action", - message: "new page detected with URL", - level: 1, - auxiliary: { - url: { - value: this.stagehandPage.page.url(), - type: "string", - }, - }, - }); - } - } - public async act({ action, steps = "",