openclaw/src/browser
Onur 424d2dddf5
fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498)
* fix(browser): prevent permanent timeout after stuck evaluate

Thread AbortSignal from client-fetch through dispatcher to Playwright
operations. When a timeout fires, force-disconnect the Playwright CDP
connection to unblock the serialized command queue, allowing the next
call to reconnect transparently.

Key changes:
- client-fetch.ts: proper AbortController with signal propagation
- pw-session.ts: new forceDisconnectPlaywrightForTarget()
- pw-tools-core.interactions.ts: accept signal, align inner timeout
  to outer-500ms, inject in-browser Promise.race for async evaluates
- routes/dispatcher.ts + types.ts: propagate signal through dispatch
- server.ts + bridge-server.ts: Express middleware creates AbortSignal
  from request lifecycle
- client-actions-core.ts: add timeoutMs to evaluate type

Fixes #10994

* fix(browser): v2 - force-disconnect via Connection.close() instead of browser.close()

When page.evaluate() is stuck on a hung CDP transport, browser.close() also
hangs because it tries to send a close command through the same stuck pipe.

v2 fix: forceDisconnectPlaywrightForTarget now directly calls Playwright's
internal Connection.close() which locally rejects all pending callbacks and
emits 'disconnected' without touching the network. This instantly unblocks
all stuck Playwright operations.

closePlaywrightBrowserConnection (clean shutdown) now also has a 3s timeout
fallback that drops to forceDropConnection if browser.close() hangs.

Fixes permanent browser timeout after stuck evaluate.

* fix(browser): v3 - fire-and-forget browser.close() instead of Connection.close()

v2's forceDropConnection called browser._connection.close() which corrupts
the entire Playwright instance because Connection is shared across all
objects (BrowserType, Browser, Page, etc.). This prevented reconnection
with cascading 'connectOverCDP: Force-disconnected' errors.

v3 fix: forceDisconnectPlaywrightForTarget now:
1. Nulls cached connection immediately
2. Fire-and-forgets browser.close() (doesn't await — it may hang)
3. Next connectBrowser() creates a fresh connectOverCDP WebSocket

Each connectOverCDP creates an independent WebSocket to the CDP endpoint,
so the new connection is unaffected by the old one's pending close.
The old browser.close() eventually resolves when the in-browser evaluate
timeout fires, or the old connection gets GC'd.

* fix(browser): v4 - clear connecting state and remove stale disconnect listeners

The reconnect was failing because:
1. forceDisconnectPlaywrightForTarget nulled cached but not connecting,
   so subsequent calls could await a stale promise
2. The old browser's 'disconnected' event handler raced with new
   connections, nulling the fresh cached reference

Fix: null both cached and connecting, and removeAllListeners on the
old browser before fire-and-forget close.

* fix(browser): v5 - use raw CDP Runtime.terminateExecution to kill stuck evaluate

When forceDisconnectPlaywrightForTarget fires, open a raw WebSocket
to the stuck page's CDP endpoint and send Runtime.terminateExecution.
This kills running JS without navigating away or crashing the page.
Also clear connecting state and remove stale disconnect listeners.

* fix(browser): abort cancels stuck evaluate

* Browser: always cleanup evaluate abort listener

* Chore: remove Playwright debug scripts

* Docs: add CDP evaluate refactor plan

* Browser: refactor Playwright force-disconnect

* Browser: abort stops evaluate promptly

* Node host: extract withTimeout helper

* Browser: remove disconnected listener safely

* Changelog: note act:evaluate hang fix

---------

Co-authored-by: Bob <bob@dutifulbob.com>
2026-02-11 07:54:48 +08:00
..
routes fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
bridge-server.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
cdp.helpers.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
cdp.helpers.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
cdp.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
cdp.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
chrome.default-browser.test.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
chrome.executables.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
chrome.profile-decoration.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
chrome.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
chrome.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
client-actions-core.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
client-actions-observe.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
client-actions-state.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
client-actions-types.ts feat(browser): expand browser control surface 2026-01-12 17:32:44 +00:00
client-actions.ts feat(browser): expand browser control surface 2026-01-12 17:32:44 +00:00
client-fetch.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
client.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
client.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
config.test.ts refactor: rename to openclaw 2026-01-30 03:16:21 +01:00
config.ts refactor: centralize isPlainObject, isRecord, isErrno, isLoopbackHost utilities (#12926) 2026-02-09 17:02:55 -08:00
constants.ts refactor: rename to openclaw 2026-01-30 03:16:21 +01:00
control-service.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
extension-relay.test.ts fix: secure chrome extension relay cdp 2026-02-01 02:25:14 -08:00
extension-relay.ts Deduplicate more 2026-02-09 18:56:58 -08:00
profiles-service.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
profiles-service.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
profiles.test.ts chore: Enable typescript/no-explicit-any rule. 2026-02-02 16:18:09 +09:00
profiles.ts chore: Enable typescript/no-explicit-any rule. 2026-02-02 16:18:09 +09:00
pw-ai-module.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-ai.test.ts fix(browser): register AI snapshot refs (#1282) 2026-01-20 14:14:36 +00:00
pw-ai.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
pw-role-snapshot.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
pw-role-snapshot.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-session.browserless.live.test.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-session.get-page-for-targetid.extension-fallback.test.ts fix(browser): handle extension relay page selection 2026-01-15 11:16:53 +00:00
pw-session.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
pw-session.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
pw-tools-core.activity.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.clamps-timeoutms-scrollintoview.test.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.downloads.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
pw-tools-core.interactions.evaluate.abort.test.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
pw-tools-core.interactions.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
pw-tools-core.last-file-chooser-arm-wins.test.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.responses.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.screenshots-element-selector.test.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.shared.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.snapshot.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.state.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
pw-tools-core.storage.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
pw-tools-core.trace.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
pw-tools-core.ts refactor(browser): split pw tools + agent routes 2026-01-14 05:39:44 +00:00
pw-tools-core.waits-next-download-saves-it.test.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
screenshot.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
screenshot.ts chore: Enable more lint rules, disable some that trigger a lot. Will clean up later. 2026-01-31 16:04:04 +09:00
server-context.ensure-tab-available.prefers-last-target.test.ts chore: Enable typescript/no-explicit-any rule. 2026-02-02 16:18:09 +09:00
server-context.remote-tab-ops.test.ts chore: Enable typescript/no-explicit-any rule. 2026-02-02 16:18:09 +09:00
server-context.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server-context.types.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server.agent-contract-form-layout-act-commands.test.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
server.agent-contract-snapshot-endpoints.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server.covers-additional-endpoint-branches.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server.post-tabs-open-profile-unknown-returns-404.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server.serves-status-starts-browser-requested.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server.skips-default-maxchars-explicitly-set-zero.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
server.ts fix: prevent act:evaluate hangs from getting browser tool stuck/killed (#13498) 2026-02-11 07:54:48 +08:00
target-id.test.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00
target-id.ts chore: Enable "curly" rule to avoid single-statement if confusion/errors. 2026-01-31 16:19:20 +09:00
trash.ts chore: Enable "experimentalSortImports" in Oxfmt and reformat all imorts. 2026-02-01 10:03:47 +09:00