diff --git a/.changeset/breezy-phones-happen.md b/.changeset/breezy-phones-happen.md new file mode 100644 index 000000000..f90efa52c --- /dev/null +++ b/.changeset/breezy-phones-happen.md @@ -0,0 +1,5 @@ +--- +"@browserbasehq/stagehand": patch +--- + +allow act() to call hover() diff --git a/packages/core/lib/v3/handlers/handlerUtils/actHandlerUtils.ts b/packages/core/lib/v3/handlers/handlerUtils/actHandlerUtils.ts index 98d371119..7a8ffb9a3 100644 --- a/packages/core/lib/v3/handlers/handlerUtils/actHandlerUtils.ts +++ b/packages/core/lib/v3/handlers/handlerUtils/actHandlerUtils.ts @@ -144,6 +144,7 @@ const METHOD_HANDLER_MAP: Record< prevChunk: scrollToPreviousChunk, selectOptionFromDropdown: selectOption, selectOption: selectOption, + hover: hover, }; export async function selectOption(ctx: UnderstudyMethodHandlerContext) { @@ -492,6 +493,25 @@ async function scrollByElementHeight( } } +export async function hover(ctx: UnderstudyMethodHandlerContext) { + const { locator, xpath } = ctx; + try { + await locator.hover(); + } catch (e) { + v3Logger({ + category: "action", + message: "error attempting to hover", + level: 0, + auxiliary: { + error: { value: e.message, type: "string" }, + trace: { value: e.stack, type: "string" }, + xpath: { value: xpath, type: "string" }, + }, + }); + throw new UnderstudyCommandException(e.message); + } +} + /* ===================== Helpers ===================== */ async function getFrameUrl(frame: Frame): Promise { diff --git a/packages/core/lib/v3/types/private/handlers.ts b/packages/core/lib/v3/types/private/handlers.ts index 72cba746c..df58577d4 100644 --- a/packages/core/lib/v3/types/private/handlers.ts +++ b/packages/core/lib/v3/types/private/handlers.ts @@ -37,4 +37,5 @@ export enum SupportedPlaywrightAction { NEXT_CHUNK = "nextChunk", PREV_CHUNK = "prevChunk", SELECT_OPTION_FROM_DROPDOWN = "selectOptionFromDropdown", + HOVER = "hover", }