akashyadav758 commited on
Commit
2a601f2
Β·
1 Parent(s): 7bca58d

Deploy user-based Chrome on Hugging Face using custom non-root start script

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. README.md +4 -3
  3. start_hf.sh +131 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM akashyadav758/chrome:latest
2
+
3
+ USER root
4
+
5
+ # Replace the start script with the non-root version
6
+ COPY --chmod=755 start_hf.sh /start.sh
7
+
8
+ # Run as non-root user 1000
9
+ USER 1000
10
+
11
+ CMD ["/start.sh"]
README.md CHANGED
@@ -1,9 +1,10 @@
1
  ---
2
  title: Chrome
3
- emoji: πŸš€
4
- colorFrom: pink
5
- colorTo: purple
6
  sdk: docker
 
7
  pinned: false
8
  ---
9
 
 
1
  ---
2
  title: Chrome
3
+ emoji: πŸ“Š
4
+ colorFrom: gray
5
+ colorTo: blue
6
  sdk: docker
7
+ app_port: 3001
8
  pinned: false
9
  ---
10
 
start_hf.sh ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Graceful Shutdown Handler
4
+ cleanup() {
5
+ echo "πŸ›‘ Shutting down..."
6
+ pkill -TERM google-chrome 2>/dev/null || true
7
+ sleep 5
8
+ exit 0
9
+ }
10
+ trap cleanup SIGTERM SIGINT
11
+
12
+ echo "πŸš€ Starting Chrome Headless Boot Sequence on Hugging Face Spaces..."
13
+
14
+ # 1. Structure Detection & Fix
15
+ if [ -d "/home/chrome/data/data/Default" ]; then
16
+ echo "⚠️ Nested structure detected. Fixing..."
17
+ mv /home/chrome/data/data/* /home/chrome/data/ 2>/dev/null || true
18
+ rmdir /home/chrome/data/data 2>/dev/null || true
19
+ fi
20
+
21
+ # 2. Deep Junk Cleanup (80% bloat removal)
22
+ echo "🧹 Performing Deep Junk Cleanup..."
23
+ rm -rf /home/chrome/data/Default/Cache \
24
+ /home/chrome/data/Default/Code\ Cache \
25
+ /home/chrome/data/Default/GPUCache \
26
+ /home/chrome/data/Default/DawnGraphiteCache \
27
+ /home/chrome/data/Default/DawnWebGPUCache \
28
+ /home/chrome/data/Default/ShaderCache \
29
+ /home/chrome/data/Default/GrShaderCache \
30
+ /home/chrome/data/Default/Service\ Worker/CacheStorage \
31
+ /home/chrome/data/Default/History \
32
+ /home/chrome/data/Default/Favicons \
33
+ /home/chrome/data/Default/Top\ Sites \
34
+ /home/chrome/data/Default/Visited\ Links \
35
+ /home/chrome/data/Default/Network\ Action\ Predictor \
36
+ /home/chrome/data/Default/Network\ Persistent\ State 2>/dev/null || true
37
+
38
+ rm -rf /home/chrome/data/component_crx_cache \
39
+ /home/chrome/data/optimization_guide_model_store \
40
+ /home/chrome/data/WasmTtsEngine \
41
+ /home/chrome/data/OnDeviceHeadSuggestModel \
42
+ /home/chrome/data/hyphen-data \
43
+ /home/chrome/data/ZxcvbnData \
44
+ /home/chrome/data/SafetyTips \
45
+ /home/chrome/data/Safe\ Browsing* \
46
+ /home/chrome/data/BrowserMetrics* \
47
+ /home/chrome/data/Crashpad \
48
+ /home/chrome/data/GrShaderCache \
49
+ /home/chrome/data/ShaderCache \
50
+ /home/chrome/data/GraphiteDawnCache 2>/dev/null || true
51
+
52
+ # 3. Singleton/Lock removal
53
+ echo "πŸ”“ Removing lock files..."
54
+ find /home/chrome -name "Singleton*" -exec rm -f {} +
55
+ rm -f /home/chrome/data/Default/LOCK /home/chrome/data/Default/LOG.old 2>/dev/null || true
56
+
57
+ # 4. Crash Fix (prevent restore popup)
58
+ if [ -f /home/chrome/data/Default/Preferences ]; then
59
+ sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/g' /home/chrome/data/Default/Preferences 2>/dev/null || true
60
+ sed -i 's/"exit_type":"SessionCrashed"/"exit_type":"Normal"/g' /home/chrome/data/Default/Preferences 2>/dev/null || true
61
+ fi
62
+
63
+ # 5. Start Go Monitor Server
64
+ echo "πŸš€ Starting Go Monitor Server..."
65
+ cd /opt/monitor-server
66
+ ./monitor-server > /home/chrome/monitor.log 2>&1 &
67
+
68
+ # 6. Start CDP Proxy
69
+ echo "πŸ”Œ Starting CDP Proxy..."
70
+ socat TCP-LISTEN:9223,fork,bind=0.0.0.0 TCP:127.0.0.1:9222 &
71
+
72
+ # 7. Launch Chrome Headless
73
+ echo "✨ Launching Chrome Headless..."
74
+ google-chrome-stable \
75
+ --headless=new \
76
+ --no-sandbox \
77
+ --disable-setuid-sandbox \
78
+ --disable-infobars \
79
+ --disable-blink-features=AutomationControlled \
80
+ --excludeSwitches=enable-automation \
81
+ --use-fake-ui-for-media-stream \
82
+ --use-fake-device-for-media-stream \
83
+ --use-mock-keychain \
84
+ --password-store=basic \
85
+ --window-size=980,1070 \
86
+ --user-agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36' \
87
+ --disable-gpu \
88
+ --disable-software-rasterizer \
89
+ --disable-gpu-compositing \
90
+ --disable-breakpad \
91
+ --disable-crash-reporter \
92
+ --mute-audio \
93
+ --in-process-gpu \
94
+ --no-zygote \
95
+ --renderer-process-limit=1 \
96
+ --disable-dev-shm-usage \
97
+ --font-render-hinting=none \
98
+ --disable-font-subpixel-positioning \
99
+ --force-color-profile=srgb \
100
+ --remote-debugging-port=9222 \
101
+ --remote-debugging-address=127.0.0.1 \
102
+ --remote-allow-origins='*' \
103
+ --user-data-dir=/home/chrome/data \
104
+ --disable-background-networking \
105
+ --disable-sync \
106
+ --no-first-run \
107
+ --disable-default-apps \
108
+ --disable-background-timer-throttling \
109
+ --disable-renderer-backgrounding \
110
+ --disable-backgrounding-occluded-windows \
111
+ --disable-extensions \
112
+ --disable-translate \
113
+ --memory-pressure-off \
114
+ --process-per-site \
115
+ --disable-client-side-phishing-detection \
116
+ --disable-component-update \
117
+ --disable-domain-reliability \
118
+ --disable-hang-monitor \
119
+ --disable-ipc-flooding-protection \
120
+ --disable-popup-blocking \
121
+ --disable-prompt-on-repost \
122
+ --disable-cookie-encryption \
123
+ --force-dark-mode \
124
+ --udp-force-randomized-port \
125
+ --disable-partial-raster \
126
+ --disable-features=TranslateUI,PaintHolding,IsolateOrigins,site-per-process \
127
+ --enable-features=NetworkService,NetworkServiceInProcess \
128
+ --disable-site-isolation-trials \
129
+ --js-flags="--max-old-space-size=256" \
130
+ --metrics-recording-only \
131
+ 'https://gemini.google.com/app'