File size: 4,259 Bytes
8cb0b9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8272e9
8cb0b9d
f8272e9
8cb0b9d
f8272e9
8cb0b9d
 
 
 
51f9ff2
8cb0b9d
 
 
 
51f9ff2
8cb0b9d
 
 
 
f8272e9
8cb0b9d
 
 
 
f8272e9
8cb0b9d
f8272e9
8cb0b9d
 
 
 
f8272e9
8cb0b9d
f8272e9
8cb0b9d
f8272e9
8cb0b9d
f8272e9
8cb0b9d
f8272e9
8cb0b9d
f8272e9
8cb0b9d
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
title: Chrome Controller Pro
emoji: 🌐
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: mit
app_port: 7860
---

# Chrome Controller Pro

A professional-grade Chrome browser controller for Hugging Face Spaces with advanced automation capabilities.

## πŸš€ Features

- **Headless Chrome Management**: Start, stop, and monitor Chrome instances
- **Screenshot Capture**: Take high-quality screenshots of web pages
- **URL Navigation**: Navigate to any website with automatic protocol handling
- **JavaScript Execution**: Execute custom JavaScript code in the browser context
- **Process Management**: Robust Chrome process lifecycle management
- **Persistent Profiles**: Chrome user data persistence during session

## πŸ› οΈ Key Improvements Over Previous Version

### Fixed Issues:
1. **Gradio Schema Error**: Resolved `TypeError: argument of type 'bool' is not iterable` by using proper Gradio component initialization
2. **Launch Configuration**: Fixed localhost accessibility issues with proper server configuration
3. **Chrome Stability**: Enhanced Chrome startup reliability with better error handling
4. **Resource Management**: Improved process cleanup and memory management

### New Features:
1. **JavaScript Console**: Execute custom JavaScript code directly in the browser
2. **Tabbed Interface**: Organized functionality into logical tabs
3. **Enhanced Status Monitoring**: Real-time Chrome process status updates
4. **Better Error Handling**: Comprehensive error messages and recovery options
5. **Optimized Performance**: Reduced startup time and improved responsiveness

## πŸ—οΈ Architecture

The application uses a class-based architecture with the `ChromeController` class managing:
- Chrome process lifecycle
- WebDriver connections
- Screenshot capture
- JavaScript execution
- Process monitoring

## 🐳 Docker Configuration

The Dockerfile is optimized for:
- Minimal image size with multi-stage optimization
- Proper Chrome dependencies installation
- Security best practices with non-root user
- Health checks for reliability

## πŸ“‹ Usage Instructions

1. **Start Chrome**: Click "πŸš€ Start Chrome" to launch the browser instance
2. **Navigate**: Enter a URL and click "🧭 Navigate" to visit websites
3. **Screenshot**: Use "πŸ“Έ Take Screenshot" to capture the current page
4. **Execute JS**: Use the JavaScript tab to run custom code
5. **Monitor**: Check status and manage processes as needed

## πŸ”§ Technical Details

### Chrome Arguments
Optimized Chrome flags for containerized environments:
- Headless mode with new engine
- Disabled GPU acceleration for CPU environments
- Security sandbox disabled for container compatibility
- Remote debugging enabled on port 9222
- Crash reporting disabled to prevent permission issues

### Dependencies
- `gradio==4.44.0` - Web interface framework
- `selenium==4.25.0` - Browser automation
- `webdriver-manager==4.0.2` - ChromeDriver management
- `psutil==6.0.0` - Process management
- `Pillow==10.4.0` - Image processing

## 🚨 Troubleshooting

### Common Issues:

1. **Chrome won't start**
   - Check the status output for specific error messages
   - Ensure sufficient memory is available
   - Try stopping and restarting Chrome

2. **Screenshots fail**
   - Verify Chrome is running with "πŸ“Š Check Status"
   - Ensure the page has finished loading
   - Check if the target URL is accessible

3. **JavaScript execution errors**
   - Verify the JavaScript syntax
   - Ensure Chrome is running and has a page loaded
   - Check browser console for additional error details

### Performance Tips:
- Keep Chrome running between operations for better performance
- Use the status check before taking screenshots
- Clean up processes periodically if running long sessions

## πŸ”’ Security Notes

- Runs in a sandboxed container environment
- Uses non-root user for enhanced security
- Chrome security features are partially disabled for container compatibility
- No persistent data storage outside the session

## πŸ“ License

MIT License - Feel free to use and modify as needed.

## 🀝 Contributing

This is an open-source project. Contributions, issues, and feature requests are welcome!

---

*Built with ❀️ for the Hugging Face Spaces community*