Spaces:
No application file
No application file
Update browser_automation_ui.html
Browse files- browser_automation_ui.html +110 -31
browser_automation_ui.html
CHANGED
|
@@ -61,6 +61,30 @@
|
|
| 61 |
/* Simulate Lucide icons with simple shapes */
|
| 62 |
.lucide-camera::before {content: "📷";font-size: 16px;}
|
| 63 |
.lucide-download::before {content: "⬇️";font-size: 14px;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
</style>
|
| 65 |
</head>
|
| 66 |
<body>
|
|
@@ -105,12 +129,15 @@
|
|
| 105 |
<h3>Session Manager</h3>
|
| 106 |
</div>
|
| 107 |
<div class="api-body">
|
| 108 |
-
<
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
<button class="btn btn-danger" onclick="closeAllSessions()">
|
| 111 |
-
<i class="lucide lucide-
|
| 112 |
</button>
|
| 113 |
</div>
|
|
|
|
| 114 |
</div>
|
| 115 |
</section>
|
| 116 |
|
|
@@ -186,37 +213,90 @@
|
|
| 186 |
<script>
|
| 187 |
// --- Session Manager -----------------------------------------------------------
|
| 188 |
let sessionId = null;
|
|
|
|
| 189 |
const sessions = [];
|
| 190 |
|
| 191 |
-
function renderSessionList() {
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
}
|
| 204 |
|
| 205 |
async function closeSession(id) {
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
} finally {
|
| 211 |
-
const idx = sessions.indexOf(id);
|
| 212 |
-
if (idx !== -1) sessions.splice(idx, 1);
|
| 213 |
-
renderSessionList();
|
| 214 |
}
|
|
|
|
| 215 |
}
|
| 216 |
|
| 217 |
-
function closeAllSessions() {
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
}
|
| 221 |
|
| 222 |
// Tab switching
|
|
@@ -234,7 +314,8 @@
|
|
| 234 |
document.getElementById('typeTextGroup').style.display = e.target.value === 'type' ? 'block':'none';
|
| 235 |
});
|
| 236 |
|
| 237 |
-
// Helpers
|
|
|
|
| 238 |
// Helper for POST requests that include sessionId automatically
|
| 239 |
async function api(path, body = {}) {
|
| 240 |
const res = await fetch(`/api${path}`, {
|
|
@@ -346,10 +427,8 @@
|
|
| 346 |
});
|
| 347 |
}
|
| 348 |
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
});
|
| 352 |
-
|
| 353 |
// Init icons & status
|
| 354 |
window.addEventListener('DOMContentLoaded',()=>{ lucide.createIcons(); checkStatus(); });
|
| 355 |
</script>
|
|
|
|
| 61 |
/* Simulate Lucide icons with simple shapes */
|
| 62 |
.lucide-camera::before {content: "📷";font-size: 16px;}
|
| 63 |
.lucide-download::before {content: "⬇️";font-size: 14px;}
|
| 64 |
+
#sessionManager .session-list {
|
| 65 |
+
list-style: none;
|
| 66 |
+
padding: 0;
|
| 67 |
+
margin: 4px 0 0 0;
|
| 68 |
+
max-height: 180px;
|
| 69 |
+
overflow-y: auto;
|
| 70 |
+
font-family: "Source Code Pro", monospace;
|
| 71 |
+
font-size: 12px;
|
| 72 |
+
border: 1px solid #e2e8f0;
|
| 73 |
+
border-radius: 6px;
|
| 74 |
+
}
|
| 75 |
+
#sessionManager .session-item {
|
| 76 |
+
padding: 4px 6px;
|
| 77 |
+
cursor: pointer;
|
| 78 |
+
white-space: nowrap;
|
| 79 |
+
transition: background 0.15s;
|
| 80 |
+
}
|
| 81 |
+
#sessionManager .session-item:hover {
|
| 82 |
+
background: #f1f5f9;
|
| 83 |
+
}
|
| 84 |
+
#sessionManager .session-item.active {
|
| 85 |
+
background: #38bdf8;
|
| 86 |
+
color: #fff;
|
| 87 |
+
}
|
| 88 |
</style>
|
| 89 |
</head>
|
| 90 |
<body>
|
|
|
|
| 129 |
<h3>Session Manager</h3>
|
| 130 |
</div>
|
| 131 |
<div class="api-body">
|
| 132 |
+
<div style="display:flex;gap:8px;flex-wrap:wrap;margin-bottom:6px;">
|
| 133 |
+
<button class="btn btn-secondary" onclick="refreshSessions()">
|
| 134 |
+
<i class="lucide lucide-refresh-ccw"></i>Refresh
|
| 135 |
+
</button>
|
| 136 |
<button class="btn btn-danger" onclick="closeAllSessions()">
|
| 137 |
+
<i class="lucide lucide-trash-2"></i>Close all sessions
|
| 138 |
</button>
|
| 139 |
</div>
|
| 140 |
+
<ul id="sessionList" class="session-list"></ul>
|
| 141 |
</div>
|
| 142 |
</section>
|
| 143 |
|
|
|
|
| 213 |
<script>
|
| 214 |
// --- Session Manager -----------------------------------------------------------
|
| 215 |
let sessionId = null;
|
| 216 |
+
let currentSessionId = null;
|
| 217 |
const sessions = [];
|
| 218 |
|
| 219 |
+
// function renderSessionList() {
|
| 220 |
+
// const ul = document.getElementById('sessionList');
|
| 221 |
+
// if (!ul) return;
|
| 222 |
+
// ul.innerHTML = sessions
|
| 223 |
+
// .map(
|
| 224 |
+
// (id) => `
|
| 225 |
+
// <li style="display:flex;align-items:center;gap:8px;margin-bottom:4px;">
|
| 226 |
+
// <code style="flex:1;word-break:break-all;">${id}</code>
|
| 227 |
+
// <button class="btn btn-sm btn-danger" onclick="closeSession('${id}')">✖</button>
|
| 228 |
+
// </li>`
|
| 229 |
+
// )
|
| 230 |
+
// .join('');
|
| 231 |
+
// }
|
| 232 |
+
|
| 233 |
+
async function listSessions() {
|
| 234 |
+
const res = await fetch("/api/browser/sessions");
|
| 235 |
+
if (!res.ok) return [];
|
| 236 |
+
const data = await res.json();
|
| 237 |
+
return data.sessions || [];
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
async function refreshSessions() {
|
| 242 |
+
const listEl = document.getElementById("sessionList");
|
| 243 |
+
listEl.innerHTML = "<li style='padding:4px 6px;'>Loading...</li>";
|
| 244 |
+
const sessions = await listSessions();
|
| 245 |
+
listEl.innerHTML = "";
|
| 246 |
+
sessions.forEach((s) => {
|
| 247 |
+
const li = document.createElement("li");
|
| 248 |
+
li.textContent = s.session_id;
|
| 249 |
+
li.className = "session-item" +
|
| 250 |
+
(s.session_id === currentSessionId ? " active" : "");
|
| 251 |
+
li.onclick = () => selectSession(li, s.session_id);
|
| 252 |
+
|
| 253 |
+
// individual close button (🗑) inside each li
|
| 254 |
+
const closeBtn = document.createElement("span");
|
| 255 |
+
closeBtn.innerHTML = " 🗑";
|
| 256 |
+
closeBtn.style.cursor = "pointer";
|
| 257 |
+
closeBtn.onclick = (e) => {
|
| 258 |
+
e.stopPropagation();
|
| 259 |
+
closeSession(s.session_id);
|
| 260 |
+
};
|
| 261 |
+
li.appendChild(closeBtn);
|
| 262 |
+
|
| 263 |
+
listEl.appendChild(li);
|
| 264 |
+
});
|
| 265 |
+
if (sessions.length === 0) {
|
| 266 |
+
listEl.innerHTML = "<li style='padding:4px 6px;color:#94a3b8;'>No active sessions</li>";
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
function selectSession(li, id) {
|
| 271 |
+
document.querySelectorAll("#sessionList .session-item").forEach((el) =>
|
| 272 |
+
el.classList.remove("active")
|
| 273 |
+
);
|
| 274 |
+
li.classList.add("active");
|
| 275 |
+
currentSessionId = id;
|
| 276 |
+
sessionId = id; // update the global variable for other UI parts
|
| 277 |
}
|
| 278 |
|
| 279 |
async function closeSession(id) {
|
| 280 |
+
await fetch(`/api/browser/close/${id}`, { method: "DELETE" });
|
| 281 |
+
if (id === currentSessionId) {
|
| 282 |
+
currentSessionId = null;
|
| 283 |
+
sessionId = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
}
|
| 285 |
+
refreshSessions();
|
| 286 |
}
|
| 287 |
|
| 288 |
+
async function closeAllSessions() {
|
| 289 |
+
const sessions = await listSessions();
|
| 290 |
+
if (sessions.length === 0) return;
|
| 291 |
+
if (!confirm(`Close ALL ${sessions.length} sessions?`)) return;
|
| 292 |
+
await Promise.all(
|
| 293 |
+
sessions.map((s) =>
|
| 294 |
+
fetch(`/api/browser/close/${s.session_id}`, { method: "DELETE" })
|
| 295 |
+
)
|
| 296 |
+
);
|
| 297 |
+
currentSessionId = null;
|
| 298 |
+
sessionId = null;
|
| 299 |
+
refreshSessions();
|
| 300 |
}
|
| 301 |
|
| 302 |
// Tab switching
|
|
|
|
| 314 |
document.getElementById('typeTextGroup').style.display = e.target.value === 'type' ? 'block':'none';
|
| 315 |
});
|
| 316 |
|
| 317 |
+
// --- Helpers -----------------------------------------------------------
|
| 318 |
+
|
| 319 |
// Helper for POST requests that include sessionId automatically
|
| 320 |
async function api(path, body = {}) {
|
| 321 |
const res = await fetch(`/api${path}`, {
|
|
|
|
| 427 |
});
|
| 428 |
}
|
| 429 |
|
| 430 |
+
// auto‑refresh on page load
|
| 431 |
+
document.addEventListener("DOMContentLoaded", refreshSessions);
|
|
|
|
|
|
|
| 432 |
// Init icons & status
|
| 433 |
window.addEventListener('DOMContentLoaded',()=>{ lucide.createIcons(); checkStatus(); });
|
| 434 |
</script>
|