Skip to content

Commit eef817f

Browse files
committed
Add docker support
1 parent db6348d commit eef817f

File tree

8 files changed

+360
-4
lines changed

8 files changed

+360
-4
lines changed

.env.example

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,17 @@ ANONYMIZED_TELEMETRY=true
1717
# LogLevel: Set to debug to enable verbose logging, set to result to get results only. Available: result | debug | info
1818
BROWSER_USE_LOGGING_LEVEL=info
1919

20+
# Chrome settings
2021
CHROME_PATH=
21-
CHROME_USER_DATA=
22+
CHROME_USER_DATA=
23+
CHROME_DEBUGGING_PORT=9222
24+
CHROME_DEBUGGING_HOST=localhost
25+
CHROME_PERSISTENT_SESSION=false # Set to true to keep browser open between AI tasks
26+
27+
# Display settings
28+
RESOLUTION=1920x1080x24 # Format: WIDTHxHEIGHTxDEPTH
29+
RESOLUTION_WIDTH=1920 # Width in pixels
30+
RESOLUTION_HEIGHT=1080 # Height in pixels
31+
32+
# VNC settings
33+
VNC_PASSWORD=youvncpassword

Dockerfile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
FROM python:3.11-slim
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
wget \
6+
gnupg \
7+
curl \
8+
unzip \
9+
xvfb \
10+
libgconf-2-4 \
11+
libxss1 \
12+
libnss3 \
13+
libnspr4 \
14+
libasound2 \
15+
libatk1.0-0 \
16+
libatk-bridge2.0-0 \
17+
libcups2 \
18+
libdbus-1-3 \
19+
libdrm2 \
20+
libgbm1 \
21+
libgtk-3-0 \
22+
libxcomposite1 \
23+
libxdamage1 \
24+
libxfixes3 \
25+
libxrandr2 \
26+
xdg-utils \
27+
fonts-liberation \
28+
dbus \
29+
xauth \
30+
xvfb \
31+
x11vnc \
32+
tigervnc-tools \
33+
supervisor \
34+
net-tools \
35+
procps \
36+
git \
37+
python3-numpy \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
# Install noVNC
41+
RUN git clone https://github.com/novnc/noVNC.git /opt/novnc \
42+
&& git clone https://github.com/novnc/websockify /opt/novnc/utils/websockify \
43+
&& ln -s /opt/novnc/vnc.html /opt/novnc/index.html
44+
45+
# Install Chrome
46+
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
47+
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
48+
&& apt-get update \
49+
&& apt-get install -y google-chrome-stable \
50+
&& rm -rf /var/lib/apt/lists/*
51+
52+
# Set up working directory
53+
WORKDIR /app
54+
55+
# Copy requirements and install Python dependencies
56+
COPY requirements.txt .
57+
RUN pip install --no-cache-dir -r requirements.txt
58+
59+
# Install Playwright and browsers with system dependencies
60+
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
61+
RUN playwright install --with-deps chromium
62+
RUN playwright install-deps
63+
64+
# Copy the application code
65+
COPY . .
66+
67+
# Set environment variables
68+
ENV PYTHONUNBUFFERED=1
69+
ENV BROWSER_USE_LOGGING_LEVEL=info
70+
ENV CHROME_PATH=/usr/bin/google-chrome
71+
ENV ANONYMIZED_TELEMETRY=false
72+
ENV DISPLAY=:99
73+
ENV RESOLUTION=1920x1080x24
74+
ENV VNC_PASSWORD=vncpassword
75+
76+
# Set up supervisor configuration
77+
RUN mkdir -p /var/log/supervisor
78+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
79+
80+
EXPOSE 7788 6080 5900
81+
82+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

README.md

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,45 @@ We would like to officially thank [WarmShao](https://github.com/warmshao) for hi
1717

1818
**Custom Browser Support:** You can use your own browser with our tool, eliminating the need to re-login to sites or deal with other authentication challenges. This feature also supports high-definition screen recording.
1919

20-
<video src="https://github.com/user-attachments/assets/56bc7080-f2e3-4367-af22-6bf2245ff6cb" controls="controls" >Your browser does not support playing this video!</video>
20+
**Persistent Browser Sessions:** You can choose to keep the browser window open between AI tasks, allowing you to see the complete history and state of AI interactions.
2121

22-
## Installation Guide
22+
<video src="https://github.com/user-attachments/assets/56bc7080-f2e3-4367-af22-6bf2245ff6cb" controls="controls">Your browser does not support playing this video!</video>
23+
24+
## Installation Options
25+
26+
### Option 1: Docker Installation (Recommended)
27+
28+
1. **Prerequisites:**
29+
- Docker and Docker Compose installed on your system
30+
- Git to clone the repository
31+
32+
2. **Setup:**
33+
```bash
34+
# Clone the repository
35+
git clone <repository-url>
36+
cd browser-use-webui
37+
38+
# Copy and configure environment variables
39+
cp .env.example .env
40+
# Edit .env with your preferred text editor and add your API keys
41+
```
42+
43+
3. **Run with Docker:**
44+
```bash
45+
# Build and start the container with default settings (browser closes after AI tasks)
46+
docker compose up --build
47+
48+
# Or run with persistent browser (browser stays open between AI tasks)
49+
CHROME_PERSISTENT_SESSION=true docker compose up --build
50+
```
51+
52+
4. **Access the Application:**
53+
- WebUI: `http://localhost:7788`
54+
- VNC Viewer (to see browser interactions): `http://localhost:6080/vnc.html`
55+
56+
Default VNC password is "vncpassword". You can change it by setting the `VNC_PASSWORD` environment variable in your `.env` file.
57+
58+
### Option 2: Local Installation
2359

2460
Read the [quickstart guide](https://docs.browser-use.com/quickstart#prepare-the-environment) or follow the steps below to get started.
2561

@@ -51,6 +87,59 @@ playwright install
5187

5288
## Usage
5389

90+
### Docker Setup
91+
1. **Environment Variables:**
92+
- All configuration is done through the `.env` file
93+
- Available environment variables:
94+
```
95+
# LLM API Keys
96+
OPENAI_API_KEY=your_key_here
97+
ANTHROPIC_API_KEY=your_key_here
98+
GOOGLE_API_KEY=your_key_here
99+
100+
# Browser Settings
101+
CHROME_PERSISTENT_SESSION=true # Set to true to keep browser open between AI tasks
102+
RESOLUTION=1920x1080x24 # Custom resolution format: WIDTHxHEIGHTxDEPTH
103+
RESOLUTION_WIDTH=1920 # Custom width in pixels
104+
RESOLUTION_HEIGHT=1080 # Custom height in pixels
105+
106+
# VNC Settings
107+
VNC_PASSWORD=your_vnc_password # Optional, defaults to "vncpassword"
108+
```
109+
110+
2. **Browser Persistence Modes:**
111+
- **Default Mode (CHROME_PERSISTENT_SESSION=false):**
112+
- Browser opens and closes with each AI task
113+
- Clean state for each interaction
114+
- Lower resource usage
115+
116+
- **Persistent Mode (CHROME_PERSISTENT_SESSION=true):**
117+
- Browser stays open between AI tasks
118+
- Maintains history and state
119+
- Allows viewing previous AI interactions
120+
- Set in `.env` file or via environment variable when starting container
121+
122+
3. **Viewing Browser Interactions:**
123+
- Access the noVNC viewer at `http://localhost:6080/vnc.html`
124+
- Enter the VNC password (default: "vncpassword" or what you set in VNC_PASSWORD)
125+
- You can now see all browser interactions in real-time
126+
127+
4. **Container Management:**
128+
```bash
129+
# Start with persistent browser
130+
CHROME_PERSISTENT_SESSION=true docker compose up -d
131+
132+
# Start with default mode (browser closes after tasks)
133+
docker compose up -d
134+
135+
# View logs
136+
docker compose logs -f
137+
138+
# Stop the container
139+
docker compose down
140+
```
141+
142+
### Local Setup
54143
1. **Run the WebUI:**
55144
```bash
56145
python webui.py --ip 127.0.0.1 --port 7788
@@ -129,4 +218,4 @@ CHROME_USER_DATA="~/Library/Application Support/Google/Chrome/Profile 1"
129218

130219
## Changelog
131220

132-
- [x] **2025/01/06:** Thanks to @richard-devbot, a New and Well-Designed WebUI is released. [Video tutorial demo](https://github.com/warmshao/browser-use-webui/issues/1#issuecomment-2573393113).
221+
- [x] **2025/01/06:** Thanks to @richard-devbot, a New and Well-Designed WebUI is released. [Video tutorial demo](https://github.com/warmshao/browser-use-webui/issues/1#issuecomment-2573393113).

docker-compose.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
services:
2+
browser-use-webui:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
ports:
7+
- "7788:7788" # Gradio default port
8+
- "6080:6080" # noVNC web interface
9+
- "5900:5900" # VNC port
10+
- "9222:9222" # Chrome remote debugging port
11+
environment:
12+
- OPENAI_ENDPOINT=${OPENAI_ENDPOINT:-https://api.openai.com/v1}
13+
- OPENAI_API_KEY=${OPENAI_API_KEY:-}
14+
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
15+
- GOOGLE_API_KEY=${GOOGLE_API_KEY:-}
16+
- AZURE_OPENAI_ENDPOINT=${AZURE_OPENAI_ENDPOINT:-}
17+
- AZURE_OPENAI_API_KEY=${AZURE_OPENAI_API_KEY:-}
18+
- DEEPSEEK_ENDPOINT=${DEEPSEEK_ENDPOINT:-https://api.deepseek.com}
19+
- DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY:-}
20+
- BROWSER_USE_LOGGING_LEVEL=${BROWSER_USE_LOGGING_LEVEL:-info}
21+
- ANONYMIZED_TELEMETRY=false
22+
- CHROME_PATH=/usr/bin/google-chrome
23+
- CHROME_USER_DATA=/app/data/chrome_data
24+
- CHROME_PERSISTENT_SESSION=${CHROME_PERSISTENT_SESSION:-false}
25+
- DISPLAY=:99
26+
- PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
27+
- RESOLUTION=${RESOLUTION:-1920x1080x24}
28+
- RESOLUTION_WIDTH=${RESOLUTION_WIDTH:-1920}
29+
- RESOLUTION_HEIGHT=${RESOLUTION_HEIGHT:-1080}
30+
- VNC_PASSWORD=${VNC_PASSWORD:-vncpassword}
31+
- PERSISTENT_BROWSER_PORT=9222
32+
- PERSISTENT_BROWSER_HOST=localhost
33+
- CHROME_DEBUGGING_PORT=9222
34+
- CHROME_DEBUGGING_HOST=localhost
35+
volumes:
36+
- ./data:/app/data
37+
- ./data/chrome_data:/app/data/chrome_data
38+
- /tmp/.X11-unix:/tmp/.X11-unix
39+
restart: unless-stopped
40+
shm_size: '2gb'
41+
cap_add:
42+
- SYS_ADMIN
43+
security_opt:
44+
- seccomp=unconfined
45+
tmpfs:
46+
- /tmp
47+
healthcheck:
48+
test: ["CMD", "nc", "-z", "localhost", "5900"]
49+
interval: 10s
50+
timeout: 5s
51+
retries: 3

src/browser/config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2025/1/6
3+
# @Author : wenshao
4+
# @ProjectName: browser-use-webui
5+
# @FileName: config.py
6+
7+
import os
8+
from dataclasses import dataclass
9+
from typing import Optional
10+
11+
12+
@dataclass
13+
class BrowserPersistenceConfig:
14+
"""Configuration for browser persistence"""
15+
16+
persistent_session: bool = False
17+
user_data_dir: Optional[str] = None
18+
debugging_port: Optional[int] = None
19+
debugging_host: Optional[str] = None
20+
21+
@classmethod
22+
def from_env(cls) -> "BrowserPersistenceConfig":
23+
"""Create config from environment variables"""
24+
return cls(
25+
persistent_session=os.getenv("CHROME_PERSISTENT_SESSION", "").lower()
26+
== "true",
27+
user_data_dir=os.getenv("CHROME_USER_DATA"),
28+
debugging_port=int(os.getenv("CHROME_DEBUGGING_PORT", "9222")),
29+
debugging_host=os.getenv("CHROME_DEBUGGING_HOST", "localhost"),
30+
)

src/browser/custom_browser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from browser_use.browser.browser import Browser
88
from browser_use.browser.context import BrowserContext, BrowserContextConfig
99

10+
from .config import BrowserPersistenceConfig
1011
from .custom_context import CustomBrowserContext
1112

1213

@@ -18,3 +19,9 @@ async def new_context(
1819
) -> BrowserContext:
1920
"""Create a browser context"""
2021
return CustomBrowserContext(config=config, browser=self, context=context)
22+
async def close(self):
23+
"""Override close to respect persistence setting"""
24+
# Check if persistence is enabled before closing
25+
persistence_config = BrowserPersistenceConfig.from_env()
26+
if not persistence_config.persistent_session:
27+
await super().close()

src/browser/custom_context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from browser_use.browser.context import BrowserContext, BrowserContextConfig
1414
from playwright.async_api import Browser as PlaywrightBrowser
1515

16+
from .config import BrowserPersistenceConfig
1617
logger = logging.getLogger(__name__)
1718

1819

@@ -25,6 +26,7 @@ def __init__(
2526
):
2627
super(CustomBrowserContext, self).__init__(browser=browser, config=config)
2728
self.context = context
29+
2830

2931
async def _create_context(self, browser: PlaywrightBrowser):
3032
"""Creates a new browser context with anti-detection measures and loads cookies if available."""

0 commit comments

Comments
 (0)