Commit Graph

27 Commits

Author SHA1 Message Date
Saurav Panda c5f0fa767c Fix navigation readiness detection: per-target lifecycle event storage
Navigation waits polled a per-session event deque whose feeding handler was
registered per-session on cdp-use's single-slot event registry. Any later
target attach replaced the handler, freezing existing tabs' deques with only
pre-navigation events, so every navigation on those tabs burned the full
readiness timeout (3s same-domain / 8s cross-domain) and then proceeded on a
page in unknown load state.

- Store lifecycle events per target_id in SessionManager, fed by ONE global
  Page.lifecycleEvent handler registered in start_monitoring() and routed by
  session_id; buffers are freed on target removal
- _navigate_and_wait reads the per-target buffer and now returns a timeout
  status string instead of swallowing readiness timeouts;
  on_NavigateToUrlEvent surfaces it via NavigationCompleteEvent.loading_status
- Skip loaderId-less lifecycle events that predate the current navigation
- Drop unused CDPSession._lifecycle_lock

Deterministic regression test: navigating tab A after opening tab B took
exactly the 3s fallback timeout before this fix, <0.5s after.
2026-07-03 22:48:20 +08:00
Saurav Panda 3b8f2457b1 fix: index elements inside cross-origin iframes reliably 2026-03-21 15:54:35 -07:00
Laith Weinberger 89817de334 Fix proxy auth attach handler overwriting tab tracking 2026-02-26 15:48:38 -05:00
Mert Unsal a742645416 Revert "Improve demo mode" 2025-11-29 13:09:20 -08:00
kalil0321 50bafbd9aa Change log level from info to debug for session data clearing and browser session reset messages 2025-11-18 18:52:43 +01:00
kalil0321 5c41ea9112 implementlogs persistence 2025-11-18 17:30:07 +01:00
reformedot 6c1f772a2d Enhance SessionManager and BrowserSession with defensive checks and connection management
- Added defensive checks in SessionManager to skip target attachment and focus recovery if the browser is shutting down (i.e., _cdp_client_root is None).
- Introduced a connection lock in BrowserSession to prevent concurrent connection attempts, ensuring safe CDP client management.
- Improved logging for session reset and connection handling, providing clearer insights into the browser session state during operations.
- Enhanced error handling when stopping the CDP client and clearing session manager state on initialization failures.

These changes improve the robustness and reliability of session management in the browser environment.
2025-11-14 13:05:18 -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 74775cab9a refactor: update target discovery to include iframe types in session management 2025-11-12 16:12:22 -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 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 c99e1bb41f refactor: improve type checking and linting script
- Updated `pyproject.toml` to enhance type checking configuration by refining the `exclude` list and adding an `include` section for better clarity.
- Modified `lint.sh` to run tools directly from the virtual environment, improving execution reliability and avoiding permission errors.
- Enhanced comments in `lint.sh` for better understanding of script functionality and usage.
2025-11-11 12:00:20 -08:00
reformedot 7a31936f5d refactor: simplify session retrieval methods in SessionManager and BrowserSession
- Changed `get_session_for_target` in `SessionManager` from async to sync, improving performance by removing unnecessary locking.
- Updated all references in `BrowserSession` and related watchdogs to use the new synchronous method for session retrieval.
- Enhanced readability and consistency across session management logic, ensuring a more streamlined approach to handling sessions.
2025-11-10 19:07:01 -08:00
reformedot d39ed5869c fix: ensure target URL is correctly handled in focus change events
- Updated focus change event dispatch in `SessionManager` to use a fallback URL ('about:blank') when the target is not found, preventing potential errors.
- Modified `BrowserSession` to exclude the `session_manager` from serialization, ensuring cleaner data handling.
2025-11-10 14:09:23 -08:00
reformedot 043897c665 refactor: enhance session and target management in SessionManager
- Introduced a new `Target` class to represent browser targets, separating target properties from session management.
- Updated `SessionManager` to maintain a single source of truth for all targets and sessions, improving data integrity.
- Refactored session retrieval methods to ensure consistent access to sessions and targets, enhancing performance and readability.
- Improved logging for session and target operations, providing clearer insights into state changes and actions.
2025-11-10 13:59:43 -08:00
reformedot 0b89bfd7ba feat: add method to retrieve all page sessions and refactor navigation logic
- Introduced `get_all_page_sessions` method in `SessionManager` to fetch all active page/tab sessions.
- Updated `BrowserSession` to utilize the new method for improved navigation and tab management, enhancing performance and readability.
- Refactored related navigation event handling to leverage cached session data instead of direct CDP calls.
2025-11-07 13:09:34 -08:00
reformedot af9123edd4 fix: fixed lifecycle event monitoring 2025-11-07 11:10:23 -08:00
reformedot 984a8c678b feat: enhance session management with target discovery and event handling
- Enabled target discovery to automatically receive targetInfoChanged events, reducing the need for polling.
- Added event handler for targetInfoChanged to update session title and URL dynamically.
- Improved initialization of existing targets to ensure monitoring readiness without race conditions.
- Updated navigation logic to utilize cached session data for faster access to target information.
2025-11-07 10:20:11 -08:00
reformedot 027fae6c23 fix: improved session manager 2025-11-06 21:10:26 -08:00
reformedot 62c0495ef0 fix: enable page monitoring on already existing targets 2025-11-06 17:53:56 -08:00
reformedot 052286e630 feat: improved navigate to URL event logic and wait mechanism 2025-11-06 16:20:51 -08:00
Magnus Müller f8ca1ab3b4 Logs 2025-10-29 23:53:12 -07:00
Magnus Müller 8296e430aa Change logs 2025-10-29 16:14:32 -07:00
reformedot b2b5a260db fix: fixed cubic issues + handle onTabClosed event emission correctly 2025-10-28 18:57:25 -07:00
reformedot 9a0bad39c2 fix: improved session recovery, target type caching & cleaned code 2025-10-28 17:35:04 -07:00
reformedot 3a21ce805d fix: don't focus when generating DOMTree in _get_viewport_ratio 2025-10-26 06:42:10 -07:00
reformedot 54e4dacbf9 feat: improved session manager 2025-10-26 06:05:49 -07:00