Spaces:
Runtime error
Runtime error
Download src/browser/custom_browser.py from katiue/browser-use-webui: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/katiue/browser-use-webui/resolve/main/src/browser/custom_browser.py
- Command line
-
hf download hf://spaces/katiue/browser-use-webui/src/browser/custom_browser.py
-
curl -L -o custom_browser.py https://huggingface.co/spaces/katiue/browser-use-webui/resolve/main/src/browser/custom_browser.py
1.18 kB
| # -*- coding: utf-8 -*- | |
| # @Time : 2025/1/2 | |
| # @Author : wenshao | |
| # @ProjectName: browser-use-webui | |
| # @FileName: custom_browser.py | |
| import logging | |
| from browser_use.browser.browser import Browser, BrowserConfig | |
| from browser_use.browser.context import BrowserContextConfig, BrowserContext | |
| from .custom_context import CustomBrowserContext | |
| logger = logging.getLogger(__name__) | |
| class CustomBrowser(Browser): | |
| async def new_context( | |
| self, | |
| config: BrowserContextConfig = BrowserContextConfig(), | |
| context=None | |
| ) -> BrowserContext: | |
| """Create a browser context with custom implementation""" | |
| # First get/create the underlying Playwright browser | |
| playwright_browser = await self.get_playwright_browser() | |
| return CustomBrowserContext( | |
| browser=self, # Pass self instead of playwright browser | |
| config=config, | |
| context=context | |
| ) | |
| async def get_playwright_browser(self): | |
| """Ensure we have a Playwright browser instance""" | |
| if not self.playwright_browser: | |
| await self._init() | |
| return self.playwright_browser | |