Skip to content

Commit f49eebd

Browse files
authored
added error thrown on act from a not-supported observe result (#520)
* added error thrown on act from a not-supported observe result * added todo for validation
1 parent 516725f commit f49eebd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: .changeset/selfish-panthers-guess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
Performing act from a 'not-supported' ObserveResult will now throw an informed error

Diff for: lib/handlers/actHandler.ts

+24
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,29 @@ export class StagehandActHandler {
8686
});
8787

8888
const method = observe.method;
89+
if (method === "not-supported") {
90+
this.logger({
91+
category: "action",
92+
message: "Cannot execute ObserveResult with unsupported method",
93+
level: 1,
94+
auxiliary: {
95+
error: {
96+
value:
97+
"NotSupportedError: The method requested in this ObserveResult is not supported by Stagehand.",
98+
type: "string",
99+
},
100+
trace: {
101+
value: `Cannot execute act from ObserveResult with unsupported method: ${method}`,
102+
type: "string",
103+
},
104+
},
105+
});
106+
return {
107+
success: false,
108+
message: `Unable to perform action: The method '${method}' is not supported in ObserveResult. Please use a supported Playwright locator method.`,
109+
action: observe.description || `ObserveResult action (${method})`,
110+
};
111+
}
89112
const args = observe.arguments ?? [];
90113
// remove the xpath prefix on the selector
91114
const selector = observe.selector.replace("xpath=", "");
@@ -168,6 +191,7 @@ export class StagehandActHandler {
168191
* This method will observe the page and then perform the act on the first element returned.
169192
*/
170193
public async observeAct(instruction: string): Promise<ActResult> {
194+
// TODO: Add validation for the supported playwright methods
171195
const observeResults = await this.stagehandPage.observe(
172196
`Find the most relevant element to perform an action on given the following action: ${instruction}.
173197
Provide an action for this element such as ${Object.values(SupportedPlaywrightAction).join(", ")}, or any other playwright locator method. Remember that to users, buttons and links look the same in most cases.

0 commit comments

Comments
 (0)