tap handler in daemon.py blocks ~2–4s per navigation on await Runtime.evaluate
Thanks for the harness. Hit a performance thing worth flagging.
Finding:
On a fresh Chromium with cache-busted navigations, a goto → wait_for_load → js(extract) loop runs at ~4.5s per iteration. Playwright on the same browser does it in ~0.9s. One tweak gets the harness to ~1.06s, so it isn't the CDP layer.
Cause is daemon.py:152, the mark_js eval in the tap handler. Dropping the await:
elif method in ("Page.loadEventFired", "Page.domContentEventFired"):
asyncio.create_task(self.cdp.send_raw(
"Runtime.evaluate", {"expression": mark_js}, session_id=self.session
))
Two stalls compound. cdp-use dispatches events one at a time, so the await on domContentEventFired holds up loadEventFired in the queue. Chrome's V8 thread is busy, the eval doesn't return, the 2s wait_for ceiling hits. Then the same thing happens on loadEventFired, and the user's next js(...) queues behind that second eval on V8. Two ~2s waits, one in event dispatch, one in Chrome.
Fire-and-forget fixes both. The 🟢 title still lands, just a moment later. Median per iteration: 4.595s → 1.060s.
Question:
The await and 2s cap both look deliberate. What I'm less sure is intentional: the cap trips twice per navigation (DCL + load), and the second eval stacks in V8's queue ahead of the user's next js(...), so the cost doubles. Did you mean to pay that twice, or was one trip the worst case you had in mind? Happy to open a PR if the double-trip wasn't the intent.
Env:
macOS 14.6 / Apple Silicon, Chrome for Testing 145, Python 3.13, browser-harness@main, cdp-use==1.4.5.
Implemented in PR https://github.com/browser-use/browser-harness/pull/171. Kept the existing except Exception: pass behavior via a module-level _silent(coro) wrapper so stale-session failures still swallow quietly, now off the critical path.