Reviewer feedback noted the second fixed failure branch (a SwitchTabEvent
that completes without raising but yields no TargetID) had no dedicated
coverage. Adds a test using the same event_bus.dispatch monkeypatch
pattern already used elsewhere in this test suite.
- event_result(raise_if_any=True) so a SwitchTabEvent handler failure
surfaces its actual cause through the except block instead of
becoming a generic 'produced no result' message (only one handler
is ever registered for SwitchTabEvent, so this is safe).
- Test file used a dynamically-built ActionModel that pyright can't
see the fields of; switched to a statically declared _TabActionModel
subclass, matching the pattern used elsewhere in this file.
switch() returned a non-error ActionResult on both of its failure paths
(a stale/unknown tab_id, and a SwitchTabEvent that produced no result),
so callers had no way to tell a failed switch from a real one. The false
'Switched to tab #...' claim was written into long_term_memory, so
subsequent agent steps reasoned from a tab that was never actually
reached.
Raise BrowserError on both failure paths instead, following the same
convention upload_file already uses in this file. The error message
preserves the actual underlying cause instead of a generic string, so
ActionResult.error carries actionable information back to the agent.
Adds regression tests covering the failing tab_id case and confirming
the happy path is unaffected.
Page.navigate omits loaderId for same-document navigations (#fragment,
History API), and Chrome emits no new load/DOMContentLoaded lifecycle events
for them — the navigation is already committed when Page.navigate returns.
The stale-event timestamp guard would otherwise reject all buffered events
and burn the full readiness timeout.
Short-circuit when loaderId is absent, and simplify the stale-event guard
(the no-navigation-id case can no longer reach it). Regression test drains
the previous load's trailing networkIdle first so a stale event can't
accidentally satisfy the wait.
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.
Earlier commit 9a09c4d7 swapped the CDPClient construction in
browser_use/browser/session.py from the raw cdp_use.CDPClient to our
TimeoutWrappedCDPClient subclass. test_cdp_headers.py patches the
CDPClient symbol in session.py's namespace to assert headers/User-Agent
propagate — but since the code now instantiates TimeoutWrappedCDPClient,
the patch no longer intercepts the call and the mock.assert_called_once
check fails with 'Called 0 times'.
Point the patches at session.TimeoutWrappedCDPClient instead so the
assertions match what the code actually constructs. Header propagation
still works end-to-end because TimeoutWrappedCDPClient forwards
*args/**kwargs to super().__init__.
- Updated the assertion for the User-Agent header in the /json/version endpoint test to improve readability by using a multi-line format.
- This change enhances the clarity of the test's intent while maintaining the existing validation logic.
These modifications contribute to better maintainability of the test code.
- Improved assertions in tests to ensure all user-provided headers are present in the additional_headers.
- Added checks to confirm that the User-Agent header is injected for remote connections, ensuring consistent behavior across tests.
- Updated the test for the /json/version endpoint to validate the presence and format of the User-Agent header.
These changes enhance the reliability of header handling in the CDP client tests.
- Introduced a new test to verify the ability to click elements inside true cross-origin iframes, specifically targeting external domains like example.com.
- Implemented a fixture to create a browser session with cross-origin iframe support, enhancing the test's reliability and clarity.
- The test checks for the presence of elements from different CDP targets and ensures that at least one element from the cross-origin iframe can be successfully clicked.
This addition aims to improve the coverage of cross-origin iframe interactions in the browser automation framework, ensuring robust functionality in real-world scenarios.
- Updated the DOMTreeSerializer to remove debug code related to cross-origin iframe detection, enhancing clarity and maintainability.
- Adjusted test cases to replace the cross-origin iframe source with a placeholder (about:blank) for improved test isolation and reliability.
- Updated comments and descriptions in tests to reflect the changes in iframe handling, ensuring accurate documentation of test behavior.
This change aims to streamline the handling of cross-origin iframes in both the serializer and tests, improving overall robustness and maintainability.
- Updated test to verify clicking elements inside iframes in different CDP targets, enhancing the description for better understanding.
- Replaced the previous cross-origin iframe setup with a more controlled iframe content for testing.
- Adjusted assertions to ensure at least one element from the iframe is found, improving test reliability.
- Cleaned up comments and print statements for clarity, ensuring the test accurately reflects its purpose.
This change aims to enhance the robustness and maintainability of tests involving iframe interactions in the browser automation framework.
- Updated the sleep duration from 3 to 5 seconds to accommodate potential network delays in CI environments.
- Enhanced the comment to clarify that cross-origin iframe extraction is enabled when getting the DOM state.
This change aims to improve the reliability of tests involving cross-origin iframes by allowing sufficient time for them to load before interaction.
Verifies that:
- Cross-origin iframe DOM extraction works (finds multiple CDP targets)
- Elements from cross-origin iframes appear in the selector_map
- Elements inside cross-origin iframes can be clicked successfully
- Target/session switching works correctly for cross-origin actions
The test uses example.com as the cross-origin iframe source and
clicks the "Learn more" link inside the iframe to verify end-to-end
functionality.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Introduced a new HTML template for testing stacked DOM elements, including open and closed shadow DOMs, same-origin and cross-origin iframes, and a final button.
- Implemented a test case to validate click functionality through these stacked elements, ensuring that all interactive elements are clickable and that the click counter reflects the expected number of clicks.
- Enhanced the browser session configuration to accommodate a taller window size for better visibility of stacked elements.
This update aims to improve the robustness of DOM interaction tests and ensure comprehensive coverage of complex scenarios in the browser automation framework.
- Introduced new HTML templates for DOM serializer tests, including a main page and an iframe template.
- Enhanced logging in the BrowserSession to provide clearer insights when fetching the CDP client for target nodes, improving traceability during debugging.
- Updated tests to utilize the new HTML templates, ensuring better structure and maintainability.
This update aims to enhance the robustness of the DOM serializer tests and improve error handling in session management.
- Added check for failure messages in extracted_content
- Now catches both error field and 'not available'/'failed' in content
- Test will now fail in CI as expected, revealing click issues
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Tests DOM serializer extracts elements from:
- Regular DOM (buttons, inputs, links)
- Shadow DOM (elements inside shadow roots)
- Same-origin iframes
- Cross-origin iframes
- Tests clicking elements using tools.click(index) for each category
- Test fails if clicks don't work (currently failing - needs fix)
- Verifies 12 total interactive elements are found
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>