Skip to content

fix(daemon): fire-and-forget mark_js in tap handler (fixes #136)#164

Open
hnshah wants to merge 2 commits intobrowser-use:mainfrom
hnshah:fix/tap-handler-perf
Open

fix(daemon): fire-and-forget mark_js in tap handler (fixes #136)#164
hnshah wants to merge 2 commits intobrowser-use:mainfrom
hnshah:fix/tap-handler-perf

Conversation

@hnshah
Copy link
Copy Markdown

@hnshah hnshah commented Apr 23, 2026

Summary

The tap event handler in daemon.py awaits the Runtime.evaluate call that adds the 🟢 tab marker on every Page.loadEventFired and Page.domContentEventFired. Because cdp-use dispatches events sequentially, this await blocks the event queue — domContentEventFired holds up loadEventFired, and both evals queue in Chrome's V8 thread ahead of the user's next js(...) call. Two ~2s timeouts compound to ~4s per navigation.

Switching to asyncio.create_task() makes the mark_js eval fire-and-forget. The 🟢 title still appears, just a moment later. The event queue is no longer blocked.

Before / after (9 navigations, 3 URLs × 3 rounds)

Before After
Median 4.136s 0.278s
Mean 4.266s 0.287s
Min 4.032s 0.126s

~15× improvement.

Test plan

  • Benchmark before/after with goto → wait_for_load → js loop
  • Tab marking still works — page_info()["title"] contains 🟢
  • Screenshot, js(), drain_events() all functional
  • 10 rapid tab create/navigate/close cycles — no race conditions

Summary by cubic

Switch the tap handler to fire-and-forget the mark_js Runtime.evaluate via asyncio.create_task so CDP events don’t block on 2s timeouts, and guard the task with try/except to avoid unhandled exceptions. Navigation is ~15× faster (median 4.1s → 0.28s) and the 🟢 tab title still appears.

Written for commit 9779034. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="daemon.py">

<violation number="1" location="daemon.py:157">
P2: Fire-and-forget `create_task` for `send_raw` is unguarded (no timeout/exception handling), which can leave pending tasks and produce unhandled task exceptions under CDP stalls/failures.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread daemon.py Outdated
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.

1 participant