mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-09 19:27:45 +02:00
[eric] browser: replay clicks scroll-and-retry when off-screen, long names resolve by stable prefix
This commit is contained in:
@@ -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.` };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user