/** * cleanWebPageSourceForAI * * Strips non-UI noise from raw HTML so an AI agent can read page structure * and generate XPaths without drowning in scripts, styles, hidden subtrees, * inline base64, or analytics chatter. * * Aggressive trims (NEW-3): * 1. Removes non-UI tags entirely (script, style, link, meta, noscript, * template, svg, canvas). * 2. Removes HTML comments. * 3. Removes hidden subtrees outright (was: marked with special-remark). * 4. Strips `on*` event-handler attributes. * 5. Strips inline `style` attributes after hidden detection. * 6. Strips analytics `data-*` attributes (gtm, ga, segment, track, * analytics). * 7. Replaces base64 data URIs in `src`/`href` with `[base64 N bytes]`. * 8. Truncates text nodes longer than 200 chars. * 9. Recurses into iframe `srcdoc` content (cleans embedded HTML). * * Preserved (intentional, per design): * - Everything outside `` (``, ``, `<html>` attrs). * - All `class` attributes — sometimes the only stable selector. * * Hidden detection covers: `hidden` attr, `aria-hidden="true"`, * `type="hidden"`, inline `display:none`/`visibility:hidden`/`opacity:0`, * and `<dialog>` without an `open` attribute. * * Returns raw HTML unchanged on any parse/serialise error (fail-safe). * * Known limits (out of scope for this cleaner): * - CSS-class-based hiding (external stylesheets, media queries) is * undetectable from raw HTML. Closed dropdowns / modals styled via * `.is-hidden { display:none }` survive cleaning. * - Shadow DOM is not in `getPageSource()` output by default — * Web Components' shadow trees never reach this function. * - Native Android (UIAutomator) / iOS (XCUITest) XML is bypassed * entirely via `isWebPageSource()`. A separate cleaner is needed * to trim deep native layout trees. * - `<svg>` roots are preserved when they carry locator-relevant * attributes (`aria-label` / `role` / `id` / `data-test*`); inner * geometry (`<path>` / `<circle>` / `<g>` / `<title>` etc.) is * stripped either way. Decorative svg with no such attrs is * removed entirely. SVGs with a `<title>` child but no locator * attrs on the root will lose the title — wrap in `<button>` or * hoist the title text to an `aria-label` if you need that surface. * - iframe `srcdoc` recursion is verified synthetically; production * pages using `srcdoc` (sandboxed previews, ad units, Storybook) * are uncommon in our sample. Behavior on real-world srcdoc * content is asserted-by-construction, not measured. */ export interface CleanStats { removedNonUI: number; removedComments: number; removedHiddenSubtrees: number; strippedEventHandlers: number; strippedInlineStyles: number; strippedAnalyticsAttrs: number; base64Replaced: number; truncatedTextNodes: number; iframesRecursed: number; svgsRemoved: number; svgRootsPreserved: number; originalLength: number; cleanedLength: number; } export interface CleanResult { html: string; stats: CleanStats; } export declare function cleanWebPageSourceForAI(html: string): CleanResult; /** * Returns true if the page source looks like web HTML rather than * native Android/iOS XML. */ export declare function isWebPageSource(source: string): boolean; /** * Pretty-print HTML/XML markup for GREPPABILITY: one element per line, indented by * nesting depth, text nodes trimmed onto their own line. Cleaned DOM is often written * as one enormous line (6000+ chars), which makes `grep -A/-B` flood and bounded reads * useless. This is NOT a spec-perfect formatter — it is a robust-enough pass so that * `grep -n "Section"` + a bounded read shows real structure the model can reason over * (e.g. which input sits under which section). Void / self-closing tags don't change * depth; comments and declarations print as-is. Returns the input unchanged when it * isn't markup. */ export declare function prettyPrintHtml(source: string): string; export interface NativeCleanStats { originalLength: number; cleanedLength: number; /** Default-valued boolean attributes removed (focused="false" etc.). */ attrsStripped: number; /** Repeated Android package="…" attributes removed (root keeps the first). */ packageAttrsStripped: number; } export interface NativeCleanResult { xml: string; stats: NativeCleanStats; } export declare function cleanNativeXmlForAI(xml: string): NativeCleanResult;