Skip to content

Commit 9579694

Browse files
authored
refactor: Improve the configurations (#38)
## Summary - **refactor: Improve browser configuration with stealth mode and support for multiple engines** - **docs: Update Dockerfile and configuration for browser selection and Xvfb support** - **chore: Update ADL CLI version to 0.23.9 in generated files** --------- Signed-off-by: Eden Reich <eden.reich@gmail.com>
1 parent f298176 commit 9579694

File tree

20 files changed

+735
-62
lines changed

20 files changed

+735
-62
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.releaserc.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ browser-agent is an A2A (Agent-to-Agent) server implementing the [A2A Protocol](
1010

1111
### ADL-Generated Structure
1212

13-
The codebase is generated using ADL CLI 0.23.8 and follows a strict generation pattern:
13+
The codebase is generated using ADL CLI 0.23.9 and follows a strict generation pattern:
1414
- **Generated Files**: Marked with `DO NOT EDIT` headers - manual changes will be overwritten
1515
- **Configuration Source**: `agent.yaml` - defines agent capabilities, skills, and metadata
1616
- **Server Implementation**: Built on the ADK (Agent Development Kit) framework from `github.com/inference-gateway/adk`
@@ -117,7 +117,7 @@ Activate with: `flox activate` (if Flox is installed)
117117

118118
- **Generated Files**: Never manually edit files with "DO NOT EDIT" headers
119119
- **Configuration Changes**: Always modify `agent.yaml` and regenerate
120-
- **ADL Version**: Ensure ADL CLI 0.23.8 or compatible version for regeneration
120+
- **ADL Version**: Ensure ADL CLI 0.23.9 or compatible version for regeneration
121121
- **Port Configuration**: Default 8080, configurable via `A2A_PORT` or `A2A_SERVER_PORT`
122122

123123
## Debugging Tips

Dockerfile

Lines changed: 33 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ A production-ready [Agent-to-Agent (A2A)](https://github.com/inference-gateway/a
1515
## Quick Start
1616

1717
```bash
18-
# Run the agent
18+
# Run the agent locally
1919
go run .
2020

21-
# Or with Docker
21+
# Or with Docker (Chromium only - smallest image)
2222
docker build -t browser-agent .
2323
docker run -p 8080:8080 browser-agent
24+
25+
# Build with specific browser engine
26+
docker build --build-arg BROWSER_ENGINE=firefox -t browser-agent:firefox .
27+
28+
# Run with Xvfb enabled (for extensions or specific rendering features)
29+
docker run -p 8080:8080 -e BROWSER_XVFB_ENABLED=true browser-agent
2430
```
2531

2632
## Features
@@ -62,16 +68,21 @@ The following custom configuration variables are available:
6268
|----------|----------|-------------|---------|
6369
| **Browser** | `BROWSER_ARGS` | Args configuration | `[--disable-blink-features=AutomationControlled --disable-features=VizDisplayCompositor --no-first-run --disable-default-apps --disable-extensions --disable-plugins --disable-sync --disable-translate --hide-scrollbars --mute-audio --no-zygote --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-renderer-backgrounding --disable-ipc-flooding-protection]` |
6470
| **Browser** | `BROWSER_DATA_DIR` | Data_dir configuration | `/tmp/playwright/artifacts` |
71+
| **Browser** | `BROWSER_ENGINE` | Engine configuration | `chromium` |
6572
| **Browser** | `BROWSER_HEADER_ACCEPT` | Header_accept configuration | `text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7` |
6673
| **Browser** | `BROWSER_HEADER_ACCEPT_ENCODING` | Header_accept_encoding configuration | `gzip, deflate, br` |
6774
| **Browser** | `BROWSER_HEADER_ACCEPT_LANGUAGE` | Header_accept_language configuration | `en-US,en;q=0.9` |
6875
| **Browser** | `BROWSER_HEADER_CONNECTION` | Header_connection configuration | `keep-alive` |
6976
| **Browser** | `BROWSER_HEADER_DNT` | Header_dnt configuration | `1` |
7077
| **Browser** | `BROWSER_HEADER_UPGRADE_INSECURE_REQUESTS` | Header_upgrade_insecure_requests configuration | `1` |
7178
| **Browser** | `BROWSER_HEADLESS` | Headless configuration | `true` |
79+
| **Browser** | `BROWSER_STEALTH_MODE` | Stealth_mode configuration | `false` |
7280
| **Browser** | `BROWSER_USER_AGENT` | User_agent configuration | `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36` |
7381
| **Browser** | `BROWSER_VIEWPORT_HEIGHT` | Viewport_height configuration | `1080` |
7482
| **Browser** | `BROWSER_VIEWPORT_WIDTH` | Viewport_width configuration | `1920` |
83+
| **Browser** | `BROWSER_XVFB_DISPLAY` | Xvfb_display configuration | `:99` |
84+
| **Browser** | `BROWSER_XVFB_ENABLED` | Xvfb_enabled configuration | `false` |
85+
| **Browser** | `BROWSER_XVFB_SCREEN_RESOLUTION` | Xvfb_screen_resolution configuration | `1920x1080x24` |
7586

7687
| Category | Variable | Description | Default |
7788
|----------|----------|-------------|---------|
@@ -158,10 +169,10 @@ docker run --rm -it --network host ghcr.io/inference-gateway/a2a-debugger:latest
158169

159170
### Docker
160171

161-
The Docker image can be built with custom version information using build arguments:
172+
The Docker image can be built with custom version information and browser selection using build arguments:
162173

163174
```bash
164-
# Build with default values from ADL
175+
# Build with default values from ADL (Chromium only)
165176
docker build -t browser-agent .
166177

167178
# Build with custom version information
@@ -170,15 +181,42 @@ docker build \
170181
--build-arg AGENT_NAME="My Custom Agent" \
171182
--build-arg AGENT_DESCRIPTION="Custom agent description" \
172183
-t browser-agent:1.2.3 .
184+
185+
# Build with specific browser engine
186+
docker build --build-arg BROWSER_ENGINE=firefox -t browser-agent:firefox .
187+
188+
# Build with all browsers (larger image)
189+
docker build --build-arg BROWSER_ENGINE=all -t browser-agent:all .
173190
```
174191

175192
**Available Build Arguments:**
176193
- `VERSION` - Agent version (default: `0.4.1`)
177194
- `AGENT_NAME` - Agent name (default: `browser-agent`)
178195
- `AGENT_DESCRIPTION` - Agent description (default: `AI agent for browser automation and web testing using Playwright`)
196+
- `BROWSER_ENGINE` - Browser to install (`chromium`, `firefox`, `webkit`, or `all`) (default: `chromium`)
179197

180198
These values are embedded into the binary at build time using linker flags, making them accessible at runtime without requiring environment variables.
181199

200+
#### Xvfb Configuration
201+
202+
By default, the browser runs in native headless mode. For cases requiring a virtual display (e.g., extensions, specific rendering features), you can enable Xvfb:
203+
204+
```bash
205+
# Run with Xvfb enabled
206+
docker run -p 8080:8080 \
207+
-e BROWSER_XVFB_ENABLED=true \
208+
browser-agent
209+
210+
# Customize Xvfb display settings
211+
docker run -p 8080:8080 \
212+
-e BROWSER_XVFB_ENABLED=true \
213+
-e BROWSER_XVFB_DISPLAY=:99 \
214+
-e BROWSER_XVFB_SCREEN_RESOLUTION=1920x1080x24 \
215+
browser-agent
216+
```
217+
218+
**Security Note:** Xvfb is configured without the `-ac` flag (access control disabled) for security. The X server uses `-nolisten tcp` to prevent network access.
219+
182220
## License
183221

184222
MIT License - see LICENSE file for details

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ spec:
1212
config:
1313
browser:
1414
headless: true
15+
engine: "chromium"
16+
stealth_mode: false
1517
user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
1618
viewport_width: 1920
1719
viewport_height: 1080
@@ -22,6 +24,9 @@ spec:
2224
header_connection: "keep-alive"
2325
header_upgrade_insecure_requests: "1"
2426
data_dir: "/tmp/playwright/artifacts"
27+
xvfb_enabled: false
28+
xvfb_display: ":99"
29+
xvfb_screen_resolution: "1920x1080x24"
2530
args:
2631
- "--disable-blink-features=AutomationControlled"
2732
- "--disable-features=VizDisplayCompositor"

config/config.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-entrypoint.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Configuration from environment variables
5+
XVFB_ENABLED="${BROWSER_XVFB_ENABLED:-false}"
6+
XVFB_DISPLAY="${BROWSER_XVFB_DISPLAY:-:99}"
7+
XVFB_SCREEN="${BROWSER_XVFB_SCREEN_RESOLUTION:-1920x1080x24}"
8+
9+
# Function to check if Xvfb is ready
10+
wait_for_xvfb() {
11+
local max_attempts=10
12+
local attempt=0
13+
14+
while [ $attempt -lt $max_attempts ]; do
15+
if xdpyinfo -display "$XVFB_DISPLAY" >/dev/null 2>&1; then
16+
echo "Xvfb is ready on display $XVFB_DISPLAY"
17+
return 0
18+
fi
19+
attempt=$((attempt + 1))
20+
sleep 0.5
21+
done
22+
23+
echo "Warning: Xvfb failed to start within timeout"
24+
return 1
25+
}
26+
27+
# Start Xvfb if enabled
28+
if [ "$XVFB_ENABLED" = "true" ]; then
29+
echo "Starting Xvfb on display $XVFB_DISPLAY with screen resolution $XVFB_SCREEN"
30+
31+
# Start Xvfb without -ac flag for security
32+
# Use -nolisten tcp to prevent network access
33+
Xvfb "$XVFB_DISPLAY" -screen 0 "$XVFB_SCREEN" -nolisten tcp &
34+
XVFB_PID=$!
35+
36+
# Wait for Xvfb to be ready
37+
if wait_for_xvfb; then
38+
export DISPLAY="$XVFB_DISPLAY"
39+
echo "Xvfb started successfully (PID: $XVFB_PID)"
40+
else
41+
echo "Error: Xvfb failed to start properly"
42+
kill "$XVFB_PID" 2>/dev/null || true
43+
exit 1
44+
fi
45+
46+
# Trap to cleanup Xvfb on exit
47+
trap "echo 'Stopping Xvfb...'; kill $XVFB_PID 2>/dev/null || true" EXIT
48+
else
49+
echo "Xvfb disabled, using native headless mode"
50+
fi
51+
52+
# Log configuration
53+
echo "Browser configuration:"
54+
echo " Engine: ${BROWSER_ENGINE:-chromium}"
55+
echo " Headless: ${BROWSER_HEADLESS:-true}"
56+
echo " Stealth Mode: ${BROWSER_STEALTH_MODE:-false}"
57+
echo " Xvfb Enabled: $XVFB_ENABLED"
58+
59+
# Start the main application
60+
exec ./main

0 commit comments

Comments
 (0)