Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
use raw CDP call for screenshot instead of playwright CDP session
Nick Sweeting48fd583ae137
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 9b5a2e52f..2e22ba5f0 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -2653,7 +2653,11 @@ class BrowserSession(BaseModel):# Take the screenshot using CDP# https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot- result = await cdp_session.send('Page.captureScreenshot', cdp_params)+ # Use the internal _channel.send method to bypass some of the async wrapper issues+ if hasattr(cdp_session, '_channel'):+ result = await cdp_session._channel.send('send', None, {'method': 'Page.captureScreenshot', 'params': cdp_params})+ else:+ result = await cdp_session.send('Page.captureScreenshot', cdp_params)# The result already contains base64 encoded database64_screenshot = result.get('data')@@ -2673,8 +2677,13 @@ class BrowserSession(BaseModel):# Clean up CDP sessionif cdp_session:try:- await cdp_session.detach()+ # Use internal method if available to ensure proper cleanup+ if hasattr(cdp_session, '_channel') and hasattr(cdp_session._channel, 'send'):+ await cdp_session._channel.send('detach', None, {})+ else:+ await cdp_session.detach()except Exception:+ # Ignore all exceptions during cleanuppass@require_initialization