From 89546887bd609e25ad3ef4543cf369e18ed31d94 Mon Sep 17 00:00:00 2001 From: linked-danis Date: Thu, 12 Mar 2026 14:09:40 +0100 Subject: [PATCH] fix: type-safe scrollIntoViewIfNeeded Add proper interface for WebKit extension method. Changes: - Add ScrollableElement interface - Use typeof check instead of 'as any' cast --- packages/core/src/PageAgentCore.ts | 6 ++++-- packages/page-controller/src/actions.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/src/PageAgentCore.ts b/packages/core/src/PageAgentCore.ts index c7ab84b..23a6acf 100644 --- a/packages/core/src/PageAgentCore.ts +++ b/packages/core/src/PageAgentCore.ts @@ -511,7 +511,8 @@ export class PageAgentCore extends EventTarget { // Accumulated wait time warning if (this.#states.totalWaitTime >= 3) { this.pushObservation( - `You have waited ${this.#states.totalWaitTime} seconds accumulatively. DO NOT wait any longer unless you have a good reason.` + `You have waited ${this.#states.totalWaitTime} seconds accumulatively. ` + + `DO NOT wait any longer unless you have a good reason.` ) } @@ -527,7 +528,8 @@ export class PageAgentCore extends EventTarget { const remaining = this.config.maxSteps - step if (remaining === 5) { this.pushObservation( - `⚠️ Only ${remaining} steps remaining. Consider wrapping up or calling done with partial results.` + `⚠️ Only ${remaining} steps remaining. ` + + `Consider wrapping up or calling done with partial results.` ) } else if (remaining === 2) { this.pushObservation( diff --git a/packages/page-controller/src/actions.ts b/packages/page-controller/src/actions.ts index 983192f..53b3c6c 100644 --- a/packages/page-controller/src/actions.ts +++ b/packages/page-controller/src/actions.ts @@ -213,14 +213,18 @@ export async function selectOptionElement(selectElement: HTMLSelectElement, opti await waitFor(0.1) // Wait to ensure change event processing completes } +interface ScrollableElement extends HTMLElement { + scrollIntoViewIfNeeded?: (centerIfNeeded?: boolean) => void +} + export async function scrollIntoViewIfNeeded(element: HTMLElement) { - const el = element as any - if (el.scrollIntoViewIfNeeded) { + const el = element as ScrollableElement + if (typeof el.scrollIntoViewIfNeeded === 'function') { el.scrollIntoViewIfNeeded() // await waitFor(0.5) // Animation playback } else { // @todo visibility check - el.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' }) + element.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' }) // await waitFor(0.5) // Animation playback } }