mirror of
https://github.com/browser-use/web-ui.git
synced 2026-03-22 03:07:54 +08:00
19
Dockerfile
19
Dockerfile
@@ -67,24 +67,23 @@ WORKDIR /app
|
||||
|
||||
# Copy requirements and install Python dependencies
|
||||
COPY requirements.txt .
|
||||
# Ensure 'patchright' is in your requirements.txt or install it directly
|
||||
# RUN pip install --no-cache-dir -r requirements.txt patchright # If not in requirements
|
||||
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Install Patchright browsers and dependencies
|
||||
# Patchright documentation suggests PLAYWRIGHT_BROWSERS_PATH is still relevant
|
||||
# or that Patchright installs to a similar default location that Playwright would.
|
||||
# Let's assume Patchright respects PLAYWRIGHT_BROWSERS_PATH or its default install location is findable.
|
||||
# Install playwright browsers and dependencies
|
||||
# playwright documentation suggests PLAYWRIGHT_BROWSERS_PATH is still relevant
|
||||
# or that playwright installs to a similar default location that Playwright would.
|
||||
# Let's assume playwright respects PLAYWRIGHT_BROWSERS_PATH or its default install location is findable.
|
||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-browsers
|
||||
RUN mkdir -p $PLAYWRIGHT_BROWSERS_PATH
|
||||
|
||||
# Install recommended: Google Chrome (instead of just Chromium for better undetectability)
|
||||
# The 'patchright install chrome' command might download and place it.
|
||||
# The '--with-deps' equivalent for patchright install is to run 'patchright install-deps chrome' after.
|
||||
# RUN patchright install chrome --with-deps
|
||||
# The 'playwright install chrome' command might download and place it.
|
||||
# The '--with-deps' equivalent for playwright install is to run 'playwright install-deps chrome' after.
|
||||
# RUN playwright install chrome --with-deps
|
||||
|
||||
# Alternative: Install Chromium if Google Chrome is problematic in certain environments
|
||||
RUN patchright install chromium --with-deps
|
||||
RUN playwright install chromium --with-deps
|
||||
|
||||
|
||||
# Copy the application code
|
||||
|
||||
@@ -61,13 +61,13 @@ Install Python packages:
|
||||
uv pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Install Browsers in Patchright.
|
||||
Install Browsers in playwright.
|
||||
```bash
|
||||
patchright install --with-deps
|
||||
playwright install --with-deps
|
||||
```
|
||||
Or you can install specific browsers by running:
|
||||
```bash
|
||||
patchright install chromium --with-deps
|
||||
playwright install chromium --with-deps
|
||||
```
|
||||
|
||||
#### Step 4: Configure Environment
|
||||
|
||||
@@ -54,7 +54,7 @@ services:
|
||||
|
||||
# Display Settings
|
||||
- DISPLAY=:99
|
||||
# This ENV is used by the Dockerfile during build time if Patchright respects it.
|
||||
# This ENV is used by the Dockerfile during build time if playwright respects it.
|
||||
# It's not strictly needed at runtime by docker-compose unless your app or scripts also read it.
|
||||
- PLAYWRIGHT_BROWSERS_PATH=/ms-browsers # Matches Dockerfile ENV
|
||||
- RESOLUTION=${RESOLUTION:-1920x1080x24}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
browser-use==0.1.45
|
||||
browser-use==0.1.47
|
||||
pyperclip==1.9.0
|
||||
gradio==5.27.0
|
||||
json-repair
|
||||
|
||||
@@ -15,9 +15,6 @@ from browser_use.agent.views import (
|
||||
ToolCallingMethod,
|
||||
)
|
||||
from browser_use.browser.views import BrowserStateHistory
|
||||
from browser_use.telemetry.views import (
|
||||
AgentEndTelemetryEvent,
|
||||
)
|
||||
from browser_use.utils import time_execution_async
|
||||
from dotenv import load_dotenv
|
||||
from browser_use.agent.message_manager.utils import is_model_without_tool_support
|
||||
@@ -144,19 +141,6 @@ class BrowserUseAgent(Agent):
|
||||
# Unregister signal handlers before cleanup
|
||||
signal_handler.unregister()
|
||||
|
||||
self.telemetry.capture(
|
||||
AgentEndTelemetryEvent(
|
||||
agent_id=self.state.agent_id,
|
||||
is_done=self.state.history.is_done(),
|
||||
success=self.state.history.is_successful(),
|
||||
steps=self.state.n_steps,
|
||||
max_steps_reached=self.state.n_steps >= max_steps,
|
||||
errors=self.state.history.errors(),
|
||||
total_input_tokens=self.state.history.total_input_tokens(),
|
||||
total_duration_seconds=self.state.history.total_duration_seconds(),
|
||||
)
|
||||
)
|
||||
|
||||
if self.settings.save_playwright_script_path:
|
||||
logger.info(
|
||||
f'Agent run finished. Attempting to save Playwright script to: {self.settings.save_playwright_script_path}'
|
||||
|
||||
@@ -81,7 +81,7 @@ async def run_single_browser_task(
|
||||
bu_browser_context = None
|
||||
try:
|
||||
logger.info(f"Starting browser task for query: {task_query}")
|
||||
extra_args = [f"--window-size={window_w},{window_h}"]
|
||||
extra_args = []
|
||||
if use_own_browser:
|
||||
browser_binary_path = os.getenv("BROWSER_PATH", None) or browser_binary_path
|
||||
if browser_binary_path == "":
|
||||
@@ -99,6 +99,10 @@ async def run_single_browser_task(
|
||||
extra_browser_args=extra_args,
|
||||
wss_url=wss_url,
|
||||
cdp_url=cdp_url,
|
||||
new_context_config=BrowserContextConfig(
|
||||
window_width=window_w,
|
||||
window_height=window_h,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import asyncio
|
||||
import pdb
|
||||
|
||||
from patchright.async_api import Browser as PlaywrightBrowser
|
||||
from patchright.async_api import (
|
||||
from playwright.async_api import Browser as PlaywrightBrowser
|
||||
from playwright.async_api import (
|
||||
BrowserContext as PlaywrightBrowserContext,
|
||||
)
|
||||
from patchright.async_api import (
|
||||
from playwright.async_api import (
|
||||
Playwright,
|
||||
async_playwright,
|
||||
)
|
||||
from browser_use.browser.browser import Browser, IN_DOCKER
|
||||
from browser_use.browser.context import BrowserContext, BrowserContextConfig
|
||||
from patchright.async_api import BrowserContext as PlaywrightBrowserContext
|
||||
from playwright.async_api import BrowserContext as PlaywrightBrowserContext
|
||||
import logging
|
||||
|
||||
from browser_use.browser.chrome import (
|
||||
@@ -48,9 +48,13 @@ class CustomBrowser(Browser):
|
||||
if (
|
||||
not self.config.headless
|
||||
and hasattr(self.config, 'new_context_config')
|
||||
and hasattr(self.config.new_context_config, 'browser_window_size')
|
||||
and hasattr(self.config.new_context_config, 'window_width')
|
||||
and hasattr(self.config.new_context_config, 'window_height')
|
||||
):
|
||||
screen_size = self.config.new_context_config.browser_window_size.model_dump()
|
||||
screen_size = {
|
||||
'width': self.config.new_context_config.window_width,
|
||||
'height': self.config.new_context_config.window_height,
|
||||
}
|
||||
offset_x, offset_y = get_window_adjustments()
|
||||
elif self.config.headless:
|
||||
screen_size = {'width': 1920, 'height': 1080}
|
||||
@@ -67,17 +71,12 @@ class CustomBrowser(Browser):
|
||||
*(CHROME_DISABLE_SECURITY_ARGS if self.config.disable_security else []),
|
||||
*(CHROME_DETERMINISTIC_RENDERING_ARGS if self.config.deterministic_rendering else []),
|
||||
f'--window-position={offset_x},{offset_y}',
|
||||
f'--window-size={screen_size["width"]},{screen_size["height"]}',
|
||||
*self.config.extra_browser_args,
|
||||
}
|
||||
contain_window_size = False
|
||||
for arg in self.config.extra_browser_args:
|
||||
if "--window-size" in arg:
|
||||
contain_window_size = True
|
||||
break
|
||||
if not contain_window_size:
|
||||
chrome_args.add(f'--window-size={screen_size["width"]},{screen_size["height"]}')
|
||||
|
||||
# check if port 9222 is already taken, if so remove the remote-debugging-port arg to prevent conflicts
|
||||
# check if chrome remote debugging port is already taken,
|
||||
# if so remove the remote-debugging-port arg to prevent conflicts
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
if s.connect_ex(('localhost', self.config.chrome_remote_debugging_port)) == 0:
|
||||
chrome_args.remove(f'--remote-debugging-port={self.config.chrome_remote_debugging_port}')
|
||||
@@ -100,6 +99,7 @@ class CustomBrowser(Browser):
|
||||
}
|
||||
|
||||
browser = await browser_class.launch(
|
||||
channel='chromium', # https://github.com/microsoft/playwright/issues/33566
|
||||
headless=self.config.headless,
|
||||
args=args[self.config.browser_class],
|
||||
proxy=self.config.proxy.model_dump() if self.config.proxy else None,
|
||||
|
||||
@@ -4,8 +4,8 @@ import os
|
||||
|
||||
from browser_use.browser.browser import Browser, IN_DOCKER
|
||||
from browser_use.browser.context import BrowserContext, BrowserContextConfig
|
||||
from patchright.async_api import Browser as PlaywrightBrowser
|
||||
from patchright.async_api import BrowserContext as PlaywrightBrowserContext
|
||||
from playwright.async_api import Browser as PlaywrightBrowser
|
||||
from playwright.async_api import BrowserContext as PlaywrightBrowserContext
|
||||
from typing import Optional
|
||||
from browser_use.browser.context import BrowserContextState
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ async def run_agent_task(
|
||||
# Create Browser if needed
|
||||
if not webui_manager.bu_browser:
|
||||
logger.info("Launching new browser instance.")
|
||||
extra_args = [f"--window-size={window_w},{window_h}"]
|
||||
extra_args = []
|
||||
if use_own_browser:
|
||||
browser_binary_path = os.getenv("BROWSER_PATH", None) or browser_binary_path
|
||||
if browser_binary_path == "":
|
||||
@@ -469,6 +469,10 @@ async def run_agent_task(
|
||||
extra_browser_args=extra_args,
|
||||
wss_url=wss_url,
|
||||
cdp_url=cdp_url,
|
||||
new_context_config=BrowserContextConfig(
|
||||
window_width=window_w,
|
||||
window_height=window_h,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -29,21 +29,19 @@ async def test_browser_use_agent():
|
||||
from src.utils import llm_provider
|
||||
from src.agent.browser_use.browser_use_agent import BrowserUseAgent
|
||||
|
||||
# llm = utils.get_llm_model(
|
||||
# provider="openai",
|
||||
# model_name="gpt-4o",
|
||||
# temperature=0.8,
|
||||
# base_url=os.getenv("OPENAI_ENDPOINT", ""),
|
||||
# api_key=os.getenv("OPENAI_API_KEY", ""),
|
||||
# )
|
||||
|
||||
llm = llm_provider.get_llm_model(
|
||||
provider="google",
|
||||
model_name="gemini-2.0-flash",
|
||||
temperature=0.6,
|
||||
api_key=os.getenv("GOOGLE_API_KEY", "")
|
||||
provider="openai",
|
||||
model_name="gpt-4o",
|
||||
temperature=0.8,
|
||||
)
|
||||
|
||||
# llm = llm_provider.get_llm_model(
|
||||
# provider="google",
|
||||
# model_name="gemini-2.0-flash",
|
||||
# temperature=0.6,
|
||||
# api_key=os.getenv("GOOGLE_API_KEY", "")
|
||||
# )
|
||||
|
||||
# llm = utils.get_llm_model(
|
||||
# provider="deepseek",
|
||||
# model_name="deepseek-reasoner",
|
||||
@@ -104,7 +102,7 @@ async def test_browser_use_agent():
|
||||
browser_context = None
|
||||
|
||||
try:
|
||||
extra_browser_args = [f"--window-size={window_w},{window_h}"]
|
||||
extra_browser_args = []
|
||||
if use_own_browser:
|
||||
browser_binary_path = os.getenv("BROWSER_PATH", None)
|
||||
if browser_binary_path == "":
|
||||
@@ -119,6 +117,10 @@ async def test_browser_use_agent():
|
||||
headless=False,
|
||||
browser_binary_path=browser_binary_path,
|
||||
extra_browser_args=extra_browser_args,
|
||||
new_context_config=BrowserContextConfig(
|
||||
window_width=window_w,
|
||||
window_height=window_h,
|
||||
)
|
||||
)
|
||||
)
|
||||
browser_context = await browser.new_context(
|
||||
@@ -256,7 +258,7 @@ async def test_browser_use_parallel():
|
||||
browser_context = None
|
||||
|
||||
try:
|
||||
extra_browser_args = [f"--window-size={window_w},{window_h}"]
|
||||
extra_browser_args = []
|
||||
if use_own_browser:
|
||||
browser_binary_path = os.getenv("BROWSER_PATH", None)
|
||||
if browser_binary_path == "":
|
||||
@@ -271,6 +273,10 @@ async def test_browser_use_parallel():
|
||||
headless=False,
|
||||
browser_binary_path=browser_binary_path,
|
||||
extra_browser_args=extra_browser_args,
|
||||
new_context_config=BrowserContextConfig(
|
||||
window_width=window_w,
|
||||
window_height=window_h,
|
||||
)
|
||||
)
|
||||
)
|
||||
browser_context = await browser.new_context(
|
||||
|
||||
@@ -6,7 +6,7 @@ load_dotenv()
|
||||
|
||||
def test_connect_browser():
|
||||
import os
|
||||
from patchright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
chrome_exe = os.getenv("CHROME_PATH", "")
|
||||
chrome_use_data = os.getenv("CHROME_USER_DATA", "")
|
||||
|
||||
Reference in New Issue
Block a user