Commit Graph

166 Commits

Author SHA1 Message Date
Laith Weinberger 9ad4c63cdb fix pagination classifier to prioritize semantic labels over shared glyph symbols 2026-04-11 18:30:46 -04:00
MagMueller e600b70d45 fix: reuse querySelectorAll result to avoid duplicate DOM traversal 2026-04-01 16:55:52 -07:00
MagMueller d2aab6b495 fix: address review comments (StopIteration, isClickable semantics) 2026-04-01 16:45:34 -07:00
MagMueller 163575d9d7 style: fix lint (unused import, redundant parens) 2026-04-01 16:24:17 -07:00
MagMueller 89d82689d8 perf: fix O(n²) bottlenecks in DOM capture for heavy pages
Three targeted fixes for pages with 5k+ elements:

1. build_snapshot_lookup: convert isClickable list to set before loop
   _parse_rare_boolean_data used `index in list` (O(n) per call).
   Called once per node = O(n²). Now O(1) via set lookup.
   20k elements: 14,160ms → 2,973ms. 100k: 356s → 9s.

2. RectUnionPure: add _MAX_RECTS=5000 safety cap
   Paint order rect union fragments exponentially with overlapping
   layers. Uncapped, 20k elements took 372s. Capped: 4.7s.
   Degrades gracefully (less aggressive filtering, same correctness).

3. Skip JS listener detection on pages with >10k elements
   querySelectorAll('*') + per-element DOM.describeNode took 2.3s at 20k.
   Elements still detected via accessibility tree + heuristics.

Combined effect at 20k elements: ~400s → ~16s (25x faster).
Normal pages (<5k elements) are completely unaffected.
2026-04-01 16:21:33 -07:00
MagMueller 5ec5c8d43a perf: hoist CDP session lookup + cap paint order rect explosion
Two additional performance fixes for heavy pages:

1. Hoist get_or_create_cdp_session() outside _construct_enhanced_node
   Previously called once PER DOM NODE inside the recursive tree
   construction. On a 100k-element page, this was 100k+ async
   operations. Now resolved once before recursion starts.

2. Add _MAX_RECTS=5000 safety cap to RectUnionPure
   The paint order rect union can fragment exponentially with many
   overlapping translucent layers (each add() splits up to 4 rects).
   Cap prevents memory/CPU explosion on complex pages.

Also: expanded stress test suite to 15 pages (up to 132k elements)
including shadow DOM + iframe combos, overlapping layers, cross-origin
iframes, and a 100k flat element test. All 15 pass.
2026-04-01 12:25:10 -07:00
MagMueller 683994da8e fix: prevent DOM capture timeout on heavy pages (20k+ elements)
Pages with very large DOMs (e.g. Stimulsoft designer with 20,000+
elements) cause the browser state capture to time out, making the
agent unable to interact with the browser.

Three targeted fixes:

1. Skip JS listener detection on heavy pages (>10k elements)
   The querySelectorAll('*') + getEventListeners() loop followed by
   individual DOM.describeNode CDP calls for each listener element is
   O(n) and can take 10s+ alone on heavy pages.

2. Batch DOM.describeNode calls (chunks of 50)
   Previously all calls fired at once via asyncio.gather, flooding the
   CDP WebSocket and causing timeouts on concurrent operations.

3. Adaptive CDP timeouts based on page complexity
   - >15k elements: 25s initial / 10s retry (was 10s/2s)
   - >5k elements: 15s initial / 5s retry
   - Normal pages: unchanged 10s/2s
2026-04-01 11:25:03 -07:00
Saurav Panda 3b8f2457b1 fix: index elements inside cross-origin iframes reliably 2026-03-21 15:54:35 -07:00
Laith Weinberger 5b9371ee30 use existing clickable element detector 2026-01-26 17:21:38 -05:00
Laith Weinberger f3f82689dd fix docstring incorrectly referencing y_position instead of pages + show generic hint 2026-01-25 13:19:30 -05:00
Laith Weinberger 9027991bae when detecting iframe elements, tell LLM exactly how far to scroll to reach each
Get pixel location of each iframe element that's out of the viewport, convert from pixels to number of page lengths, and provide that to the LLM as context
2026-01-25 13:11:37 -05:00
Laith Weinberger 230a60d6c5 lint 2026-01-25 12:29:29 -05:00
Laith Weinberger eb8e1c1d59 fix(#3619): add hidden content hints for iframes in DOM context
Elements in iframes beyond the 1000px viewport threshold are filtered from selector_map, causing agents to scroll blindly to find them. Add hints to the LLM context indicating hidden content
2026-01-25 12:19:57 -05:00
Laith Weinberger 1794849886 don't mutate page
instead of writing markers to DOM, collect element references in JS, resolve them to internal Chrome node IDs via CDP, and store those IDs in Python
2026-01-24 16:36:14 -05:00
Laith Weinberger 20f51c7fef detect JS event listeners for clickable elements
uses CDP Runtime.evaluate with includeCommandLineAPI to access getEventListeners() and mark elements with click/mousedown/pointerdown listeners before DOM snapshot capture
2026-01-24 14:44:08 -05:00
Saurav Panda 07b7a6d8c0 fix: include shadow DOM form elements in selector_map even without snapshot data 2025-12-19 18:32:40 -08:00
kalil0321 1c85a8a688 Fix lint 2025-11-13 15:49:43 +01:00
kalil0321 0988199776 Merge branch 'main' into kalil0321/demo-mode 2025-11-13 15:34:49 +01:00
reformedot 13868aee9b refactor: update all_frames parameter handling in DomService
- Changed the type of the all_frames parameter to allow for None, enabling lazy fetching of cross-origin iframes only when necessary.
- Updated comments to clarify the behavior of all_frames during DOM tree construction.
2025-11-12 20:05:01 -08:00
reformedot 77d7f161fb refactor: enhance session management and error handling in BrowserSession
- Improved the `create_task_with_error_handling` function to allow for better exception logging and retrieval based on the `suppress_exceptions` parameter.
- Updated `SessionManager` to implement event-driven recovery for stale agent focus, replacing polling with efficient event handling.
- Refactored session retrieval methods to ensure focus validation and recovery are handled automatically.
- Enhanced logging for recovery processes and session management to provide clearer insights into state changes and errors.
- Adjusted various watchdogs to utilize the new session management methods, ensuring they correctly handle focus validation and session retrieval.
2025-11-12 19:42:24 -08:00
reformedot bff596f2e7 refactor: remove target type caching and streamline target retrieval in session management
- Eliminated the caching of target types in SessionManager, simplifying the management of target information.
- Updated various components to directly access target types from the Target objects, enhancing clarity and reducing redundancy.
- Adjusted related methods in BrowserSession, CrashWatchdog, and DomService to reflect the changes in target type retrieval.
2025-11-12 15:19:34 -08:00
reformedot 6859920d68 refactor: enhance timing breakdown in DOMWatchdog and DomService for improved performance insights
- Updated DOMWatchdog to provide a detailed hierarchical breakdown of timing metrics for various operations, improving clarity in performance logging.
- Enhanced DomService to calculate and log specific timing metrics for iframe scrolling, CDP calls, and snapshot processing, contributing to more accurate performance tracking.
2025-11-11 20:38:39 -08:00
reformedot 44045765b5 refactor: improve timing metrics in DOMWatchdog and DomService for enhanced performance tracking
- Updated DOMWatchdog to exclude specific sub-timings from total tracked time to avoid double-counting.
- Enhanced DomService to calculate and log overhead timings for both get_dom_tree and get_serialized_dom_tree operations, improving accuracy in performance metrics.
2025-11-11 20:12:52 -08:00
reformedot e766733ef4 refactor: enhance timing metrics in DomService for improved performance tracking 2025-11-11 19:51:54 -08:00
reformedot b4e9ffa984 refactor: implement error handling for asyncio tasks across various components
- Introduced a utility function `create_task_with_error_handling` to manage asyncio tasks with proper exception logging and suppression options.
- Updated multiple components, including `SessionManager`, `BrowserSession`, and various watchdogs, to utilize the new error handling mechanism for background tasks.
- Enhanced overall robustness of asynchronous operations by ensuring exceptions are logged and handled appropriately, improving maintainability and debugging capabilities.
2025-11-11 17:27:54 -08:00
reformedot 0282675ade refactor: implement lazy fetching for DOM tree construction
- Updated DOM tree retrieval methods to lazily fetch frame hierarchy only when necessary, improving performance for pages without cross-origin iframes.
- Adjusted method signatures to reflect optional frame fetching, enhancing flexibility in DOM service operations.
- Streamlined timing metrics by setting placeholders for timing logs, preparing for future performance enhancements.
2025-11-10 21:28:10 -08:00
reformedot 97420238c1 refactor: enhance DOM tree construction and timing metrics
- Updated DOM tree retrieval methods to include pre-fetched frame hierarchy, reducing redundant CDP calls and improving performance.
- Adjusted timing logs to provide detailed breakdowns of DOM tree construction, including total time and individual component timings.
- Removed commented-out code related to Python-based highlighting, streamlining the DOMWatchdog class.
- Reduced wait time in DOMWatchdog for page stability, enhancing responsiveness during DOM builds.
2025-11-10 20:53:23 -08:00
reformedot bf350bc4b0 refactor: update agent focus handling to use target ID consistently
- Replaced instances of `agent_focus` with `agent_focus_target_id` across various components to ensure consistent target management.
- Enhanced error handling and logging in `Watchdog` classes to reflect the new target ID approach.
- Improved session retrieval methods to streamline interactions with the `SessionManager`, ensuring better performance and reliability.
2025-11-10 14:29:50 -08:00
kalil0321 3f64178894 Implement demo mode for in-browser logging 2025-11-08 21:39:57 +01:00
reformedot 3a21ce805d fix: don't focus when generating DOMTree in _get_viewport_ratio 2025-10-26 06:42:10 -07:00
Magnus Müller b678f27a3e Migration from highlight index to backendnode id 2025-10-21 21:02:28 -07:00
Magnus Müller 9caa248316 Merge code7 branch changes 2025-10-21 18:55:54 -07:00
Magnus Müller 730019471d Fix: filter shadow roots from children nodes, ensuring clean separation in the DOM tree structure. Update EnhancedDOMTreeNode to make a copy of children_nodes to prevent mutation of the original list. 2025-10-13 19:36:13 -07:00
Magnus Müller 7e2d4de32c Timing 2025-09-19 19:36:53 -07:00
Magnus Müller c1ea8ffa36 Adjust intersection logic in DomService to extend vertical bounds by 1000 pixels for improved frame detection. 2025-09-18 17:26:49 -07:00
Magnus Müller 90e27e07d1 Works 2025-09-18 11:10:57 -07:00
Magnus Müller 661bb46b9e Increase default 2025-09-08 08:28:39 -07:00
Magnus Müller dc0c18f55d linter 2025-09-08 08:18:47 -07:00
Magnus Müller 700910126a make iframe depth variable 2025-09-08 08:17:15 -07:00
Gregor Žunič 05408613b9 Merge branch 'main' into feature/paint-order-filtering 2025-09-07 21:07:19 -07:00
Gregor Žunič c2eede8e20 paint order filtering 2025-09-07 20:56:48 -07:00
Magnus Müller 016a1709de Refactor iframe dimension retrieval in DomService
- Updated the method of accessing iframe dimensions from dictionary-style to attribute-style for improved clarity and consistency.
- Ensured that width and height are directly accessed as properties of the bounds object.
2025-09-06 12:44:34 -07:00
Magnus Müller ff27735392 Refactor logging statements in DomService for improved readability
- Updated logging statements to use multi-line formatting for better clarity.
- Ensured consistent spacing and formatting throughout the service to enhance code maintainability.
2025-09-06 12:39:02 -07:00
Magnus Müller 66fc319938 Merge commit 'af5b4400cd31644d06590ce5bcd0c19ac4ef35dd' into iframe-limits 2025-09-06 12:36:26 -07:00
Gregor Žunič 3d8e00f0b0 added FRAME to everywhere where we have IFRAME 2025-08-29 21:04:50 -07:00
Nick Sweeting e725edb62a cross-origin iframes on by default with depth limits 2025-08-22 19:42:18 -07:00
Nick Sweeting 4c93f39a49 cleanup test file naming 2025-08-22 16:06:47 -07:00
Nick Sweeting 5668ab3f9b move cross-origin iframe option to instance attr instead of hardcoded global 2025-08-22 16:05:17 -07:00
Magnus Müller 6cc2f8c5fb remove specific city logs 2025-08-18 23:07:26 -07:00
Nick Sweeting 76512fbfdd fix Failed to build DOM tree: cannot reuse already awaited coroutine 2025-08-16 17:58:45 -07:00