simoncck commited on
Commit
3be51b5
·
verified ·
1 Parent(s): 2112b6c

Update browser_automation_ui.html

Browse files
Files changed (1) hide show
  1. browser_automation_ui.html +61 -7
browser_automation_ui.html CHANGED
@@ -99,6 +99,20 @@
99
  <div class="response-area" id="browserResp"></div>
100
  </div>
101
  </section>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  <!-- Screenshot -->
104
  <section class="api-section">
@@ -170,8 +184,40 @@
170
 
171
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lucide/0.263.1/lucide.min.js"></script>
172
  <script>
173
- // --- State ---
174
  let sessionId = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
  // Tab switching
177
  document.querySelectorAll('.tab-btn').forEach(btn => {
@@ -223,12 +269,20 @@
223
  setDot('seleniumDot', up);
224
  }
225
 
226
- async function launchBrowser(){
227
- const out = await api('/browser/launch');
228
- sessionId = out.session_id || out.sessionId || sessionId;
229
- //sessionId = out.sessionId || sessionId;
230
- document.getElementById('browserResp').textContent = JSON.stringify(out,null,2);
231
- checkStatus();
 
 
 
 
 
 
 
 
232
  }
233
 
234
  async function navigate(){
 
99
  <div class="response-area" id="browserResp"></div>
100
  </div>
101
  </section>
102
+ <section class="api-section" id="sessionManager">
103
+ <div class="api-header">
104
+ <i class="lucide lucide-layout-list"></i>
105
+ <h3>Session Manager</h3>
106
+ </div>
107
+ <div class="api-body">
108
+ <ul id="sessionList" class="session-list"></ul>
109
+ <div style="margin-top:8px;">
110
+ <button class="btn btn-danger" onclick="closeAllSessions()">
111
+ <i class="lucide lucide-x-circle"></i> Close all sessions
112
+ </button>
113
+ </div>
114
+ </div>
115
+ </section>
116
 
117
  <!-- Screenshot -->
118
  <section class="api-section">
 
184
 
185
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lucide/0.263.1/lucide.min.js"></script>
186
  <script>
187
+ // --- Session Manager -----------------------------------------------------------
188
  let sessionId = null;
189
+ const sessions = [];
190
+
191
+ function renderSessionList() {
192
+ const ul = document.getElementById('sessionList');
193
+ if (!ul) return;
194
+ ul.innerHTML = sessions
195
+ .map(
196
+ (id) => `
197
+ <li style="display:flex;align-items:center;gap:8px;margin-bottom:4px;">
198
+ <code style="flex:1;word-break:break-all;">${id}</code>
199
+ <button class="btn btn-sm btn-danger" onclick="closeSession('${id}')">✖</button>
200
+ </li>`
201
+ )
202
+ .join('');
203
+ }
204
+
205
+ async function closeSession(id) {
206
+ try {
207
+ await api(`/browser/close/${id}`, 'DELETE');
208
+ } catch (err) {
209
+ console.error(err);
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
+ // create a shallow copy to avoid mutation issues while iterating
219
+ [...sessions].forEach((id) => closeSession(id));
220
+ }
221
 
222
  // Tab switching
223
  document.querySelectorAll('.tab-btn').forEach(btn => {
 
269
  setDot('seleniumDot', up);
270
  }
271
 
272
+ // async function launchBrowser(){
273
+ // const out = await api('/browser/launch');
274
+ // sessionId = out.session_id || out.sessionId || sessionId;
275
+ // //sessionId = out.sessionId || sessionId;
276
+ // document.getElementById('browserResp').textContent = JSON.stringify(out,null,2);
277
+ // checkStatus();
278
+ // }
279
+ async function launchBrowser() {
280
+ const resp = await api('/browser/launch', 'POST', {});
281
+ if (resp.session_id) {
282
+ sessions.push(resp.session_id);
283
+ renderSessionList();
284
+ showToast(`Launched browser: ${resp.session_id.substring(0, 8)}…`, 'success');
285
+ }
286
  }
287
 
288
  async function navigate(){