# @file purpose: Serializes enhanced DOM trees to string format for LLM consumption from typing import Any from browser_use.dom.serializer.clickable_elements import ClickableElementDetector from browser_use.dom.serializer.paint_order import PaintOrderRemover from browser_use.dom.utils import cap_text_length from browser_use.dom.views import ( DOMRect, DOMSelectorMap, EnhancedDOMTreeNode, NodeType, PropagatingBounds, SerializedDOMState, SimplifiedNode, ) DISABLED_ELEMENTS = {'style', 'script', 'head', 'meta', 'link', 'title'} # SVG child elements to skip (decorative only, no interaction value) SVG_ELEMENTS = { 'path', 'rect', 'g', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'use', 'defs', 'clipPath', 'mask', 'pattern', 'image', 'text', 'tspan', } class DOMTreeSerializer: """Serializes enhanced DOM trees to string format.""" # Configuration - elements that propagate bounds to their children PROPAGATING_ELEMENTS = [ {'tag': 'a', 'role': None}, # Any tag {'tag': 'button', 'role': None}, # Any