Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

finish updating last few locations where nested window_size was used

Nick Sweetingd08b40210135
diff --git a/browser_use/agent/playwright_script_generator.py b/browser_use/agent/playwright_script_generator.py
index a36cc22e3..346a570f6 100644
--- a/browser_use/agent/playwright_script_generator.py
+++ b/browser_use/agent/playwright_script_generator.py
@@ -111,10 +111,10 @@ class PlaywrightScriptGenerator:
# Handle viewport/window size
if self.context_config.no_viewport:
options_dict['no_viewport'] = True
- elif self.context_config.browser_window_size:
+ elif hasattr(self.context_config, 'window_width') and hasattr(self.context_config, 'window_height'):
options_dict['viewport'] = {
- 'width': self.context_config.browser_window_size.width,
- 'height': self.context_config.browser_window_size.height,
+ 'width': self.context_config.window_width,
+ 'height': self.context_config.window_height,
}
# Note: cookies_file and save_downloads_path are handled separately
diff --git a/browser_use/browser/browser.py b/browser_use/browser/browser.py
index 11240b1f2..2dd8a203a 100644
--- a/browser_use/browser/browser.py
+++ b/browser_use/browser/browser.py
@@ -269,9 +269,13 @@ class Browser:
if (
not self.config.headless
and hasattr(self.config, 'new_context_config')
- and hasattr(self.config.new_context_config, 'browser_window_size')
+ and hasattr(self.config.new_context_config, 'window_width')
+ and hasattr(self.config.new_context_config, 'window_height')
):
- screen_size = self.config.new_context_config.browser_window_size.model_dump()
+ screen_size = {
+ 'width': self.config.new_context_config.window_width,
+ 'height': self.config.new_context_config.window_height,
+ }
offset_x, offset_y = get_window_adjustments()
elif self.config.headless:
screen_size = {'width': 1920, 'height': 1080}
diff --git a/browser_use/browser/chrome.py b/browser_use/browser/chrome.py
index 2aebcd2e1..e3fa229eb 100644
--- a/browser_use/browser/chrome.py
+++ b/browser_use/browser/chrome.py
@@ -1,6 +1,3 @@
-CHROME_DEFAULT_USER_AGENT = (
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.3'
-)
CHROME_EXTENSIONS = {} # coming in a separate PR
CHROME_EXTENSIONS_PATH = 'chrome_extensions'
CHROME_PROFILE_PATH = 'chrome_profile'
@@ -102,7 +99,7 @@ CHROME_ARGS = [
# f'--profile-directory={CHROME_PROFILE_USER}',
# '--password-store=basic', # use mock keychain instead of OS-provided keychain (we manage auth.json instead)
# '--use-mock-keychain',
- '--disable-cookie-encryption', # we need to be able to write unencrypted cookies to save/load auth.json
+ # '--disable-cookie-encryption', # we need to be able to write unencrypted cookies to save/load auth.json
'--disable-sync', # don't try to use Google account sync features while automation is active
# Extensions
# chrome://inspect/#extensions
diff --git a/docs/customize/browser-settings.mdx b/docs/customize/browser-settings.mdx
index 3b7537930..74b664bf3 100644
--- a/docs/customize/browser-settings.mdx
+++ b/docs/customize/browser-settings.mdx
@@ -117,7 +117,8 @@ from browser_use.browser.context import BrowserContextConfig
config = BrowserContextConfig(
cookies_file="path/to/cookies.json",
wait_for_network_idle_page_load_time=3.0,
- browser_window_size={'width': 1280, 'height': 1100},
+ window_width=1280,
+ window_height=1100,
locale='en-US',
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
highlight_elements=True,
@@ -151,7 +152,7 @@ async def run_search():
### Display Settings
-- **browser_window_size** (default: `{'width': 1280, 'height': 1100}`)
+- **window_width** (default: `1280`) and **window_height** (default: `1100`)
Browser window dimensions. The default size is optimized for general use cases and interaction with common UI elements like cookie banners.
- **locale** (default: `None`)
diff --git a/examples/features/result_processing.py b/examples/features/result_processing.py
index 07f485161..ca0454d1a 100644
--- a/examples/features/result_processing.py
+++ b/examples/features/result_processing.py
@@ -26,7 +26,8 @@ async def main():
config=BrowserContextConfig(
trace_path='./tmp/result_processing',
no_viewport=False,
- browser_window_size={'width': 1280, 'height': 1000},
+ window_width=1280,
+ window_height=1000,
)
) as browser_context:
agent = Agent(
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 4b2d56d04..fe31c3968 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -468,8 +468,8 @@ async def test_standard_browser_launch_with_proxy(monkeypatch):
@pytest.mark.asyncio
async def test_browser_window_size(monkeypatch):
"""
- Test that when a browser_window_size is provided in BrowserContextConfig,
- it's properly converted to a dictionary when passed to Playwright.
+ Test that when window_width and window_height are provided in BrowserContextConfig,
+ they're properly converted to a dictionary when passed to Playwright.
"""
class DummyPage:
@@ -564,9 +564,9 @@ async def test_browser_window_size(monkeypatch):
playwright_browser = await browser_obj.get_playwright_browser()
# Create context config with specific window size
- context_config = BrowserContextConfig(browser_window_size={'width': 1280, 'height': 1100})
+ context_config = BrowserContextConfig(window_width=1280, window_height=1100)
- # Create browser context - this will test if browser_window_size is properly converted
+ # Create browser context - this will test if window dimensions are properly converted
browser_context = BrowserContext(browser=browser_obj, config=context_config)
await browser_context._initialize_session()