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 print
Magnus Müllerc1331604c7f6
diff --git a/browser_use/dom/debug/highlights.py b/browser_use/dom/debug/highlights.pyindex 8e8a4893b..33beba22e 100644--- a/browser_use/dom/debug/highlights.py+++ b/browser_use/dom/debug/highlights.py@@ -1,11 +1,14 @@# 100% vibe codedimport json+import loggingimport tracebackfrom browser_use.dom.service import DomServicefrom browser_use.dom.views import DOMSelectorMap+logger = logging.getLogger(__name__)+def convert_dom_selector_map_to_highlight_format(selector_map: DOMSelectorMap) -> list[dict]:"""Convert DOMSelectorMap to the format expected by the highlighting script."""@@ -55,7 +58,7 @@ async def remove_highlighting_script(dom_service: DomService) -> None:# Get CDP client and session IDcdp_session = await dom_service.browser_session.get_or_create_cdp_session()- print('🧹 Removing browser-use highlighting elements')+ logger.debug('🧹 Removing browser-use highlighting elements')# Create script to remove all highlightsscript = """@@ -82,24 +85,22 @@ async def remove_highlighting_script(dom_service: DomService) -> None:await cdp_session.cdp_client.send.Runtime.evaluate(params={'expression': script, 'returnByValue': True}, session_id=cdp_session.session_id)- print('✅ All browser-use highlighting elements removed')except Exception as e:- print(f'❌ Error removing highlighting elements: {e}')- traceback.print_exc()+ traceback.logger.debug_exc()async def inject_highlighting_script(dom_service: DomService, interactive_elements: DOMSelectorMap) -> None:"""Inject JavaScript to highlight interactive elements with detailed hover tooltips that work around CSP restrictions."""if not interactive_elements:- print('⚠️ No interactive elements to highlight')+ logger.debug('⚠️ No interactive elements to highlight')returntry:# Convert DOMSelectorMap to the format expected by the JavaScriptconverted_elements = convert_dom_selector_map_to_highlight_format(interactive_elements)- print(f'📍 Creating CSP-safe highlighting for {len(converted_elements)} elements')+ logger.debug(f'📍 Creating CSP-safe highlighting for {len(converted_elements)} elements')# ALWAYS remove any existing highlights first to prevent double-highlightingawait remove_highlighting_script(dom_service)@@ -387,7 +388,7 @@ async def inject_highlighting_script(dom_service: DomService, interactive_elemen// Add container to documentdocument.body.appendChild(container);- console.log('✅ Browser-use highlighting complete');+ console.log('Highlighting complete');}})();"""@@ -397,8 +398,8 @@ async def inject_highlighting_script(dom_service: DomService, interactive_elemenawait cdp_session.cdp_client.send.Runtime.evaluate(params={'expression': script, 'returnByValue': True}, session_id=cdp_session.session_id)- print(f'✅ Enhanced CSP-safe highlighting injected for {len(converted_elements)} elements')+ logger.debug(f'Enhanced CSP-safe highlighting injected for {len(converted_elements)} elements')except Exception as e:- print(f'❌ Error injecting enhanced highlighting script: {e}')+ logger.debug(f'❌ Error injecting enhanced highlighting script: {e}')traceback.print_exc()diff --git a/browser_use/tokens/service.py b/browser_use/tokens/service.pyindex aab1aa0e4..80932f6dc 100644--- a/browser_use/tokens/service.py+++ b/browser_use/tokens/service.py@@ -130,7 +130,7 @@ class TokenCost:cached = CachedPricingData.model_validate_json(content)self._pricing_data = cached.dataexcept Exception as e:- print(f'Error loading cached pricing data from {cache_file}: {e}')+ logger.debug(f'Error loading cached pricing data from {cache_file}: {e}')# Fall back to fetchingawait self._fetch_and_cache_pricing_data()@@ -157,7 +157,7 @@ class TokenCost:await f.write(cached.model_dump_json(indent=2))except Exception as e:- print(f'Error fetching pricing data: {e}')+ logger.debug(f'Error fetching pricing data: {e}')# Fall back to empty pricing dataself._pricing_data = {}@@ -559,7 +559,7 @@ class TokenCost:except Exception:passexcept Exception as e:- print(f'Error cleaning old cache files: {e}')+ logger.debug(f'Error cleaning old cache files: {e}')async def ensure_pricing_loaded(self) -> None:"""Ensure pricing data is loaded in the background. Call this after creating the service."""