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
If page exists, use it
Magnus Müller5817d2cdeb2d
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.pyindex 8925b6e33..751090293 100644--- a/browser_use/browser/context.py+++ b/browser_use/browser/context.py@@ -202,7 +202,15 @@ class BrowserContext:context = await self._create_context(playwright_browser)self._add_new_page_listener(context)- page = await context.new_page()++ # Check if there's an existing page we can use+ existing_pages = context.pages+ if existing_pages:+ page = existing_pages[-1] # Use the last existing page+ logger.debug('Reusing existing page')+ else:+ page = await context.new_page()+ logger.debug('Created new page')# Instead of calling _update_state(), create an empty initial stateinitial_state = self._get_initial_state(page)