Spaces:
Sleeping
Sleeping
yusef commited on
Commit ·
54f9efc
1
Parent(s): 0db29d0
Update worker with click by coordinates
Browse files
README.md
CHANGED
|
@@ -1,10 +1,39 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Lukas Worker - Browser Automation Engine
|
| 2 |
+
|
| 3 |
+
هذا المجلد يحتوي على "عضلات" لوكاس - السيرفر المسؤول عن تشغيل المتصفح والبث المباشر.
|
| 4 |
+
|
| 5 |
+
## 🚀 الرفع على Hugging Face Spaces
|
| 6 |
+
|
| 7 |
+
1. أنشئ Space جديد على [Hugging Face](https://huggingface.co/new-space)
|
| 8 |
+
2. اختر **Docker** كـ SDK
|
| 9 |
+
3. ارفع محتويات هذا المجلد
|
| 10 |
+
4. أضف Environment Variable:
|
| 11 |
+
- `WORKER_SECRET` = (نفس القيمة في Vercel)
|
| 12 |
+
|
| 13 |
+
## ⚙️ Environment Variables
|
| 14 |
+
|
| 15 |
+
| المتغير | الوصف |
|
| 16 |
+
|---------|-------|
|
| 17 |
+
| `WORKER_SECRET` | كلمة السر للاتصال الآمن مع "المخ" |
|
| 18 |
+
| `PORT` | البورت (افتراضي: 7860) |
|
| 19 |
+
|
| 20 |
+
## 🔌 الأوامر المتاحة (Socket.io Events)
|
| 21 |
+
|
| 22 |
+
| الحدث | الوصف |
|
| 23 |
+
|-------|-------|
|
| 24 |
+
| `browser:goto` | الذهاب لرابط معين |
|
| 25 |
+
| `browser:click` | الضغط على عنصر |
|
| 26 |
+
| `browser:type` | الكتابة في حقل |
|
| 27 |
+
| `browser:scroll` | التمرير لأعلى/لأسفل |
|
| 28 |
+
| `browser:screenshot` | أخذ لقطة شاشة |
|
| 29 |
+
| `browser:getContent` | جلب محتوى الصفحة |
|
| 30 |
+
| `stream:frame` | (صادر) إطار البث المباشر |
|
| 31 |
+
|
| 32 |
+
## 🧪 التشغيل المحلي
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
cd worker
|
| 36 |
+
npm install
|
| 37 |
+
npx playwright install chromium
|
| 38 |
+
npm start
|
| 39 |
+
```
|
index.js
CHANGED
|
@@ -179,10 +179,20 @@ io.on('connection', async (socket) => {
|
|
| 179 |
|
| 180 |
socket.on('browser:click', async (data, callback) => {
|
| 181 |
try {
|
| 182 |
-
const { selector } = data;
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
-
await activePage.click(selector, { timeout: 10000 });
|
| 186 |
callback({ success: true });
|
| 187 |
} catch (error) {
|
| 188 |
console.error('❌ Click error:', error.message);
|
|
@@ -192,10 +202,18 @@ io.on('connection', async (socket) => {
|
|
| 192 |
|
| 193 |
socket.on('browser:type', async (data, callback) => {
|
| 194 |
try {
|
| 195 |
-
const { selector, text
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
-
await activePage.fill(selector, text);
|
| 199 |
callback({ success: true });
|
| 200 |
} catch (error) {
|
| 201 |
console.error('❌ Type error:', error.message);
|
|
|
|
| 179 |
|
| 180 |
socket.on('browser:click', async (data, callback) => {
|
| 181 |
try {
|
| 182 |
+
const { selector, x, y } = data;
|
| 183 |
+
|
| 184 |
+
if (x !== undefined && y !== undefined) {
|
| 185 |
+
// Click by coordinates
|
| 186 |
+
console.log(`🖱️ Clicking at coordinates: (${x}, ${y})`);
|
| 187 |
+
await activePage.mouse.click(x, y);
|
| 188 |
+
} else if (selector) {
|
| 189 |
+
// Click by selector
|
| 190 |
+
console.log(`🖱️ Clicking selector: ${selector}`);
|
| 191 |
+
await activePage.click(selector, { timeout: 10000 });
|
| 192 |
+
} else {
|
| 193 |
+
throw new Error('Either selector or x,y coordinates required');
|
| 194 |
+
}
|
| 195 |
|
|
|
|
| 196 |
callback({ success: true });
|
| 197 |
} catch (error) {
|
| 198 |
console.error('❌ Click error:', error.message);
|
|
|
|
| 202 |
|
| 203 |
socket.on('browser:type', async (data, callback) => {
|
| 204 |
try {
|
| 205 |
+
const { selector, text } = data;
|
| 206 |
+
|
| 207 |
+
if (selector) {
|
| 208 |
+
// Type into specific element
|
| 209 |
+
console.log(`⌨️ Typing in selector: ${selector}`);
|
| 210 |
+
await activePage.fill(selector, text);
|
| 211 |
+
} else {
|
| 212 |
+
// Type using keyboard (to focused element)
|
| 213 |
+
console.log(`⌨️ Typing text: ${text.substring(0, 20)}...`);
|
| 214 |
+
await activePage.keyboard.type(text, { delay: 30 });
|
| 215 |
+
}
|
| 216 |
|
|
|
|
| 217 |
callback({ success: true });
|
| 218 |
} catch (error) {
|
| 219 |
console.error('❌ Type error:', error.message);
|