Expand description
CSS selector sanitization for LLM-generated selectors. CSS selector sanitization and validation for LLM-generated selectors.
The LLM sometimes returns garbage instead of a CSS selector (explanations,
JSON objects, :not(*), null, stray quotes or code fences). These
helpers normalize the response and reject values that can never match an
element, so step errors show the LLM’s actual output instead of a cryptic
“element :not(*) not found”.
Functions§
- sanitize_
selector - Strips common LLM response noise from a raw selector string: surrounding whitespace, code fences (with optional language tag), and outer single/double/backtick quotes.
- selector_
is_ useless - Returns
truewhen a sanitized selector can never match a real element, i.e. the LLM clearly did not produce a selector at all. - selector_
matches_ js - Builds the JavaScript snippet that checks whether a selector matches at least one element on the current page.
- validate_
selector - Basic syntactic sanity check for a selector before it is executed.