Visual highlighting system that automatically detects and highlights interactive elements while the AI provides guidanceThe highlighting system is a sophisticated feature that enables the AI agent to visually highlight interactive elements on web pages while providing guidance. It operates through a multi-layered architecture that seamlessly integrates visual guidance with AI conversation.
Overview
The highlighting system provides:- Automatic Element Detection: Continuously scans the DOM for interactive elements
- Proactive Highlighting: Agent highlights elements automatically when providing guidance
- Context-Aware Injection: Injects element information into the AI’s context at strategic moments
- Performance Optimized: Uses caching and debouncing to minimize performance impact
- SPA Support: Handles single-page application navigation seamlessly
Highlighting is disabled by default (
enableHighlighting: false
) and must be explicitly enabled for performance reasons.Quick Start
Enable Highlighting
How It Works
Once enabled, the system automatically:- Detects interactive elements on page load and navigation
- Injects element context into the AI’s knowledge
- Highlights elements when the AI references them in responses
- Updates dynamically as the page changes
Interactive Element Detection
What Gets Detected
The system identifies elements as interactive if they match any of these criteria:- ARIA Roles
- Event Handlers
- Accessibility
Element Descriptions
The system extracts descriptions in this priority order:- Text content (first 50 characters)
aria-label
attributeplaceholder
attribute (for inputs)title
attribute- Fallback: “No text”
Visual Highlighting
Highlight Behavior
When the AI highlights an element, it:- Applies visual styling: Orange border with glow effect
- Scrolls element into view: Ensures visibility
- Auto-removes after 10 seconds: Prevents visual clutter
- Removes on click: Interactive cleanup
AI Integration
Context Injection Format
Interactive elements are automatically injected into the AI’s context in this format:Agent Behavior
The AI is automatically instructed to:- Never announce highlighting (“Let me highlight…”)
- Highlight proactively when mentioning UI elements
- Match descriptions to the injected element list
- Continue naturally after highlighting
The AI will automatically highlight relevant elements as it provides guidance, creating a seamless user experience without explicit highlighting requests.
Configuration
Provider Configuration
Configuration Options
Master switch to enable/disable the highlighting system
Debounce time in milliseconds for element detection to prevent excessive DOM scanning
Interval in milliseconds for periodic element refresh to catch dynamic content changes
Detection Timing
When Elements Are Detected
Initial Load
Immediate detection when WebSocket connection opens
- No debounce delay
- Ensures elements are available for first AI response
Follow-up Detection
1 second after initial to catch late-loading elements
- Captures dynamically loaded content
- Handles async component mounting
Periodic Refresh
Every 6 seconds (configurable) for ongoing changes
- Balances freshness with performance
- Catches new interactive elements
User Interactions
500ms after user clicks to capture DOM changes
- Allows DOM to settle after interaction
- Detects newly appeared elements
Navigation Changes
Immediate on URL change for SPA navigation
- Clears cache for new page
- Fresh detection for new content
Performance Considerations
Optimization Features
- Caching Strategy
- Lazy Initialization
- Debouncing
Performance Metrics
- Initial Detection: ~10-50ms for typical page
- Cached Retrieval: < 1ms
- Context Injection: ~5-10ms
- Visual Highlighting: < 5ms
- Memory Usage: ~50-200KB total
Advanced Usage
Shadow DOM Support
The system automatically traverses Shadow DOM boundaries:Custom Element Integration
Works seamlessly with custom elements and web components:Troubleshooting
Common Issues
Elements Not Being DetectedCheck these common causes:
- Is highlighting enabled in configuration?
- Are elements visible on screen?
- Do elements meet interactive criteria?
- Check browser console for errors
Highlighting Not WorkingVerify these conditions:
- Is the highlight tool registered with the AI?
- Is the element index valid and current?
- Is the element still present in the DOM?
- Check for CSS conflicts with highlight styles
Performance IssuesTry these optimizations:
- Increase
debounceMs
for stable pages - Reduce
refreshInterval
if not needed - Check for DOM mutation loops
- Monitor console logs for excessive scanning
Debug Logging
Enable verbose logging to troubleshoot issues:Best Practices
When to Enable Highlighting
Enable for guided experiences where users need visual assistance navigating interfaces
Enable for complex applications with many interactive elements that benefit from AI guidance
Enable for onboarding flows where highlighting enhances user understanding
Performance Best Practices
- Enable only when needed - Highlighting has computational overhead
- Configure appropriately - Adjust debounce and refresh intervals based on your application
- Monitor performance - Watch console logs for detection timing
- Test thoroughly - Verify highlighting works across different page states
Integration Tips
- Test with dynamic content - Ensure highlighting works with async-loaded elements
- Verify SPA compatibility - Test navigation between different routes/pages
- Check mobile responsiveness - Ensure highlights are visible on mobile devices
- Validate accessibility - Confirm highlighting doesn’t interfere with screen readers
Summary
The highlighting system transforms static AI conversations into interactive, visually-guided experiences. By automatically detecting interactive elements and highlighting them contextually, it creates intuitive user guidance without requiring explicit user requests. Key benefits:- Seamless integration with existing applications
- Performance optimized with extensive caching
- Flexible configuration for different use cases
- Robust architecture that handles edge cases gracefully
- Enhanced user experience through visual guidance
Start with the default configuration and adjust
debounceMs
and refreshInterval
based on your application’s specific needs and performance requirements.