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 pydantic issue causing config to be overwritten
Nick Sweeting5fa2e133b812
diff --git a/browser_use/browser/browser.py b/browser_use/browser/browser.pyindex 888f26932..782575799 100644--- a/browser_use/browser/browser.py+++ b/browser_use/browser/browser.py@@ -79,7 +79,14 @@ class BrowserConfig(BaseModel):Enable deterministic rendering (makes GPU/font rendering consistent across different OS's and docker)"""- model_config = ConfigDict(arbitrary_types_allowed=True, extra='ignore')+ model_config = ConfigDict(+ arbitrary_types_allowed=True,+ extra='ignore',+ populate_by_name=True,+ from_attributes=True,+ validate_assignment=True,+ revalidate_instances='subclass-instances',+ )wss_url: str | None = Nonecdp_url: str | None = None@@ -109,16 +116,16 @@ class Browser:def __init__(self,- config: BrowserConfig = BrowserConfig(),+ config: BrowserConfig | None = None,):logger.debug('🌎 Initializing new browser')- self.config = config+ self.config = config or BrowserConfig()self.playwright: Playwright | None = Noneself.playwright_browser: PlaywrightBrowser | None = None- async def new_context(self, config: BrowserContextConfig = BrowserContextConfig()) -> BrowserContext:+ async def new_context(self, config: BrowserContextConfig | None = None) -> BrowserContext:"""Create a browser context"""- return BrowserContext(config=config, browser=self)+ return BrowserContext(config=config or self.config, browser=self)async def get_playwright_browser(self) -> PlaywrightBrowser:"""Get a browser context"""diff --git a/browser_use/controller/registry/views.py b/browser_use/controller/registry/views.pyindex a2a88797a..47956a048 100644--- a/browser_use/controller/registry/views.py+++ b/browser_use/controller/registry/views.py@@ -26,7 +26,7 @@ class RegisteredAction(BaseModel):s += str({k: {sub_k: sub_v for sub_k, sub_v in v.items() if sub_k not in skip_keys}- for k, v in self.param_model.schema()['properties'].items()+ for k, v in self.param_model.model_json_schema()['properties'].items()})s += '}'diff --git a/browser_use/controller/views.py b/browser_use/controller/views.pyindex 579b64ec5..b7519a91f 100644--- a/browser_use/controller/views.py+++ b/browser_use/controller/views.py@@ -1,6 +1,6 @@from typing import Optional-from pydantic import BaseModel, Field, model_validator+from pydantic import BaseModel, ConfigDict, Field, model_validator# Action Input Models@@ -90,12 +90,9 @@ class NoParamsAction(BaseModel):and discards it, so the final parsed model is empty."""+ model_config = ConfigDict(extra='allow')+@model_validator(mode='before')def ignore_all_inputs(cls, values):# No matter what the user sends, discard it and return empty.return {}-- class Config:- # If you want to silently allow unknown fields at top-level,- # set extra = 'allow' as well:- extra = 'allow'