Skip to content

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

Linter

Magnus Müller0fd93c6c97ff
diff --git a/browser_use/code_use/namespace.py b/browser_use/code_use/namespace.py
index 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 libraries
try:
- import numpy as np
+ import numpy as np # type: ignore
NUMPY_AVAILABLE = True
except ImportError:
NUMPY_AVAILABLE = False
try:
- import pandas as pd
+ import pandas as pd # type: ignore
PANDAS_AVAILABLE = True
except ImportError:
PANDAS_AVAILABLE = False
try:
- import matplotlib.pyplot as plt
+ import matplotlib.pyplot as plt # type: ignore
MATPLOTLIB_AVAILABLE = True
except ImportError:
MATPLOTLIB_AVAILABLE = False
try:
- from bs4 import BeautifulSoup
+ from bs4 import BeautifulSoup # type: ignore
BS4_AVAILABLE = True
except ImportError:
BS4_AVAILABLE = False
try:
- from pypdf import PdfReader
+ from pypdf import PdfReader # type: ignore
PYPDF_AVAILABLE = True
except ImportError:
PYPDF_AVAILABLE = False
try:
- from tabulate import tabulate
+ from tabulate import tabulate # type: ignore
TABULATE_AVAILABLE = True
except ImportError:
diff --git a/browser_use/code_use/service.py b/browser_use/code_use/service.py
index 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 agent
browser_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 instance
page_extraction_llm: Optional LLM for page extraction
file_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.py
index 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 Path
from 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_ipynb
Laminar.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.