mirror of
https://github.com/browser-use/browser-use
synced 2026-05-06 17:52:15 +02:00
75 lines
1.9 KiB
Python
75 lines
1.9 KiB
Python
import os
|
|
|
|
from browser_use.logging_config import setup_logging
|
|
|
|
# Only set up logging if not in MCP mode or if explicitly requested
|
|
if os.environ.get('BROWSER_USE_SETUP_LOGGING', 'true').lower() != 'false':
|
|
logger = setup_logging()
|
|
else:
|
|
import logging
|
|
|
|
logger = logging.getLogger('browser_use')
|
|
|
|
# Monkeypatch BaseSubprocessTransport.__del__ to handle closed event loops gracefully
|
|
from asyncio import base_subprocess
|
|
|
|
from browser_use.agent.prompts import SystemPrompt
|
|
from browser_use.agent.service import Agent
|
|
from browser_use.agent.views import ActionModel, ActionResult, AgentHistoryList
|
|
from browser_use.browser import Browser, BrowserConfig, BrowserContext, BrowserContextConfig, BrowserProfile, BrowserSession
|
|
from browser_use.controller.service import Controller
|
|
from browser_use.dom.service import DomService
|
|
from browser_use.llm import (
|
|
ChatAnthropic,
|
|
ChatAzureOpenAI,
|
|
ChatGoogle,
|
|
ChatGroq,
|
|
ChatOllama,
|
|
ChatOpenAI,
|
|
)
|
|
|
|
_original_del = base_subprocess.BaseSubprocessTransport.__del__
|
|
|
|
|
|
def _patched_del(self):
|
|
"""Patched __del__ that handles closed event loops without throwing noisy red-herring errors like RuntimeError: Event loop is closed"""
|
|
try:
|
|
# Check if the event loop is closed before calling the original
|
|
if hasattr(self, '_loop') and self._loop and self._loop.is_closed():
|
|
# Event loop is closed, skip cleanup that requires the loop
|
|
return
|
|
_original_del(self)
|
|
except RuntimeError as e:
|
|
if 'Event loop is closed' in str(e):
|
|
# Silently ignore this specific error
|
|
pass
|
|
else:
|
|
raise
|
|
|
|
|
|
base_subprocess.BaseSubprocessTransport.__del__ = _patched_del
|
|
|
|
|
|
__all__ = [
|
|
'Agent',
|
|
'Browser',
|
|
'BrowserConfig',
|
|
'BrowserSession',
|
|
'BrowserProfile',
|
|
'Controller',
|
|
'DomService',
|
|
'SystemPrompt',
|
|
'ActionResult',
|
|
'ActionModel',
|
|
'AgentHistoryList',
|
|
'BrowserContext',
|
|
'BrowserContextConfig',
|
|
# Chat models
|
|
'ChatOpenAI',
|
|
'ChatGoogle',
|
|
'ChatAnthropic',
|
|
'ChatGroq',
|
|
'ChatAzureOpenAI',
|
|
'ChatOllama',
|
|
]
|