browser-use: browser is not started due to validation error with Browser and BrowserSession classes
Browser Use Version
0.2.1 and above
Bug Description, Steps to Reproduce, Screenshots
- installed browser-use lib by running
uv pip install browser-use - installed the browser by running
playwright install chromium --with-deps - Ran the code below
- Agent crashed with:
slyops | self.browser_session = browser_session or BrowserSession(
slyops | ^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
slyops | validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | pydantic_core._pydantic_core.ValidationError: 1 validation error for BrowserSession
slyops | browser
slyops | Input should be an instance of Browser [type=is_instance_of, input_value=BrowserSession(browser_pr...human_current_page=None), input_type=BrowserSession]
slyops | For further information visit https://errors.pydantic.dev/2.10/v/is_instance_of
Failing Python Code
from browser_use.browser.browser import Browser, BrowserConfig, BrowserContextConfig
controller = Controller(output_model=DummyModel)
llm = ChatOpenAI(model="gpt-4o")
task = "Go to www.google.com and search for the weather in Porto"
browser = Browser(
config=BrowserConfig(
headless=True,
disable_security=True,
new_context_config=BrowserContextConfig(
disable_security=True,
minimum_wait_page_load_time=1, # 3 on prod
maximum_wait_page_load_time=10, # 20 on prod
# no_viewport=True,
browser_window_size={
"width": 1280,
"height": 1100,
},
trace_path="./tmp/traces/",
# save_recording_path='./tmp/recordings/',
),
)
)
agent = BrowserAgent(
task=task,
llm=llm,
browser=browser,
validate_output=False,
controller=controller,
generate_gif=False,
use_vision=True,
# available_paths=[], # TODO: This may be needed to set where to save files...
# sensitive_data=sensitive_data,
# system_prompt_class=CustomSystemPrompt,
# use_vision=False, # This is True by default
)
history = await agent.run(max_steps=30)
result = history.final_result()
LLM Model
gpt-4o
Operating System & Browser Versions
Darwin MacBook-Pro.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:15 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6000 arm64
Full DEBUG Log Output
slyops | INFO [agent] š§ Starting a browser-use agent v0.2.1 with base_model=gpt-4o +tools +vision +memory extraction_model=gpt-4o
slyops | /usr/local/lib/python3.11/site-packages/faiss/loader.py:43: DeprecationWarning:
slyops |
slyops | `numpy.distutils` is deprecated since NumPy 1.23.0, as a result
slyops | of the deprecation of `distutils` itself. It will be removed for
slyops | Python >= 3.12. For older Python versions it will remain present.
slyops | It is recommended to use `setuptools < 60.0` for those Python versions.
slyops | For more details, see:
slyops | https://numpy.org/devdocs/reference/distutils_status_migration.html
slyops |
slyops |
slyops | import numpy.distutils.cpuinfo
slyops | <frozen importlib._bootstrap>:241: DeprecationWarning: builtin type SwigPyPacked has no __module__ attribute
slyops | <frozen importlib._bootstrap>:241: DeprecationWarning: builtin type SwigPyObject has no __module__ attribute
slyops | <frozen importlib._bootstrap>:241: DeprecationWarning: builtin type swigvarlink has no __module__ attribute
slyops | Traceback (most recent call last):
slyops | File "/app/main.py", line 247, in <module>
slyops | asyncio.run(main())
slyops | File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
slyops | return runner.run(main)
slyops | ^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
slyops | return self._loop.run_until_complete(task)
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
slyops | return future.result()
slyops | ^^^^^^^^^^^^^^^
slyops | File "/app/main.py", line 91, in main
slyops | scan_result: IncidentChargersList = await scanner_agent.run(
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/agent.py", line 468, in run
slyops | async for _ in agent_run:
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/agent.py", line 1923, in __anext__
slyops | next_node = await self._graph_run.__anext__()
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_graph/graph.py", line 809, in __anext__
slyops | return await self.next(self._next_node)
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_graph/graph.py", line 782, in next
slyops | self._next_node = await node.run(ctx)
slyops | ^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/_agent_graph.py", line 402, in run
slyops | async with self.stream(ctx):
slyops | File "/usr/local/lib/python3.11/contextlib.py", line 217, in __aexit__
slyops | await anext(self.gen)
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/_agent_graph.py", line 416, in stream
slyops | async for _event in stream:
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/_agent_graph.py", line 465, in _run_stream
slyops | async for event in self._events_iterator:
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/_agent_graph.py", line 443, in _run_stream
slyops | async for event in self._handle_tool_calls(ctx, tool_calls):
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/_agent_graph.py", line 494, in _handle_tool_calls
slyops | async for event in process_function_tools(
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/_agent_graph.py", line 685, in process_function_tools
slyops | result = task.result()
slyops | ^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/tools.py", line 363, in run
slyops | return await self._run(message, run_context)
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic_ai/tools.py", line 380, in _run
slyops | response_content = await function(*args, **kwargs)
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | File "/app/slyops/agents/scanner.py", line 159, in get_chargers_status
slyops | agent = BrowserAgent(
slyops | ^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/browser_use/utils.py", line 307, in wrapper
slyops | result = func(*args, **kwargs)
slyops | ^^^^^^^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/browser_use/agent/service.py", line 294, in __init__
slyops | self.browser_session = browser_session or BrowserSession(
slyops | ^^^^^^^^^^^^^^^
slyops | File "/usr/local/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
slyops | validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
slyops | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
slyops | pydantic_core._pydantic_core.ValidationError: 1 validation error for BrowserSession
slyops | browser
slyops | Input should be an instance of Browser [type=is_instance_of, input_value=BrowserSession(browser_pr...human_current_page=None), input_type=BrowserSession]
slyops | For further information visit https://errors.pydantic.dev/2.10/v/is_instance_of
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 21 (10 by maintainers)
ok, 0.2.6 will also have several more fixes to handling the old
cookies_file+ it will auto-export a newstorage_state.jsonif the old format is used to make switching easier0.2.4this is not solved right?
After I have used this method (
await page.context.add_cookies(cookies)):It seems that the cookies are now finally being used by the Agent. For some reason, it didnt work with the previous methodsā¦