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
Linter
Magnus Müller0fd93c6c97ff
diff --git a/browser_use/code_use/namespace.py b/browser_use/code_use/namespace.pyindex c054fa327..58bc1784b 100644--- a/browser_use/code_use/namespace.py+++ b/browser_use/code_use/namespace.py@@ -24,42 +24,42 @@ logger = logging.getLogger(__name__)# Try to import optional data science librariestry:- import numpy as np+ import numpy as np # type: ignoreNUMPY_AVAILABLE = Trueexcept ImportError:NUMPY_AVAILABLE = Falsetry:- import pandas as pd+ import pandas as pd # type: ignorePANDAS_AVAILABLE = Trueexcept ImportError:PANDAS_AVAILABLE = Falsetry:- import matplotlib.pyplot as plt+ import matplotlib.pyplot as plt # type: ignoreMATPLOTLIB_AVAILABLE = Trueexcept ImportError:MATPLOTLIB_AVAILABLE = Falsetry:- from bs4 import BeautifulSoup+ from bs4 import BeautifulSoup # type: ignoreBS4_AVAILABLE = Trueexcept ImportError:BS4_AVAILABLE = Falsetry:- from pypdf import PdfReader+ from pypdf import PdfReader # type: ignorePYPDF_AVAILABLE = Trueexcept ImportError:PYPDF_AVAILABLE = Falsetry:- from tabulate import tabulate+ from tabulate import tabulate # type: ignoreTABULATE_AVAILABLE = Trueexcept ImportError:diff --git a/browser_use/code_use/service.py b/browser_use/code_use/service.pyindex f1d5cc365..dff2f199d 100644--- a/browser_use/code_use/service.py+++ b/browser_use/code_use/service.py@@ -83,7 +83,7 @@ class CodeAgent:task: The task description for the agentbrowser_session: Optional browser session (will be created if not provided) [DEPRECATED: use browser]browser: Optional browser session (cleaner API)- tools: Optional Tools instance (will create default if not provided)+ tools: Optional Tools instance (will create default if not provided)controller: Optional Tools instancepage_extraction_llm: Optional LLM for page extractionfile_system: Optional file system for file operations@@ -109,8 +109,8 @@ class CodeAgent:logger.debug('CodeAgent using ChatBrowserUse')except Exception as e:raise RuntimeError(f'Failed to initialize CodeAgent LLM: {e}')-- if "ChatBrowserUse" not in llm.__class__.__name__:++ if 'ChatBrowserUse' not in llm.__class__.__name__:raise ValueError('This agent works only with ChatBrowserUse.')# Handle browser vs browser_session parameter (browser takes precedence)diff --git a/examples/code_use_extract_products.py b/examples/code_use_extract_products.pyindex 8b9c00926..e00595b82 100644--- a/examples/code_use_extract_products.py+++ b/examples/code_use_extract_products.py@@ -16,18 +16,15 @@ was difficult with the extract tool alone."""import asyncio-from pathlib import Pathfrom lmnr import Laminar-from browser_use.code_use import CodeAgent, export_to_ipynb, session_to_python_script+from browser_use.code_use import CodeAgent, export_to_ipynbLaminar.initialize()async def main():--task = """Go to https://www.flipkart.com. Continue collecting products from Flipkart in the following categories. I need approximately 50 products from:\n\n1. Books & Media (books, stationery) - 15 products\n2. Sports & Fitness (equipment, clothing, accessories) - 15 products \n3. Beauty & Personal Care (cosmetics, skincare, grooming) - 10 products\nAnd 2 other categories you find interesting.\nNavigate to these categories and collect products with:\n- Product URL (working link)\n- Product name/description\n- Actual price (MRP)\n- Deal price (current selling price) \n- Discount percentage\n\nFocus on products with good discounts and clear pricing. Target around 40 products total from these three categories.