Spaces:
No application file
No application file
Update browser_automation_ui.html
Browse files- browser_automation_ui.html +52 -24
browser_automation_ui.html
CHANGED
|
@@ -175,18 +175,38 @@ All endpoints return { ok: true/false, data, error }
|
|
| 175 |
});
|
| 176 |
|
| 177 |
// Helpers
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
return res.json();
|
| 181 |
}
|
| 182 |
function setDot(id, ok){ const el=document.getElementById(id); el.classList.toggle('status-online',ok); el.classList.toggle('status-offline',!ok);}
|
| 183 |
|
| 184 |
// --- Actions ---
|
| 185 |
-
async function checkStatus(){
|
| 186 |
-
const out = await
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
| 190 |
}
|
| 191 |
|
| 192 |
async function launchBrowser(){
|
|
@@ -209,25 +229,33 @@ All endpoints return { ok: true/false, data, error }
|
|
| 209 |
if(out.b64){ document.getElementById('shotPreview').innerHTML = `<img src="data:image/png;base64,${out.b64}" style="max-width:100%;border:1px solid #e2e8f0;border-radius:8px;"/>`; }
|
| 210 |
}
|
| 211 |
|
| 212 |
-
async function elementAction(){
|
| 213 |
-
const selector=document.getElementById('selector').value.trim();
|
| 214 |
-
if(!selector) return alert('Enter selector');
|
| 215 |
-
const action=document.getElementById('action').value;
|
| 216 |
-
const
|
| 217 |
-
const out = await api('/
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
}
|
| 220 |
|
| 221 |
-
async function inspectPage(){
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
list.
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
chip.
|
| 229 |
-
chip.
|
| 230 |
-
chip.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
list.appendChild(chip);
|
| 232 |
});
|
| 233 |
}
|
|
|
|
| 175 |
});
|
| 176 |
|
| 177 |
// Helpers
|
| 178 |
+
// Helper for POST requests that include sessionId automatically
|
| 179 |
+
async function api(path, body = {}) {
|
| 180 |
+
const res = await fetch(`/api${path}`, {
|
| 181 |
+
method: 'POST',
|
| 182 |
+
headers: { 'Content-Type': 'application/json' },
|
| 183 |
+
body: JSON.stringify({ session_id: sessionId, ...body })
|
| 184 |
+
});
|
| 185 |
+
return res.json();
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
// Simple GET helper (no JSON body)
|
| 189 |
+
async function apiGet(path) {
|
| 190 |
+
const res = await fetch(`/api${path}`);
|
| 191 |
+
return res.json();
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// Health (non‑/api) helper
|
| 195 |
+
async function health() {
|
| 196 |
+
const res = await fetch('/health');
|
| 197 |
return res.json();
|
| 198 |
}
|
| 199 |
function setDot(id, ok){ const el=document.getElementById(id); el.classList.toggle('status-online',ok); el.classList.toggle('status-offline',!ok);}
|
| 200 |
|
| 201 |
// --- Actions ---
|
| 202 |
+
async function checkStatus() {
|
| 203 |
+
const out = await health().catch(() => ({ status: 'down' }));
|
| 204 |
+
const up = out.status === 'healthy';
|
| 205 |
+
// We don't have separate pool/playwright/selenium flags from backend yet,
|
| 206 |
+
// so treat health OK as all‑green.
|
| 207 |
+
setDot('poolDot', up);
|
| 208 |
+
setDot('playwrightDot', up);
|
| 209 |
+
setDot('seleniumDot', up);
|
| 210 |
}
|
| 211 |
|
| 212 |
async function launchBrowser(){
|
|
|
|
| 229 |
if(out.b64){ document.getElementById('shotPreview').innerHTML = `<img src="data:image/png;base64,${out.b64}" style="max-width:100%;border:1px solid #e2e8f0;border-radius:8px;"/>`; }
|
| 230 |
}
|
| 231 |
|
| 232 |
+
async function elementAction() {
|
| 233 |
+
const selector = document.getElementById('selector').value.trim();
|
| 234 |
+
if (!selector) return alert('Enter selector');
|
| 235 |
+
const action = document.getElementById('action').value;
|
| 236 |
+
const value = document.getElementById('typeText').value;
|
| 237 |
+
const out = await api('/elements/action', {
|
| 238 |
+
selector,
|
| 239 |
+
action,
|
| 240 |
+
value
|
| 241 |
+
});
|
| 242 |
+
document.getElementById('elementResp').textContent = JSON.stringify(out, null, 2);
|
| 243 |
}
|
| 244 |
|
| 245 |
+
async function inspectPage() {
|
| 246 |
+
if (!sessionId) return alert('Launch browser first');
|
| 247 |
+
const out = await apiGet(`/elements/inspect/${sessionId}`);
|
| 248 |
+
document.getElementById('inspectResp').textContent = JSON.stringify(out, null, 2);
|
| 249 |
+
const list = document.getElementById('selectorList');
|
| 250 |
+
list.innerHTML = '';
|
| 251 |
+
(out.elements || []).slice(0, 50).forEach(el => {
|
| 252 |
+
const chip = document.createElement('span');
|
| 253 |
+
chip.className = 'selector-chip';
|
| 254 |
+
chip.textContent = el.selector;
|
| 255 |
+
chip.onclick = () => {
|
| 256 |
+
document.getElementById('selector').value = el.selector;
|
| 257 |
+
document.getElementById('action').focus();
|
| 258 |
+
};
|
| 259 |
list.appendChild(chip);
|
| 260 |
});
|
| 261 |
}
|