Commit Graph

54 Commits

Author SHA1 Message Date
Magnus Müller 3042d8c1df Merge branch 'main' into fix/session-handler-registration 2026-09-03 11:03:22 -07:00
Magnus Müller b78b3fcebd Merge branch 'main' into fix/session-handler-registration 2026-09-03 09:00:42 -07:00
Magnus Müller 8043fec5e6 Merge branch 'main' into fix/5569-send-keys-plus 2026-09-02 22:44:36 -07:00
IENVYshanks 2b56dc8f59 test(browser): validate literal plus CDP key events 2026-08-28 23:08:25 +05:30
IENVYshanks 0a6e427c6f fix(browser): support literal plus in send_keys 2026-08-28 11:25:30 +05:30
Faseeh cbc816abb3 test: cover the 'switch event yields no result' failure path
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.
2026-08-20 19:23:54 +05:00
Faseeh c4e314072e address review feedback: preserve real cause via raise_if_any, fix pyright
- 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.
2026-08-19 23:02:33 +05:00
Faseeh c45b850231 fix(tools): report failed tab switches as errors instead of silent success
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.
2026-08-19 22:46:24 +05:00
MagMueller 05b68eb567 test(browser): verify state recovery after timeout 2026-07-24 12:30:06 -07:00
MagMueller e7cc40f5ad fix(browser): expose minimal state after capture timeout 2026-07-24 11:51:16 -07:00
MagMueller fa12474a87 fix(browser): stop reusing cached DOM after state timeout 2026-07-24 10:42:33 -07:00
MagMueller 245cdd8dfc Revert "fix(browser): recover with cached state after timeout"
This reverts commit bd45e4c22a.
2026-07-24 10:38:26 -07:00
MagMueller b7ac967ea5 Revert "fix(browser): bound cached state recovery attempts"
This reverts commit 394ccc157e.
2026-07-24 10:38:26 -07:00
MagMueller 394ccc157e fix(browser): bound cached state recovery attempts 2026-07-23 21:59:58 -07:00
MagMueller bd45e4c22a fix(browser): recover with cached state after timeout 2026-07-23 21:59:58 -07:00
MagMueller 7f22c5a7b4 fix(browser): preserve DOM when state screenshots stall 2026-07-23 21:59:58 -07:00
MagMueller 9a0399a30f style: order DOM regression test imports 2026-07-23 21:59:58 -07:00
MagMueller ce0fc1b99b fix(dom): preserve structural state when AX tree fails 2026-07-23 21:59:58 -07:00
MagMueller 9bf7feffb6 fix(dom): bound JS listener CDP fanout 2026-07-23 21:59:58 -07:00
MagMueller 5a4b02c4bd Keep selector indices unique across CDP sessions 2026-07-23 15:44:03 -07:00
MagMueller 2110918289 Scope paint-order filtering by iframe document 2026-07-23 15:36:26 -07:00
MagMueller 167f0c94d5 Scope DOM clickability cache by CDP session 2026-07-23 14:26:12 -07:00
lisa0314 554ce8f99e Restore session handlers after event bus reset 2026-07-15 10:07:05 +08:00
Saurav Panda b4b6868232 Handle same-document navigations without burning the readiness timeout
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.
2026-07-04 04:27:18 +08:00
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 ae52ce8dcd fix: satisfy pyright in profile copy test 2026-05-09 11:40:51 -07:00
duyua9 e89f3aaae2 fix: handle locked Chrome profile copies 2026-05-09 23:17:17 +08:00
Saurav Panda 44e7b1f082 fix(tests): patch TimeoutWrappedCDPClient at its new construction site
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__.
2026-04-20 17:45:35 -07:00
Alezander9 f8f7be2e90 Fix test assertions to match updated error messages 2026-04-08 22:12:16 -07:00
reformedot ad41865559 Refactor User-Agent assertion in CDP headers test
- 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.
2026-03-20 00:47:59 -07:00
reformedot f64f587d09 Enhance header validation in CDP client tests
- 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.
2026-03-20 00:43:15 -07:00
Saurav Panda e50588f3c7 fixed styling issues 2026-02-23 15:24:40 -08:00
Saurav Panda 6713afc636 updated _navigate_and_wait 2026-02-21 19:45:54 -08:00
Mert Unsal a048d97eab Merge branch 'main' into attempt-fix-real-browser 2025-11-26 13:22:22 -08:00
mertunsall ad1c9b070e fix 2025-11-26 10:33:06 -08:00
kalil0321 73f4138b10 Merge branch 'main' into attempt-fix-real-browser 2025-11-16 11:58:58 +01:00
reformedot 97deba7bb8 refactor: update agent focus handling and CDP session retrieval to fix tests 2025-11-11 12:57:35 -08:00
kalil0321 680c71bdec Merge branch 'main' into attempt-fix-real-browser 2025-11-03 16:21:58 +01:00
Gregor Žunič 9c88c5a828 better cloud params 2025-10-30 13:05:41 -07:00
Magnus Müller 1655751f8a Add test for true cross-origin iframe element clicking
- 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.
2025-10-27 17:26:02 -07:00
Magnus Müller c3db6cff02 Refactor cross-origin iframe handling in tests and serializer
- 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.
2025-10-27 17:19:03 -07:00
Magnus Müller f3c7070506 Refactor cross-origin iframe click test for improved clarity and functionality
- 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.
2025-10-27 17:14:30 -07:00
Magnus Müller c886eacb42 Increase wait time for cross-origin iframe loading in tests
- 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.
2025-10-27 00:06:29 -07:00
Magnus Müller 3ad835a311 Linter 2025-10-27 00:00:32 -07:00
Magnus Müller 7c61bd4908 Add test for clicking elements inside cross-origin iframes
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>
2025-10-26 23:56:23 -07:00
Magnus Müller 04e987df99 Add stacked DOM elements test for complex scenarios
- 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.
2025-10-26 23:16:06 -07:00
Magnus Müller 4258546098 Add DOM serializer test templates and improve logging
- 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.
2025-10-26 22:44:42 -07:00
Magnus Müller adcac19259 Fix test to properly check for click failures
- 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>
2025-10-26 21:39:15 -07:00
Magnus Müller f09df1a326 Add DOM serializer test with shadow DOM, iframes, and click functionality
- 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>
2025-10-26 17:34:50 -07:00
Magnus Müller f57a350098 Add integration tests for screenshot functionality in the agent with vision enabled. This includes setting up a mock HTTP server for testing, capturing screenshots during navigation, and verifying the existence and content of the captured screenshots in the agent's history. 2025-10-26 17:12:11 -07:00