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
linting fixes
Saurav Panda1e13c0e03f2c
diff --git a/.gitignore b/.gitignoreindex 9ea402407..8e65ffa4f 100644--- a/.gitignore+++ b/.gitignore@@ -49,4 +49,4 @@ tmp# Google API credentialscredentials.json-token.json\ No newline at end of file+token.jsondiff --git a/browser_use/integrations/gmail/__init__.py b/browser_use/integrations/gmail/__init__.pyindex 4f9d46525..0fbfac3d5 100644--- a/browser_use/integrations/gmail/__init__.py+++ b/browser_use/integrations/gmail/__init__.py@@ -21,4 +21,4 @@ Usage:from .actions import register_gmail_actionsfrom .service import GmailService-__all__ = ['GmailService', 'register_gmail_actions']\ No newline at end of file+__all__ = ['GmailService', 'register_gmail_actions']diff --git a/browser_use/integrations/gmail/actions.py b/browser_use/integrations/gmail/actions.pyindex 8ac9d0907..7225d86e3 100644--- a/browser_use/integrations/gmail/actions.py+++ b/browser_use/integrations/gmail/actions.py@@ -6,7 +6,6 @@ email reading, and authentication management.import asyncioimport logging-from typing import List, Optionalfrom pydantic import BaseModel, Field@@ -18,15 +17,15 @@ from .service import GmailServicelogger = logging.getLogger(__name__)# Global Gmail service instance - initialized when actions are registered-_gmail_service: Optional[GmailService] = None+_gmail_service: GmailService | None = Noneclass Find2FACodesParams(BaseModel):"""Parameters for finding 2FA codes in emails"""time_filter: str = Field(default='2m', description='Time filter for emails (e.g., "2m", "5m", "1h", "1d")')- sender_email: Optional[str] = Field(default=None, description='Filter by specific sender email address')- custom_patterns: Optional[List[str]] = Field(default=None, description='Additional regex patterns to search for codes')+ sender_email: str | None = Field(default=None, description='Filter by specific sender email address')+ custom_patterns: list[str] | None = Field(default=None, description='Additional regex patterns to search for codes')class GetRecentEmailsParams(BaseModel):@@ -38,7 +37,7 @@ class GetRecentEmailsParams(BaseModel):def register_gmail_actions(- controller: Controller, gmail_service: Optional[GmailService] = None, access_token: Optional[str] = None+ controller: Controller, gmail_service: GmailService | None = None, access_token: str | None = None) -> None:"""Register Gmail actions with the provided controller@@ -229,4 +228,4 @@ def register_gmail_actions(except Exception as e:logger.error(f'Error authenticating Gmail: {e}')- return ActionResult(extracted_content=f'❌ Error authenticating with Gmail: {str(e)}', include_in_memory=True)\ No newline at end of file+ return ActionResult(extracted_content=f'❌ Error authenticating with Gmail: {str(e)}', include_in_memory=True)diff --git a/browser_use/integrations/gmail/service.py b/browser_use/integrations/gmail/service.pyindex fdd4fa0eb..69e07f504 100644--- a/browser_use/integrations/gmail/service.py+++ b/browser_use/integrations/gmail/service.py@@ -9,7 +9,7 @@ import loggingimport osimport refrom pathlib import Path-from typing import Any, Dict, List, Optional+from typing import Anyimport aiofilesfrom google.auth.transport.requests import Request@@ -38,10 +38,10 @@ class GmailService:def __init__(self,- credentials_file: Optional[str] = None,- token_file: Optional[str] = None,- config_dir: Optional[str] = None,- access_token: Optional[str] = None,+ credentials_file: str | None = None,+ token_file: str | None = None,+ config_dir: str | None = None,+ access_token: str | None = None,):"""Initialize Gmail Service@@ -139,7 +139,7 @@ class GmailService:logger.error(f'❌ Gmail authentication failed: {e}')return False- async def get_recent_emails(self, max_results: int = 10, query: str = '', time_filter: str = '1h') -> List[Dict[str, Any]]:+ async def get_recent_emails(self, max_results: int = 10, query: str = '', time_filter: str = '1h') -> list[dict[str, Any]]:"""Get recent emails with optional query filterArgs:@@ -192,7 +192,7 @@ class GmailService:logger.error(f'❌ Unexpected error fetching emails: {e}')return []- def _parse_email(self, message: Dict[str, Any]) -> Dict[str, Any]:+ def _parse_email(self, message: dict[str, Any]) -> dict[str, Any]:"""Parse Gmail message into readable format"""headers = {h['name']: h['value'] for h in message['payload']['headers']}@@ -208,7 +208,7 @@ class GmailService:'raw_message': message,}- def _extract_body(self, payload: Dict[str, Any]) -> str:+ def _extract_body(self, payload: dict[str, Any]) -> str:"""Extract email body from payload"""body = ''@@ -228,8 +228,8 @@ class GmailService:return bodyasync def find_2fa_codes(- self, time_filter: str = '5m', sender_email: Optional[str] = None, custom_patterns: Optional[List[str]] = None- ) -> List[Dict[str, Any]]:+ self, time_filter: str = '5m', sender_email: str | None = None, custom_patterns: list[str] | None = None+ ) -> list[dict[str, Any]]:"""Find 2FA verification codes in recent emailsArgs:@@ -286,7 +286,7 @@ class GmailService:logger.info(f'🎯 Found {len(filtered_codes)} recent emails with 2FA codes (most recent per sender)')return filtered_codes- def _extract_codes_from_text(self, text: str, custom_patterns: Optional[List[str]] = None) -> List[str]:+ def _extract_codes_from_text(self, text: str, custom_patterns: list[str] | None = None) -> list[str]:"""Extract potential verification codes from text"""if not text:return []diff --git a/eval/service.py b/eval/service.pyindex d0f36b4f4..2167d30ff 100644--- a/eval/service.py+++ b/eval/service.py@@ -867,20 +867,20 @@ def create_controller(use_serp: bool = False, output_model: type[BaseModel] | Nocontroller = create_controller_with_serp_search(output_model=output_model)else:controller = Controller(output_model=output_model)-+# Add Gmail 2FA support if access token is availableif gmail_access_token:try:from browser_use.integrations.gmail import register_gmail_actions-+# Register Gmail actions using the access tokenregister_gmail_actions(controller, access_token=gmail_access_token)-+logger.info('Gmail 2FA integration registered successfully with access token')-+except Exception as e:logger.error(f'Failed to setup Gmail integration: {e}')-+return controller@@ -1401,11 +1401,7 @@ async def run_agent_with_browser() -> tuple[AgentHistoryList, str]:"""Run agent with the browser session"""# Create controller, optionally with SERP search, structured output, and Gmail 2FA support- controller = create_controller(- use_serp=use_serp,- output_model=task.output_model,- gmail_access_token=gmail_access_token- )+ controller = create_controller(use_serp=use_serp, output_model=task.output_model, gmail_access_token=gmail_access_token)# Check for deprecated memory parametersif enable_memory:@@ -2437,7 +2433,12 @@ if __name__ == '__main__':parser.add_argument('--github-workflow-url', type=str, default=None, help='GitHub workflow URL for tracking')# Gmail 2FA support arguments- parser.add_argument('--gmail-2fa-access-token', type=str, default=None, help='Access token for Gmail 2FA Lambda function (enables Gmail 2FA if provided)')+ parser.add_argument(+ '--gmail-2fa-access-token',+ type=str,+ default=None,+ help='Access token for Gmail 2FA Lambda function (enables Gmail 2FA if provided)',+ )# Single task mode argumentsparser.add_argument('--task-text', type=str, default=None, help='Task description for single task mode')diff --git a/examples/integrations/gmail_2fa_integration.py b/examples/integrations/gmail_2fa_integration.pyindex 23c4ce49c..35843c8f6 100644--- a/examples/integrations/gmail_2fa_integration.py+++ b/examples/integrations/gmail_2fa_integration.py@@ -105,4 +105,4 @@ async def main():if __name__ == '__main__':- asyncio.run(main())\ No newline at end of file+ asyncio.run(main())