[eric] browser: replay clicks scroll-and-retry when off-screen, long names resolve by stable prefix

This commit is contained in:
ciregenz
2026-06-05 17:21:50 -07:00
parent e010a40b50
commit 1480fddf51
2 changed files with 23 additions and 3 deletions
+8 -1
View File
@@ -937,9 +937,16 @@ async function handleClickByName(wv: BrowserWebview, params: Record<string, any>
}
const norm = (s: string) => s.trim().toLowerCase();
// Exact (role,name) first, then name-only, so we click the most specific match.
// Long names are card blobs whose SUFFIX mutates between visits (feed snippets,
// counters) while the prefix stays stable; fall back to a 40-char prefix match
// so a replayed click survives the churn.
const wantPrefix = norm(wantName).slice(0, 40);
const match =
candidates.find((c) => (!wantRole || norm(c.role) === norm(wantRole)) && norm(c.name) === norm(wantName)) ||
candidates.find((c) => norm(c.name) === norm(wantName));
candidates.find((c) => norm(c.name) === norm(wantName)) ||
(wantName.length > 40
? candidates.find((c) => (!wantRole || norm(c.role) === norm(wantRole)) && norm(c.name).startsWith(wantPrefix))
: undefined);
if (!match) {
return { error: `No element matching role="${wantRole}" name="${wantName}" on this page.` };
}