Sachin5112 commited on
Commit
963d3ff
·
verified ·
1 Parent(s): 88b4645

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -35
app.py CHANGED
@@ -151,6 +151,18 @@ async def touch(request: TouchRequest):
151
  await page.mouse.move(x, y)
152
  elif request.action == "end":
153
  await page.mouse.up()
 
 
 
 
 
 
 
 
 
 
 
 
154
  else:
155
  raise HTTPException(
156
  400,
@@ -159,7 +171,8 @@ async def touch(request: TouchRequest):
159
 
160
  return {
161
  "success": True,
162
- "image": await screenshot()
 
163
  }
164
 
165
  except Exception as error:
@@ -267,16 +280,6 @@ button {
267
  overflow: hidden;
268
  text-overflow: ellipsis;
269
  white-space: nowrap;
270
- display: flex;
271
- justify-content: space-between;
272
- align-items: center;
273
- }
274
-
275
- #kb-toggle {
276
- background: #333;
277
- padding: 2px 8px;
278
- border-radius: 4px;
279
- font-size: 11px;
280
  }
281
 
282
  #screen-container {
@@ -301,7 +304,7 @@ button {
301
  -webkit-touch-callout: none;
302
  }
303
 
304
- /* Hidden input to trigger mobile keyboard */
305
  #hidden-input {
306
  position: absolute;
307
  opacity: 0;
@@ -330,8 +333,7 @@ button {
330
  </div>
331
 
332
  <div id="status">
333
- <span id="status-text">Ready</span>
334
- <button id="kb-toggle" onclick="toggleKeyboard()">⌨️ Keyboard</button>
335
  </div>
336
 
337
  <div id="screen-container">
@@ -344,12 +346,11 @@ button {
344
  <script>
345
 
346
  const screen = document.getElementById("screen");
347
- const statusText = document.getElementById("status-text");
348
  const urlInput = document.getElementById("url");
349
  const hiddenInput = document.getElementById("hidden-input");
350
 
351
  let touching = false;
352
- let keyboardActive = false;
353
 
354
  async function navigate() {
355
  let url = urlInput.value.trim();
@@ -359,7 +360,7 @@ async function navigate() {
359
  url = "https://" + url;
360
  }
361
 
362
- statusText.textContent = "Loading...";
363
 
364
  try {
365
  const response = await fetch("/navigate", {
@@ -377,9 +378,9 @@ async function navigate() {
377
  }
378
 
379
  show(data.image);
380
- statusText.textContent = data.url;
381
  } catch (error) {
382
- statusText.textContent = "Error: " + error.message;
383
  }
384
  }
385
 
@@ -426,8 +427,17 @@ async function sendTouch(action, event) {
426
  if (data.image) {
427
  show(data.image);
428
  }
 
 
 
 
 
 
 
 
 
429
  } catch (error) {
430
- statusText.textContent = error.message;
431
  }
432
  }
433
 
@@ -447,20 +457,7 @@ async function sendKey(key) {
447
  show(data.image);
448
  }
449
  } catch (error) {
450
- statusText.textContent = error.message;
451
- }
452
- }
453
-
454
- function toggleKeyboard() {
455
- keyboardActive = !keyboardActive;
456
- if (keyboardActive) {
457
- hiddenInput.focus();
458
- document.getElementById("kb-toggle").style.background = "#007bff";
459
- statusText.textContent = "Keyboard Active (Type now)";
460
- } else {
461
- hiddenInput.blur();
462
- document.getElementById("kb-toggle").style.background = "#333";
463
- statusText.textContent = "Keyboard Closed";
464
  }
465
  }
466
 
@@ -475,7 +472,6 @@ hiddenInput.addEventListener("input", e => {
475
  sendKey("Backspace");
476
  }
477
  lastLength = val.length;
478
- // Clear out periodically to keep it manageable
479
  if(hiddenInput.value.length > 50) {
480
  hiddenInput.value = "";
481
  lastLength = 0;
 
151
  await page.mouse.move(x, y)
152
  elif request.action == "end":
153
  await page.mouse.up()
154
+ # Check if active element in page is an input/textarea/editable field
155
+ active_tag = await page.evaluate("document.activeElement ? document.activeElement.tagName.toLowerCase() : ''")
156
+ is_editable = await page.evaluate("document.activeElement ? document.activeElement.isContentEditable : false")
157
+
158
+ should_open_kb = (active_tag in ["input", "textarea", "select"] or is_editable)
159
+
160
+ # Return status to frontend so it knows whether to trigger mobile keyboard
161
+ return {
162
+ "success": True,
163
+ "image": await screenshot(),
164
+ "open_keyboard": should_open_kb
165
+ }
166
  else:
167
  raise HTTPException(
168
  400,
 
171
 
172
  return {
173
  "success": True,
174
+ "image": await screenshot(),
175
+ "open_keyboard": False
176
  }
177
 
178
  except Exception as error:
 
280
  overflow: hidden;
281
  text-overflow: ellipsis;
282
  white-space: nowrap;
 
 
 
 
 
 
 
 
 
 
283
  }
284
 
285
  #screen-container {
 
304
  -webkit-touch-callout: none;
305
  }
306
 
307
+ /* Hidden input to automatically trigger mobile keyboard */
308
  #hidden-input {
309
  position: absolute;
310
  opacity: 0;
 
333
  </div>
334
 
335
  <div id="status">
336
+ Ready
 
337
  </div>
338
 
339
  <div id="screen-container">
 
346
  <script>
347
 
348
  const screen = document.getElementById("screen");
349
+ const status = document.getElementById("status");
350
  const urlInput = document.getElementById("url");
351
  const hiddenInput = document.getElementById("hidden-input");
352
 
353
  let touching = false;
 
354
 
355
  async function navigate() {
356
  let url = urlInput.value.trim();
 
360
  url = "https://" + url;
361
  }
362
 
363
+ status.textContent = "Loading...";
364
 
365
  try {
366
  const response = await fetch("/navigate", {
 
378
  }
379
 
380
  show(data.image);
381
+ status.textContent = data.url;
382
  } catch (error) {
383
+ status.textContent = "Error: " + error.message;
384
  }
385
  }
386
 
 
427
  if (data.image) {
428
  show(data.image);
429
  }
430
+
431
+ // Action 'end' par check karega ki website par input field select hua ya nahi
432
+ if (action === "end") {
433
+ if (data.open_keyboard) {
434
+ hiddenInput.focus(); // Mobile ka keyboard apne aap khul jayega
435
+ } else {
436
+ hiddenInput.blur(); // Input par nahi hai to keyboard band ho jayega
437
+ }
438
+ }
439
  } catch (error) {
440
+ status.textContent = error.message;
441
  }
442
  }
443
 
 
457
  show(data.image);
458
  }
459
  } catch (error) {
460
+ status.textContent = error.message;
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  }
462
  }
463
 
 
472
  sendKey("Backspace");
473
  }
474
  lastLength = val.length;
 
475
  if(hiddenInput.value.length > 50) {
476
  hiddenInput.value = "";
477
  lastLength = 0;