From 34b211a753284b8b8a5e09919b062e892b0e836d Mon Sep 17 00:00:00 2001 From: yicheng <928596708@qq.com> Date: Sat, 20 Jun 2026 08:22:23 +0800 Subject: [PATCH] fix(browser): register event loop on worker thread for stream_async When strands dispatches _execute_async to a worker thread, the browser's event loop isn't available there, causing 'RuntimeError: There is no current event loop in thread'. Fix by calling asyncio.set_event_loop() in _execute_async before nest_asyncio.apply(). Fixes #453 --- src/strands_tools/browser/browser.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/strands_tools/browser/browser.py b/src/strands_tools/browser/browser.py index 03d44808..b28e849d 100644 --- a/src/strands_tools/browser/browser.py +++ b/src/strands_tools/browser/browser.py @@ -946,6 +946,10 @@ def close(self, action: CloseAction) -> Dict[str, Any]: return {"status": "error", "content": [{"text": f"Error: {str(e)}"}]} def _execute_async(self, action_coro) -> Any: + # Ensure the browser's event loop is set on the current thread + # (strands dispatches sync methods to a worker thread) + asyncio.set_event_loop(self._loop) + # Apply nest_asyncio if not already applied if not self._nest_asyncio_applied: nest_asyncio.apply()