selector-recovery
Skill10 starsChanged 2 months agoApache-2.0View on GitHub
Diagnose and safely recover failed element selectors using fingerprint matching, with hard confidence gates (0.62 threshold, 0.15 margin) that refuse to act on ambiguous matches.
In this repository16 other files it gives its agents.
- browser-forensicsSkill
- browser-interactionSkill
- browser-state-recoverySkill
- dom-inspectionSkill
- dom-mutationSkill
- dom-targetingSkill
- extension-troubleshootingSkill
- human-like-interactionSkill
- mcp-troubleshootingSkill
- page-annotationSkill
- project-captureSkill
- project-reconstructionSkill
- regression-testingSkill
- tab-managementSkill
- viewport-testingSkill
- visual-dom-comparisonSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Before retrying an interaction that failed for targeting reasons.
- Distinctive: line 26
If the selector merely matches multiple elements, tighten it yourself — recovery is not needed.
- Very specific: line 32
Check the safety gates before acting: recovery only succeeds when the best score is ≥ 0.62 AND leads the runner-up by ≥ 0.15 margin.
- Very specific: line 33
If recovered: verify matchedElementInfo (tag/id/text/classes) matches your intent, then use resolvedSelector for the next action.
- Very specific: line 34
If refused: read alternatives + diagnostics (per-component scores and the margin are printed), pick manually, or re-inspect the page and …
- Very specific: line 55
Verify each relaxation in closestWorkingSelectors really matches the intended element before adopting it as the new selector.
- Very specific: line 58
No safe recovery possible: fall back to search_dom on distinctive text, rebuild with generate_element_target, and update the stored …
- Distinctive: line 60
Never lower the gates by retrying until it "happens" to pass — a pass at the same evidence is noise, not confidence.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Skill: Selector Recovery
PURPOSE
Repair broken element references without ever silently acting on a wrong element. The recovery engine matches the previous target's fingerprint evidence against the live DOM, scores candidates, and only resolves above safety gates — otherwise it refuses and hands you diagnostics.
WHEN TO USE
- A selector that worked before now returns TARGET_NOT_FOUND (re-render, framework update, navigation, A/B variant).
- A recorded command, region annotation or reconstruction spec fails to resolve on replay.
- Before retrying an interaction that failed for targeting reasons.
- A regression replay fails at the same step repeatedly — the recorded selector no longer matches the evolved page.
PREREQUISITES
- The failing selector.
- The previous target snapshot evidence:
tag,text,classes,stableAttributes,fingerprintHash,parentSelector,childCount— fromgenerate_element_target, a region annotation, or your earlier inspection. - Live page still loaded (same or re-rendered version) in extension or Node simulation context.
WORKFLOW
diagnose_selector_failure {selector}— establish WHY it fails before touching anything:valid(syntax),matches(0 = gone, >1 = ambiguous),parseError,closestWorkingSelectors(relaxed forms that still match: drop the last compound, keep only the last part, strip:nth-of-type()/volatile classes), and human-readablediagnosissteps.
- If the selector merely matches multiple elements, tighten it yourself — recovery is not needed.
recover_selector {selector, snapshot}— the mandated fingerprint-matching workflow:- verifies the failure (if the selector matches again, it returns
recovered: true, strategy: "original-selector", confidence: 1.0— the earlier failure was a transient navigation/render race); - collects candidates (bounded tag sweep ≤400, stable-class sweep,
[name="…"],parentSelector > tag); - scores each: text 0.30, attributes 0.20, classes 0.20, tag 0.15, childCount 0.05, fingerprint hash 0.10; candidates below 0.35 are dropped;
- top-5 alternatives are returned with fresh selectors and confidences.
- verifies the failure (if the selector matches again, it returns
- Check the safety gates before acting: recovery only succeeds when the best score is ≥ 0.62 AND leads the runner-up by ≥ 0.15 margin. Below either gate the outcome is
recovered: false, strategy: "recovery-refused"— by design, not a bug. - If recovered: verify
matchedElementInfo(tag/id/text/classes) matches your intent, then useresolvedSelectorfor the next action; re-rungenerate_element_targetto refresh the stored snapshot. - If refused: read
alternatives+diagnostics(per-component scores and the margin are printed), pick manually, or re-inspect the page and capture a fresh target.
TOOLS
diagnose_selector_failure, recover_selector, generate_element_target, search_dom, inspect_live_element, get_element_fingerprint
EXAMPLES
tools/call diagnose_selector_failure { "selector": "div.css-1x2y3z > button" }
tools/call recover_selector { "selector": "#old-submit", "snapshot": { "tag": "button", "text": "Sign in", "classes": ["btn", "btn-primary"], "stableAttributes": { "data-testid": "login-submit" }, "parentSelector": "form.login", "childCount": 2 } }FAILURE MODES
- recovery-refused (score < 0.62 or margin < 0.15) — best match is not confident enough or too close to a competing element (e.g. repeated list items). The engine refuses to avoid acting on the wrong element; inspect
alternativesyourself. - No candidates above 0.35 — the region was likely removed or the page structure changed fundamentally; re-inspect and capture a new target.
- Syntax error diagnostics — the selector never parsed; fix the string, recovery scoring is irrelevant.
- Recovery on a re-rendered twin — text/classes match but semantics changed; always sanity-check
matchedElementInfobefore destructive actions.
VALIDATION
recovered: trueoutcomes carryconfidence,strategy: "fingerprint-recovery",resolvedSelectorandmatchedElementInfo— all four must be present and consistent.recovered: true, confidence: 1.0, strategy: "original-selector"means the failure was transient — suspect a navigation race, not a DOM change.- Refusals include the best-candidate score and margin in
diagnostics; use them to decide between manual picking and re-targeting. - Verify each relaxation in
closestWorkingSelectorsreally matches the intended element before adopting it as the new selector.
RECOVERY
- No safe recovery possible: fall back to
search_domon distinctive text, rebuild withgenerate_element_target, and update the stored snapshot/annotation. - Repeated refusals across a page mean systematic churn — recapture the whole project region set rather than patching selectors one by one.
- Never lower the gates by retrying until it "happens" to pass — a pass at the same evidence is noise, not confidence.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

