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
fix openai imports again
Nick Sweeting3f5e4345e55b
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 43305cc7f..7cc960a66 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -319,7 +319,7 @@ class Controller(Generic[Context]):# result = await client.send.DOM.getDocument(params={'pierce': True}, session_id=session_id)# root_node_id = result['root']['nodeId']# page_html_result = await client.send.DOM.getOuterHTML(params={'nodeId': 1}, session_id=session_id)- page_html_result = await client.send.Page.captureSnapshot(params={'format': 'mhtml'}, session_id=session_id)+ page_html_result = await client.send.Page.captureSnapshot(params={'format': 'mhtml'}, session_id=session_id) # included OOPIF content automaticallyexcept TimeoutError:raise RuntimeError('Page content extraction timed out after 5 seconds')except Exception as e:@@ -337,29 +337,6 @@ class Controller(Generic[Context]):logger.warning(f'Markdownify failed: {type(e).__name__}')raise RuntimeError(f'Could not convert html to markdown: {type(e).__name__}')- # TODO: fix this using new browser_session.get_all_frames()- # # manually append iframe text into the content so it's readable by the LLM (includes cross-origin iframes)- # for iframe in page.frames:- # try:- # await iframe.wait_for_load_state(timeout=1000) # 1 second aggressive timeout for iframe load- # except Exception:- # pass-- # if iframe.url != page.url and not iframe.url.startswith('data:') and not iframe.url.startswith('about:'):- # content += f'\n\nIFRAME {iframe.url}:\n'- # # Run markdownify in a thread pool for iframe content as well- # try:- # # Aggressive timeouts for iframe content- # iframe_html = await asyncio.wait_for(iframe.content(), timeout=2.0) # 2 second aggressive timeout- # iframe_markdown = await asyncio.wait_for(- # loop.run_in_executor(None, markdownify_func, iframe_html),- # timeout=2.0, # 2 second aggressive timeout for iframe markdownify- # )- # except Exception:- # iframe_markdown = '' # Skip failed iframes- # content += iframe_markdown- # # replace multiple sequential \n with a single \n-content = re.sub(r'\n+', '\n', content)# limit to 30000 characters - remove text in the middle (≈15000 tokens)diff --git a/browser_use/llm/openai/serializer.py b/browser_use/llm/openai/serializer.pyindex 2d0f96ff3..2bcdddd1d 100644--- a/browser_use/llm/openai/serializer.py+++ b/browser_use/llm/openai/serializer.py@@ -5,13 +5,13 @@ from openai.types.chat import (ChatCompletionContentPartImageParam,ChatCompletionContentPartRefusalParam,ChatCompletionContentPartTextParam,- ChatCompletionMessageToolCallParam,+ ChatCompletionMessageFunctionToolCallParam,ChatCompletionMessageParam,ChatCompletionSystemMessageParam,ChatCompletionUserMessageParam,)from openai.types.chat.chat_completion_content_part_image_param import ImageURL-from openai.types.chat.chat_completion_message_tool_call_param import Function+from openai.types.chat.chat_completion_message_function_tool_call_param import Functionfrom browser_use.llm.messages import (AssistantMessage,@@ -92,8 +92,8 @@ class OpenAIMessageSerializer:return serialized_parts@staticmethod- def _serialize_tool_call(tool_call: ToolCall) -> ChatCompletionMessageToolCallParam:- return ChatCompletionMessageToolCallParam(+ def _serialize_tool_call(tool_call: ToolCall) -> ChatCompletionMessageFunctionToolCallParam:+ return ChatCompletionMessageFunctionToolCallParam(id=tool_call.id,function=Function(name=tool_call.function.name, arguments=tool_call.function.arguments),type='function',