Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- src/browser/custom_browser.py +44 -12
- src/browser/custom_context.py +10 -3
src/browser/custom_browser.py
CHANGED
|
@@ -12,7 +12,7 @@ from playwright.async_api import (
|
|
| 12 |
async_playwright,
|
| 13 |
)
|
| 14 |
|
| 15 |
-
# Import browser_use components with error handling
|
| 16 |
try:
|
| 17 |
from browser_use.browser.browser import Browser, IN_DOCKER
|
| 18 |
from browser_use.browser.context import BrowserContext, BrowserContextConfig
|
|
@@ -29,19 +29,51 @@ except ImportError as e:
|
|
| 29 |
# Fallback for different browser_use versions
|
| 30 |
logger = logging.getLogger(__name__)
|
| 31 |
logger.warning(f"Failed to import browser_use components: {e}")
|
|
|
|
| 32 |
# Set default values
|
| 33 |
IN_DOCKER = False
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
from .custom_context import CustomBrowserContext
|
| 47 |
|
|
|
|
| 12 |
async_playwright,
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# Import browser_use components with comprehensive error handling
|
| 16 |
try:
|
| 17 |
from browser_use.browser.browser import Browser, IN_DOCKER
|
| 18 |
from browser_use.browser.context import BrowserContext, BrowserContextConfig
|
|
|
|
| 29 |
# Fallback for different browser_use versions
|
| 30 |
logger = logging.getLogger(__name__)
|
| 31 |
logger.warning(f"Failed to import browser_use components: {e}")
|
| 32 |
+
|
| 33 |
# Set default values
|
| 34 |
IN_DOCKER = False
|
| 35 |
+
|
| 36 |
+
# Try to import basic components
|
| 37 |
+
try:
|
| 38 |
+
from browser_use.browser.browser import Browser
|
| 39 |
+
from browser_use.browser.context import BrowserContext, BrowserContextConfig
|
| 40 |
+
except ImportError:
|
| 41 |
+
logger.error("Could not import basic browser_use components")
|
| 42 |
+
raise
|
| 43 |
+
|
| 44 |
+
# Try to import chrome components with fallbacks
|
| 45 |
+
try:
|
| 46 |
+
from browser_use.browser.chrome import (
|
| 47 |
+
CHROME_ARGS,
|
| 48 |
+
CHROME_DETERMINISTIC_RENDERING_ARGS,
|
| 49 |
+
CHROME_DISABLE_SECURITY_ARGS,
|
| 50 |
+
CHROME_DOCKER_ARGS,
|
| 51 |
+
CHROME_HEADLESS_ARGS,
|
| 52 |
+
)
|
| 53 |
+
except ImportError:
|
| 54 |
+
logger.warning("Could not import chrome components, using defaults")
|
| 55 |
+
CHROME_ARGS = []
|
| 56 |
+
CHROME_DETERMINISTIC_RENDERING_ARGS = []
|
| 57 |
+
CHROME_DISABLE_SECURITY_ARGS = []
|
| 58 |
+
CHROME_DOCKER_ARGS = []
|
| 59 |
+
CHROME_HEADLESS_ARGS = []
|
| 60 |
+
|
| 61 |
+
# Try to import utility functions with fallbacks
|
| 62 |
+
try:
|
| 63 |
+
from browser_use.browser.utils.screen_resolution import get_screen_resolution, get_window_adjustments
|
| 64 |
+
except ImportError:
|
| 65 |
+
logger.warning("Could not import screen resolution utilities, using defaults")
|
| 66 |
+
def get_screen_resolution():
|
| 67 |
+
return {'width': 1920, 'height': 1080}
|
| 68 |
+
def get_window_adjustments():
|
| 69 |
+
return 0, 0
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
from browser_use.utils import time_execution_async
|
| 73 |
+
except ImportError:
|
| 74 |
+
logger.warning("Could not import time_execution_async, using dummy function")
|
| 75 |
+
def time_execution_async(func):
|
| 76 |
+
return func
|
| 77 |
|
| 78 |
from .custom_context import CustomBrowserContext
|
| 79 |
|
src/browser/custom_context.py
CHANGED
|
@@ -2,7 +2,7 @@ import json
|
|
| 2 |
import logging
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Import browser_use components with error handling
|
| 6 |
try:
|
| 7 |
from browser_use.browser.browser import Browser, IN_DOCKER
|
| 8 |
from browser_use.browser.context import BrowserContext, BrowserContextConfig, BrowserContextState
|
|
@@ -10,10 +10,17 @@ except ImportError as e:
|
|
| 10 |
# Fallback for different browser_use versions
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
logger.warning(f"Failed to import browser_use components: {e}")
|
|
|
|
| 13 |
# Set default values
|
| 14 |
IN_DOCKER = False
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
from playwright.async_api import Browser as PlaywrightBrowser
|
| 19 |
from playwright.async_api import BrowserContext as PlaywrightBrowserContext
|
|
|
|
| 2 |
import logging
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Import browser_use components with comprehensive error handling
|
| 6 |
try:
|
| 7 |
from browser_use.browser.browser import Browser, IN_DOCKER
|
| 8 |
from browser_use.browser.context import BrowserContext, BrowserContextConfig, BrowserContextState
|
|
|
|
| 10 |
# Fallback for different browser_use versions
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
logger.warning(f"Failed to import browser_use components: {e}")
|
| 13 |
+
|
| 14 |
# Set default values
|
| 15 |
IN_DOCKER = False
|
| 16 |
+
|
| 17 |
+
# Try to import basic components
|
| 18 |
+
try:
|
| 19 |
+
from browser_use.browser.browser import Browser
|
| 20 |
+
from browser_use.browser.context import BrowserContext, BrowserContextConfig, BrowserContextState
|
| 21 |
+
except ImportError:
|
| 22 |
+
logger.error("Could not import basic browser_use components")
|
| 23 |
+
raise
|
| 24 |
|
| 25 |
from playwright.async_api import Browser as PlaywrightBrowser
|
| 26 |
from playwright.async_api import BrowserContext as PlaywrightBrowserContext
|