Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-guests-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

Add level 0 logging when xpath lookup fails in act and observe handlers
8 changes: 8 additions & 0 deletions packages/core/lib/v3/handlers/actHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ function normalizeActInferenceElement(
const xp = xpathMap[elementId as EncodedId];
const trimmed = trimTrailingTextNode(xp);
if (!trimmed) {
v3Logger({
category: "action",
message: `LLM returned ID ${elementId}, there is no xpath keyed by this ID`,
level: 0,
auxiliary: {
elementId: { value: elementId, type: "string" },
},
});
return undefined;
}

Expand Down
12 changes: 11 additions & 1 deletion packages/core/lib/v3/handlers/observeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,17 @@ export class ObserveHandler {
const lookUpIndex = elementId as EncodedId;
const xpath = combinedXpathMap[lookUpIndex];
const trimmedXpath = trimTrailingTextNode(xpath);
if (!trimmedXpath) return undefined;
if (!trimmedXpath) {
v3Logger({
category: "observation",
message: `LLM returned ID ${elementId}, there is no xpath keyed by this ID`,
level: 0,
auxiliary: {
elementId: { value: elementId, type: "string" },
},
});
return undefined;
}

// For dragAndDrop, convert element ID in arguments to xpath (target element)
let resolvedArgs = rest.arguments;
Expand Down
Loading