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
Handle uncommitted Cloud tab URLs in OpenAI tools
Magnus Muellerd1f5c8350346
diff --git a/browser_use/integrations/openai/browser_use.py b/browser_use/integrations/openai/browser_use.pyindex 846e4bd40..d6db0c8f9 100644--- a/browser_use/integrations/openai/browser_use.py+++ b/browser_use/integrations/openai/browser_use.py@@ -78,7 +78,13 @@ class BrowserUse:self._refs = {name: ref for name, ref in self._refs.items() if ref.tab in ids}return {'tabs': [- {'id': t['targetId'], 'url': t['url'], 'title': t['title'], 'active': t['targetId'] == self._active} for t in tabs+ {+ 'id': t['targetId'],+ 'url': t['url'] or 'about:blank',+ 'title': t['title'],+ 'active': t['targetId'] == self._active,+ }+ for t in tabs]}diff --git a/pyproject.toml b/pyproject.tomlindex 08f5a49f1..642200e61 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -2,7 +2,7 @@name = "browser-use"description = "Make websites accessible for AI agents"authors = [{ name = "Gregor Zunic" }]-version = "0.13.12"+version = "0.13.13"readme = "README.md"requires-python = ">=3.11,<4.0"classifiers = [diff --git a/tests/ci/integrations/test_openai_browser_use.py b/tests/ci/integrations/test_openai_browser_use.pyindex 1deb3fddc..43d77f508 100644--- a/tests/ci/integrations/test_openai_browser_use.py+++ b/tests/ci/integrations/test_openai_browser_use.py@@ -163,3 +163,37 @@ async def test_sdk_dispatch_changes_form_and_selects_option(driver):assert await page.evaluate("() => document.querySelector('#choice').value") == 'b'finally:tools.close()+++async def test_sdk_accepts_uncommitted_tab_without_url(driver, monkeypatch):+ read_targets = driver.browser.cdp_client.send.Target.getTargets++ async def uncommitted_targets(*args, **kwargs):+ result = await read_targets(*args, **kwargs)+ for target in result['targetInfos']:+ if target['type'] == 'page':+ target['url'] = ''+ return result++ monkeypatch.setattr(driver.browser.cdp_client.send.Target, 'getTargets', uncommitted_targets)+ tools = AsyncBrowserToolset(driver, members=['list_tabs'])+ try:+ output = await tools.execute(+ ResponseFunctionToolCall(+ id='fc_tabs',+ call_id='call_tabs',+ type='function_call',+ status='completed',+ name='browser_list_tabs',+ arguments='{}',+ )+ )+ assert isinstance(output['output'], list)+ assert output['output'][0]['type'] == 'input_text'+ result = json.loads(output['output'][0]['text'])+ assert result['ok'] is True+ assert result['state']['tabs']+ assert all(tab['url'] == 'about:blank' for tab in result['state']['tabs'])+ finally:+ tools.close()