Skip to content

Conversation

@dinmukhamedm
Copy link
Member

@dinmukhamedm dinmukhamedm commented Oct 23, 2025

  • Fix browser-use cdp
  • Verify browser-use cdp
  • Check if raw playwright has the same issue
  • if needed, fix raw playwright

Note

Adds a background asyncio loop to send browser events without blocking and refactors Playwright/Patchright/browser-use session instrumentation to use AsyncLaminarClient only.

  • Browser event delivery (core change):
    • Adds lmnr/sdk/browser/background_send_events.py with a dedicated background asyncio loop, future tracking, and graceful atexit shutdown.
    • Routes all browser event sends via asyncio.run_coroutine_threadsafe(...) and track_async_send(...) to avoid blocking.
  • Integration:
    • cdp_utils.py and pw_utils.py: wire background loop; reassemble/chunk events and submit sends in the background; convert exposed bindings to async-safe handlers; add create_task usage in CDP path.
    • Improve recorder injection robustness (check page.is_closed()), and switch to get_default_logger with quieter debug logs.
  • Instrumentation refactor:
    • PlaywrightInstrumentor and PatchrightInstrumentor now accept only AsyncLaminarClient; wrappers for sync/async paths use the async client.
    • _instrument_initializers.py and instruments.py: initializers updated to require async_client; init calls pass only async_client.
  • Recorder JS tweaks:
    • JS injectors: minor heartbeat/param fixes, worker-based compression cleanup, chunking flow updates; ensure single-init via window.lmnrStartedRecordingEvents.
  • Misc:
    • utils.retry_sync: final-attempt log lowered to debug.

Written by Cursor Bugbot for commit f5408b9. This will update automatically on new commits. Configure here.


Important

Introduce non-blocking background event sending for browser events, integrating it into Playwright and CDP utilities with improved logging and error handling.

  • Background Event Sending:
    • Add background_send_events.py for non-blocking background sending of browser events using a dedicated event loop.
    • Provides submit_sync_task(), get_background_loop(), and track_async_send() for managing async sends.
  • Integration:
    • CDP (cdp_utils.py): Use background loop for event uploads with asyncio.run_coroutine_threadsafe(...) and track_async_send.
    • Playwright (pw_utils.py):
      • Sync: Add lmnrSendEvents wrapper to push work to submit_sync_task(); add closed-page guards.
      • Async: Submit uploads to background loop with run_coroutine_threadsafe + track_async_send.
  • Recorder Injection JS:
    • Normalize parameter to maskInputOptions; guard to avoid double-init; adjust large-event handling.
  • Utilities:
    • retry_sync() logs final failure with logger.debug instead of logger.error.

This description was created by Ellipsis for f5408b9. You can customize this summary. It will automatically update as commits are pushed.

@dinmukhamedm dinmukhamedm marked this pull request as ready for review October 26, 2025 11:14
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Changes requested ❌

Reviewed everything up to 3c16026 in 1 minute and 42 seconds. Click for details.
  • Reviewed 572 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/lmnr/sdk/browser/background_send_events.py:157
  • Draft comment:
    Typographical error: "Finsihing" should be "Finishing".
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% While this is technically correct, it's a very minor typo in a log message that doesn't affect functionality. Log message typos are generally not important enough to warrant a PR comment. The comment doesn't suggest any meaningful code improvements or point out actual bugs. The typo could potentially confuse users who see this log message, and fixing it would improve the polish of the codebase. It's a valid catch. However, this is an extremely minor issue in a log message. We should focus PR comments on more substantial issues that affect code quality or functionality. Delete this comment as it points out an extremely minor issue that doesn't meaningfully impact the code quality or functionality.

Workflow ID: wflow_OduM5dG4AO2RlORD

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Changes requested ❌

Reviewed f5408b9 in 1 minute and 56 seconds. Click for details.
  • Reviewed 525 lines of code in 6 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/lmnr/opentelemetry_lib/tracing/_instrument_initializers.py:80
  • Draft comment:
    Removal of the 'client' parameter: all instrumentors now accept only async_client. Ensure documentation and tests are updated accordingly.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the author to ensure that documentation and tests are updated, which violates the rule against asking the author to ensure things are tested or documented. It does not provide a specific suggestion or ask for a specific test to be written.
2. src/lmnr/opentelemetry_lib/tracing/instruments.py:127
  • Draft comment:
    Initializer calls now pass only async_client. Confirm this meets all instrumentation use cases.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the PR author to confirm that the change meets all use cases, which is against the rules. It does not provide a specific suggestion or point out a specific issue with the code.
3. src/lmnr/sdk/browser/background_send_events.py:48
  • Draft comment:
    Removal of the synchronous executor (submit_sync_task) unifies sending via the async background loop. Verify that no legacy sync submissions rely on the removed function.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the PR author to verify that no legacy sync submissions rely on the removed function. This falls under the rule of not asking the author to confirm or verify intentions or dependencies. Therefore, this comment should be removed.
4. src/lmnr/sdk/browser/patchright_otel.py:96
  • Draft comment:
    PatchrightInstrumentor now only uses async_client. Confirm that downstream usage of client._browser_events.send remains compatible.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the PR author to confirm compatibility with downstream usage, which violates the rule against asking for confirmation or ensuring behavior is intended. It does not provide a specific code suggestion or ask for a test to be written.
5. src/lmnr/sdk/browser/playwright_otel.py:268
  • Draft comment:
    PlaywrightInstrumentor now relies exclusively on async_client for both sync and async wrappers. Verify that this change does not impact any browser interactions.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the PR author to verify that a change does not impact browser interactions. This falls under the rule of not asking the author to ensure behavior is intended or to double-check things. Therefore, this comment should be removed.
6. src/lmnr/sdk/browser/pw_utils.py:760
  • Draft comment:
    In start_recording_events_sync, the expose_function 'lmnrSendEvents' is set using run_coroutine_threadsafe. Confirm robust error handling in cases where the background loop might not be available.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
7. src/lmnr/sdk/browser/pw_utils.py:787
  • Draft comment:
    In start_recording_events_async, exposing the async handler via page.expose_function is done directly. Ensure that any exceptions in send_events_from_browser are properly handled.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_8Ibab2irAVQD1KTu

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@dinmukhamedm dinmukhamedm changed the title wip: fix browser-use-cdp fix browser-use-cdp Nov 5, 2025
@dinmukhamedm dinmukhamedm merged commit 641925d into main Nov 5, 2025
7 checks passed
@dinmukhamedm dinmukhamedm deleted the bg-browser-events branch November 5, 2025 12:57
@dinmukhamedm dinmukhamedm mentioned this pull request Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants