Skip to content

Commit e483484

Browse files
pass observeHandler into actHandler (#594)
* pass observeHandler into actHandler * changeset
1 parent 53889d4 commit e483484

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

Diff for: .changeset/cool-lemons-report.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
pass observeHandler into actHandler

Diff for: lib/StagehandPage.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,12 @@ export class StagehandPage {
510510
: this.llmClient;
511511

512512
if (!slowDomBasedAct) {
513-
return this.actHandler.observeAct(actionOrOptions);
513+
return this.actHandler.observeAct(
514+
actionOrOptions,
515+
this.observeHandler,
516+
llmClient,
517+
requestId,
518+
);
514519
}
515520

516521
this.stagehand.log({

Diff for: lib/handlers/actHandler.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
fallbackLocatorMethod,
2626
} from "./handlerUtils/actHandlerUtils";
2727
import { Stagehand } from "@/lib";
28+
import { StagehandObserveHandler } from "@/lib/handlers/observeHandler";
2829
/**
2930
* NOTE: Vision support has been removed from this version of Stagehand.
3031
* If useVision or verifierUseVision is set to true, a warning is logged and
@@ -211,8 +212,13 @@ export class StagehandActHandler {
211212
* Perform an act based on an instruction.
212213
* This method will observe the page and then perform the act on the first element returned.
213214
*/
214-
public async observeAct(actionOrOptions: ActOptions): Promise<ActResult> {
215-
// Extract action string and observe options
215+
public async observeAct(
216+
actionOrOptions: ActOptions,
217+
observeHandler: StagehandObserveHandler,
218+
llmClient: LLMClient,
219+
requestId: string,
220+
): Promise<ActResult> {
221+
// Extract the action string
216222
let action: string;
217223
const observeOptions: Partial<ObserveOptions> = {};
218224

@@ -251,9 +257,13 @@ export class StagehandActHandler {
251257
);
252258

253259
// Call observe with the instruction and extracted options
254-
const observeResults = await this.stagehandPage.observe({
260+
const observeResults = await observeHandler.observe({
255261
instruction,
256-
...observeOptions,
262+
llmClient: llmClient,
263+
requestId,
264+
onlyVisible: false,
265+
drawOverlay: false,
266+
returnAction: true,
257267
});
258268

259269
if (observeResults.length === 0) {
@@ -265,7 +275,7 @@ export class StagehandActHandler {
265275
}
266276

267277
// Perform the action on the first observed element
268-
const element = observeResults[0];
278+
const element: ObserveResult = observeResults[0];
269279
// Replace the arguments with the variables if any
270280
if (actionOrOptions.variables) {
271281
Object.keys(actionOrOptions.variables).forEach((key) => {

0 commit comments

Comments
 (0)