Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

add get_state_as_text

Magnus Müller4c7cf1604204
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index 96fa9444d..c1ca1cfdc 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -1160,6 +1160,13 @@ class BrowserSession(BaseModel):
assert result is not None and result.dom_state is not None
return result
+ async def get_state_as_text(self) -> str:
+ """Get the browser state as text."""
+ state = await self.get_browser_state_summary()
+ assert state.dom_state is not None
+ dom_state = state.dom_state
+ return dom_state.llm_representation()
+
async def attach_all_watchdogs(self) -> None:
"""Initialize and attach all watchdogs with explicit handler registration."""
# Prevent duplicate watchdog attachment