Skip to content

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

fix-viewport

Magnus Müllerd9e06700bd10
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.py
index 8c00b1192..898dfbbb6 100644
--- a/browser_use/browser/profile.py
+++ b/browser_use/browser/profile.py
@@ -194,7 +194,9 @@ def get_display_size() -> ViewportSize | None:
from AppKit import NSScreen # type: ignore[import]
screen = NSScreen.mainScreen().frame()
- return ViewportSize(width=int(screen.size.width), height=int(screen.size.height))
+ size = ViewportSize(width=int(screen.size.width), height=int(screen.size.height))
+ logger.debug(f'Display size: {size}')
+ return size
except Exception:
pass
@@ -204,10 +206,13 @@ def get_display_size() -> ViewportSize | None:
monitors = get_monitors()
monitor = monitors[0]
- return ViewportSize(width=int(monitor.width), height=int(monitor.height))
+ size = ViewportSize(width=int(monitor.width), height=int(monitor.height))
+ logger.debug(f'Display size: {size}')
+ return size
except Exception:
pass
+ logger.debug('No display size found')
return None
@@ -632,11 +637,11 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Bro
"""Copy old config window_width & window_height to window_size."""
if self.window_width or self.window_height:
logger.warning(
- f'⚠️ BrowserProfile(window_width=..., window_height=...) are deprecated, use BrowserProfile(window_size={"width": 1280, "height": 1100}) instead.'
+ f'⚠️ BrowserProfile(window_width=..., window_height=...) are deprecated, use BrowserProfile(window_size={"width": 1920, "height": 1080}) instead.'
)
window_size = self.window_size or ViewportSize(width=0, height=0)
- window_size['width'] = window_size['width'] or self.window_width or 1280
- window_size['height'] = window_size['height'] or self.window_height or 1100
+ window_size['width'] = window_size['width'] or self.window_width or 1920
+ window_size['height'] = window_size['height'] or self.window_height or 1080
self.window_size = window_size
return self
@@ -694,6 +699,10 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Bro
logger.warning('BrowserProfile.proxy.bypass provided but proxy has no server; bypass will be ignored.')
return self
+ def model_post_init(self, __context: Any) -> None: # noqa: ARG002
+ """Called after model initialization to set up display configuration."""
+ self.detect_display_configuration()
+
def get_args(self) -> list[str]:
"""Get the list of all Chrome CLI launch args for this profile (compiled from defaults, user-provided, and system-specific)."""
@@ -989,7 +998,7 @@ async function initialize(checkInitialized, magic) {{
display_size = get_display_size()
has_screen_available = bool(display_size)
- self.screen = self.screen or display_size or ViewportSize(width=1280, height=1100)
+ self.screen = self.screen or display_size or ViewportSize(width=1920, height=1080)
# if no headless preference specified, prefer headful if there is a display available
if self.headless is None: