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
Remove display highlights on screen feature and adjust bounding box drawing parameters
Magnus Müller8511c2d3980e
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex c9170b8b6..e29d910b0 100644--- a/browser_use/browser/profile.py+++ b/browser_use/browser/profile.py@@ -583,9 +583,6 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Bro# --- UI/viewport/DOM ---highlight_elements: bool = Field(default=True, description='Highlight interactive elements on the page.')- display_highlights_on_screen: bool = Field(- default=True, description='Display highlights directly on the browser screen in addition to screenshots.'- )# --- Downloads ---auto_download_pdfs: bool = Field(diff --git a/browser_use/browser/python_highlights.py b/browser_use/browser/python_highlights.pyindex 5644f1eac..cf958e8f4 100644--- a/browser_use/browser/python_highlights.py+++ b/browser_use/browser/python_highlights.py@@ -94,7 +94,7 @@ def draw_enhanced_bounding_box_with_text(try:# Use much bigger font size for index (5x bigger base)huge_font = None- font_size = 32 # Much bigger than the original 16+ font_size = 35 # Much bigger than the original 16try:huge_font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', font_size)except (OSError, IOError):@@ -118,8 +118,8 @@ def draw_enhanced_bounding_box_with_text(text_width = bbox_text[2] - bbox_text[0]text_height = bbox_text[3] - bbox_text[1]- # Much bigger padding (5x bigger)- padding = 20+ # No padding - container fits exactly around the number+ padding = 10element_width = x2 - x1element_height = y2 - y1diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 910324cf9..b4b01f62c 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -265,7 +265,6 @@ class BrowserSession(BaseModel):wait_for_network_idle_page_load_time: float | None = None,wait_between_actions: float | None = None,highlight_elements: bool | None = None,- display_highlights_on_screen: bool | None = None,auto_download_pdfs: bool | None = None,profile_directory: str | None = None,):diff --git a/browser_use/browser/watchdogs/dom_watchdog.py b/browser_use/browser/watchdogs/dom_watchdog.pyindex 72dee72cc..0db217d8b 100644--- a/browser_use/browser/watchdogs/dom_watchdog.py+++ b/browser_use/browser/watchdogs/dom_watchdog.py@@ -239,94 +239,6 @@ class DOMWatchdog(BaseWatchdog):except Exception as e:self.logger.warning(f'🔍 DOMWatchdog.on_BrowserStateRequestEvent: Python highlighting failed: {e}')- # Display highlighted screenshot overlay on screen if requested- if (- screenshot_b64- and content- and content.selector_map- and self.browser_session.browser_profile.display_highlights_on_screen- ):- try:- self.logger.debug(- '🔍 DOMWatchdog.on_BrowserStateRequestEvent: 🖥️ Displaying highlighted screenshot overlay...'- )-- # Use the existing screenshot (which has correct scaling) and add highlights to it- # Get CDP session for viewport info- cdp_session = await self.browser_session.get_or_create_cdp_session()-- # Create highlighted version of the existing screenshot- from browser_use.browser.python_highlights import create_highlighted_screenshot_async-- highlighted_screenshot_b64 = await create_highlighted_screenshot_async(- screenshot_b64, content.selector_map, cdp_session- )-- # Get viewport dimensions and device pixel ratio for proper scaling- viewport_info = await cdp_session.cdp_client.send.Page.getLayoutMetrics(session_id=cdp_session.session_id)- visual_viewport = viewport_info.get('visualViewport', {})- css_visual_viewport = viewport_info.get('cssVisualViewport', {})-- # Get CSS pixel dimensions (what the browser shows)- css_width = css_visual_viewport.get('clientWidth', 1280)- css_height = css_visual_viewport.get('clientHeight', 720)-- # Get device pixel dimensions (what the screenshot is)- device_width = visual_viewport.get('clientWidth', css_width)- device_height = visual_viewport.get('clientHeight', css_height)-- # Calculate device pixel ratio- device_pixel_ratio = device_width / css_width if css_width > 0 else 1.0-- # Inject the highlighted screenshot as an overlay with correct DPR scaling- overlay_script = f"""- (function() {{- // Remove any existing browser-use overlay- const existingOverlay = document.getElementById('browser-use-highlight-overlay');- if (existingOverlay) {{- existingOverlay.remove();- }}-- // Get actual viewport dimensions in CSS pixels- const cssWidth = window.innerWidth;- const cssHeight = window.innerHeight;- const devicePixelRatio = window.devicePixelRatio || 1;-- // Create overlay container- const overlay = document.createElement('div');- overlay.id = 'browser-use-highlight-overlay';- overlay.style.cssText = `- position: fixed;- top: 0;- left: 0;- width: ${{cssWidth}}px;- height: ${{cssHeight}}px;- pointer-events: none;- z-index: 2147483647;- opacity: 0.4;- background-image: url(data:image/png;base64,{highlighted_screenshot_b64});- background-size: ${{cssWidth}}px ${{cssHeight}}px;- background-position: top left;- background-repeat: no-repeat;- `;-- document.body.appendChild(overlay);- console.log('Browser-use highlighted screenshot overlay injected with', '{len(content.selector_map)}', 'elements');- console.log('CSS viewport:', cssWidth, 'x', cssHeight, 'DPR:', devicePixelRatio);- }})();- """-- # Execute the overlay script- await cdp_session.cdp_client.send.Runtime.evaluate(- params={'expression': overlay_script, 'returnByValue': True}, session_id=cdp_session.session_id- )-- self.logger.debug(- f'🔍 DOMWatchdog.on_BrowserStateRequestEvent: ✅ Displayed highlighted screenshot overlay with {len(content.selector_map)} elements'- )- except Exception as e:- self.logger.warning(f'🔍 DOMWatchdog.on_BrowserStateRequestEvent: Screenshot overlay failed: {e}')-# Ensure we have valid contentif not content:content = SerializedDOMState(_root=None, selector_map={})