diff --git a/.changeset/rare-bikes-shake.md b/.changeset/rare-bikes-shake.md new file mode 100644 index 000000000..f8d0bd273 --- /dev/null +++ b/.changeset/rare-bikes-shake.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": patch +--- + +Fix handling possible navigation on cua clicks diff --git a/lib/handlers/agentHandler.ts b/lib/handlers/agentHandler.ts index 4a6c162b2..d0c8a8cec 100644 --- a/lib/handlers/agentHandler.ts +++ b/lib/handlers/agentHandler.ts @@ -12,6 +12,7 @@ import { } from "@/types/agent"; import { Stagehand } from "../index"; import { StagehandFunctionName } from "@/types/stagehand"; +import { handlePossiblePageNavigation } from "./handlerUtils/actHandlerUtils"; export class StagehandAgentHandler { private stagehand: Stagehand; @@ -215,6 +216,13 @@ export class StagehandAgentHandler { await this.page.mouse.click(x as number, y as number, { button: button as "left" | "right", }); + await handlePossiblePageNavigation( + "clicked", + `(coordinates) x:${x}, y:${y}`, + this.page.url(), + this.stagehandPage, + this.logger, + ); return { success: true }; } diff --git a/lib/handlers/handlerUtils/actHandlerUtils.ts b/lib/handlers/handlerUtils/actHandlerUtils.ts index 1c32cf7f9..dcd59f4f1 100644 --- a/lib/handlers/handlerUtils/actHandlerUtils.ts +++ b/lib/handlers/handlerUtils/actHandlerUtils.ts @@ -471,7 +471,7 @@ export async function fallbackLocatorMethod(ctx: MethodHandlerContext) { } } -async function handlePossiblePageNavigation( +export async function handlePossiblePageNavigation( actionDescription: string, xpath: string, initialUrl: string,