Spaces:
Running
Running
File size: 1,177 Bytes
c13f7a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# -*- 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
|