@capybara-hq/plugin-browser 0.1.0-rc.11 → 0.1.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/plugin-browser",
3
- "version": "0.1.0-rc.11",
3
+ "version": "0.1.0-rc.12",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A real browser in the person's device for agents: navigate, read and act on pages through tools, with a live view in the conversation and takeover by the person",
@@ -15,7 +15,7 @@
15
15
  ".": "./dist/index.mjs"
16
16
  },
17
17
  "peerDependencies": {
18
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.75",
18
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.83",
19
19
  "zod": "^4.0.0"
20
20
  }
21
21
  }
package/ui/panel.js CHANGED
@@ -2,6 +2,10 @@
2
2
  (() => {
3
3
  // daemon/protocol.ts
4
4
  var VIEWPORT = { width: 1280, height: 800 };
5
+ var VIEWPORT_PROFILES = {
6
+ desktop: { width: VIEWPORT.width, height: VIEWPORT.height, mobile: false, scale: 1 },
7
+ phone: { width: 390, height: 844, mobile: true, scale: 2 }
8
+ };
5
9
  var IDLE_STOP_MS = 15 * 6e4;
6
10
  var VIEWER_TEXT_MAX_CHARS = 1e4;
7
11
  function clipCodePoints(text, max) {
@@ -63,6 +67,7 @@
63
67
  var DEFAULT_FRAME_MAX_BYTES = 256 * 1024;
64
68
  var CONVERSATION_IDLE_MS = 15 * 6e4;
65
69
  var EVICT_MIN_IDLE_MS = 5 * 6e4;
70
+ var WATCH_HEARTBEAT_MS = 10 * 6e4;
66
71
  var HANDOFF_KEEPALIVE_MS = 24 * 60 * 6e4;
67
72
  var FAVICON_MAX_BYTES = 8 * 1024;
68
73
  var isIconDataUrl = (s) => typeof s === "string" && s.length <= 64 + Math.ceil(FAVICON_MAX_BYTES * 4 / 3) && /^data:image\/(png|x-icon|gif|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/=]+$/.test(s);
@@ -82,6 +87,8 @@
82
87
  statusUser: "You are in control",
83
88
  statusUserDetail: "the agent is paused; press Esc to hand back",
84
89
  statusAgent: "The agent is working",
90
+ statusWaiting: "The agent is waiting for",
91
+ statusWaitingUntil: "until",
85
92
  statusUserElsewhere: "You are controlling the browser from another view",
86
93
  statusLoading: "loading the page",
87
94
  statusConnecting: "Connecting to the browser…",
@@ -114,7 +121,32 @@
114
121
  tabInUse: "Another conversation is using this tab; try again shortly",
115
122
  tabCap: "This conversation has the most tabs it can keep; close one first",
116
123
  treeEmptyTitle: "The agent has not opened a page in this conversation yet",
117
- treeEmptyBody: "Its pages show here as it opens them."
124
+ treeEmptyBody: "Its pages show here as it opens them.",
125
+ alertShown: "The page showed an alert:",
126
+ dlgConfirm: "The page asks you to confirm",
127
+ dlgPrompt: "The page asks for an answer",
128
+ dlgLeave: "The page asks whether to leave (changes may be lost)",
129
+ dlgAuth: "The site asks you to sign in",
130
+ dlgOk: "OK",
131
+ dlgCancel: "Cancel",
132
+ dlgLeaveGo: "Leave",
133
+ dlgLeaveStay: "Stay",
134
+ dlgSignIn: "Sign in",
135
+ dlgUsername: "Username",
136
+ dlgPassword: "Password",
137
+ dlgRealm: "Text from the site:",
138
+ dlgReadOnly: "Take over to answer",
139
+ permAsk: "asks for permission:",
140
+ permAllow: "Allow",
141
+ permNotifications: "notifications",
142
+ permClipboard: "reading the clipboard",
143
+ permGeolocation: "location (not available on this device)",
144
+ permCamera: "camera (not available on this device)",
145
+ permMicrophone: "microphone (not available on this device)",
146
+ phoneWidth: "Phone width",
147
+ desktopWidth: "Desktop width",
148
+ keyboard: "Keyboard",
149
+ phoneHint: "Phone width is easier to use on this screen."
118
150
  },
119
151
  zh: {
120
152
  title: "浏览器",
@@ -129,6 +161,8 @@
129
161
  statusUser: "你正在操作",
130
162
  statusUserDetail: "智能体已暂停,按 Esc 交还",
131
163
  statusAgent: "智能体正在操作",
164
+ statusWaiting: "智能体正在等待",
165
+ statusWaitingUntil: "至",
132
166
  statusUserElsewhere: "你正在另一个视图中控制浏览器",
133
167
  statusLoading: "正在加载页面",
134
168
  statusConnecting: "正在连接浏览器…",
@@ -161,7 +195,32 @@
161
195
  tabInUse: "该标签页正被其他对话使用,请稍后再试",
162
196
  tabCap: "此对话的标签页已达上限,请先关闭一个",
163
197
  treeEmptyTitle: "智能体尚未在此对话中打开网页",
164
- treeEmptyBody: "它打开的网页会显示在这里。"
198
+ treeEmptyBody: "它打开的网页会显示在这里。",
199
+ alertShown: "页面弹出了提示:",
200
+ dlgConfirm: "页面请你确认",
201
+ dlgPrompt: "页面请你输入",
202
+ dlgLeave: "页面询问是否离开(可能丢失更改)",
203
+ dlgAuth: "网站要求你登录",
204
+ dlgOk: "确定",
205
+ dlgCancel: "取消",
206
+ dlgLeaveGo: "离开",
207
+ dlgLeaveStay: "留下",
208
+ dlgSignIn: "登录",
209
+ dlgUsername: "用户名",
210
+ dlgPassword: "密码",
211
+ dlgRealm: "网站提供的文字:",
212
+ dlgReadOnly: "接管后可回答",
213
+ permAsk: "请求权限:",
214
+ permAllow: "允许",
215
+ permNotifications: "通知",
216
+ permClipboard: "读取剪贴板",
217
+ permGeolocation: "位置(此设备无法提供)",
218
+ permCamera: "摄像头(此设备无法提供)",
219
+ permMicrophone: "麦克风(此设备无法提供)",
220
+ phoneWidth: "手机宽度",
221
+ desktopWidth: "桌面宽度",
222
+ keyboard: "键盘",
223
+ phoneHint: "在这块屏幕上用手机宽度更好操作。"
165
224
  }
166
225
  };
167
226
  function t(locale, key) {
@@ -250,6 +309,7 @@
250
309
  }
251
310
  function applyCursor() {
252
311
  view.style.cursor = interactive() ? cursor : "default";
312
+ view.style.touchAction = interactive() ? "none" : "";
253
313
  }
254
314
  function queueMove(p) {
255
315
  nextMove = p;
@@ -318,6 +378,29 @@
318
378
  { passive: false }
319
379
  );
320
380
  view.addEventListener("contextmenu", (e) => e.preventDefault());
381
+ const touches = /* @__PURE__ */ new Map();
382
+ const touchPoints = () => [...touches].map(([id, p]) => ({ id, x: p.x, y: p.y }));
383
+ const isTouch = (e) => e.pointerType === "touch";
384
+ view.addEventListener("pointerdown", (e) => {
385
+ if (!isTouch(e) || !interactive()) return;
386
+ e.preventDefault();
387
+ touches.set(e.pointerId, opts.toPage(e.clientX, e.clientY));
388
+ send({ t: "touch", kind: "start", points: touchPoints() });
389
+ });
390
+ view.addEventListener("pointermove", (e) => {
391
+ if (!isTouch(e) || !touches.has(e.pointerId) || !interactive()) return;
392
+ e.preventDefault();
393
+ touches.set(e.pointerId, opts.toPage(e.clientX, e.clientY));
394
+ send({ t: "touch", kind: "move", points: touchPoints() });
395
+ });
396
+ const touchEnd = (kind) => (e) => {
397
+ if (!isTouch(e) || !touches.has(e.pointerId)) return;
398
+ touches.delete(e.pointerId);
399
+ if (!interactive()) return;
400
+ send({ t: "touch", kind, points: kind === "cancel" ? [] : touchPoints() });
401
+ };
402
+ win.addEventListener("pointerup", touchEnd("end"));
403
+ win.addEventListener("pointercancel", touchEnd("cancel"));
321
404
  const composing = (e) => e.isComposing || e.key === "Process" || e.keyCode === 229;
322
405
  const isPasteShortcut = (e) => (e.metaKey || e.ctrlKey) && !e.altKey && e.key.toLowerCase() === "v";
323
406
  function sendText(text) {
@@ -354,10 +437,19 @@
354
437
  if (interactive()) sendText(e.data ?? "");
355
438
  sink.value = "";
356
439
  });
440
+ function tapKey(key) {
441
+ send({ t: "key", kind: "down", key, code: key });
442
+ send({ t: "key", kind: "up", key, code: key });
443
+ }
357
444
  sink.addEventListener("input", (e) => {
358
445
  const ie = e;
359
446
  if (ie.isComposing || (ie.inputType ?? "").includes("Composition")) return;
360
- if (interactive()) sendText(sink.value);
447
+ if (interactive()) {
448
+ if (ie.inputType === "deleteContentBackward") tapKey("Backspace");
449
+ else if (ie.inputType === "insertLineBreak" || ie.inputType === "insertParagraph")
450
+ tapKey("Enter");
451
+ else sendText(sink.value);
452
+ }
361
453
  sink.value = "";
362
454
  });
363
455
  sink.addEventListener("paste", (e) => {
@@ -392,6 +484,11 @@
392
484
  focus() {
393
485
  focusWanted = !interactive();
394
486
  sink.focus();
487
+ },
488
+ keyboard() {
489
+ if (!interactive()) return;
490
+ sink.value = "";
491
+ sink.focus();
395
492
  }
396
493
  };
397
494
  }
@@ -544,6 +641,23 @@
544
641
  .strip .label { color: var(--cb-muted, #5E5E5A); }
545
642
  .strip:not(:has(button)) { padding-right: 12px; }
546
643
 
644
+ /* a held page dialog: a box over the picture until it is answered */
645
+ #pdialog { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: var(--cb-radius-md, 8px); background: var(--cb-raised, #fff); box-shadow: var(--cb-shadow-float, 0 8px 24px rgba(26,26,24,.12)), 0 0 0 1px var(--cb-line-soft, #E8E7E2); }
646
+ #pdialog .kind { margin: 0; color: var(--cb-muted, #5E5E5A); font-size: var(--cb-type-micro-size, 11px); line-height: var(--cb-type-micro-line, 14px); }
647
+ #pdialog .msg { margin: 0; font-family: var(--cb-font-prose, system-ui, sans-serif); overflow-wrap: anywhere; white-space: pre-wrap; max-height: 9em; overflow: auto; }
648
+ #pdialog .realm { margin: 0; color: var(--cb-muted, #5E5E5A); overflow-wrap: anywhere; }
649
+ #pdialog input { height: 32px; padding: 0 10px; border: 0; border-radius: var(--radius); box-shadow: inset 0 0 0 1px var(--cb-line, #D9D8D2); background: var(--cb-panel, #fff); }
650
+ #pdialog .actions { display: flex; justify-content: flex-end; gap: 6px; }
651
+ #pdialog .hint { margin: 0; color: var(--cb-muted, #5E5E5A); }
652
+
653
+ /* the takeover bar of a compact or touch screen: viewport, keyboard, hand back */
654
+ #touchbar { flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 12px; }
655
+ #touchbar .grow { flex: 1; }
656
+ @media (max-width: 599px), (pointer: coarse) {
657
+ #touchbar button, #pdialog button, #pdialog input, #permission button, #phonehint button { min-height: 44px; }
658
+ #touchbar button, #pdialog button { padding: 0 16px; }
659
+ }
660
+
547
661
  /* menus (narrow: tabs, more) */
548
662
  .menu { position: absolute; z-index: 2; min-width: 180px; max-width: calc(100% - 24px); max-height: 60%; overflow: auto; padding: 4px; border-radius: var(--cb-radius-md, 8px); background: var(--cb-raised, #fff); box-shadow: var(--cb-shadow-float, 0 8px 24px rgba(26,26,24,.08)), 0 0 0 1px var(--cb-line-soft, #E8E7E2); }
549
663
  .menu button { display: flex; width: 100%; justify-content: flex-start; gap: 8px; padding: 0 8px; text-align: left; overflow: hidden; text-overflow: ellipsis; }
@@ -590,12 +704,25 @@
590
704
  <p id="status" class="row" role="status"><span class="ico" id="status-icon"></span><span class="lead" id="status-lead"></span><span class="detail" id="status-detail"></span></p>
591
705
  <div id="verify" class="warn" hidden><span class="ico">${ICONS.pause}</span><div class="text"><span class="title" id="verify-title"></span><span class="body" id="verify-body"></span></div><div class="actions"><button type="button" id="verify-go" class="primary"></button></div></div>
592
706
  <div id="handoff" class="warn" hidden><span class="ico">${ICONS.pause}</span><div class="text"><span class="title" id="handoff-label"></span><span class="body" id="handoff-message"></span></div><div class="actions"><button type="button" id="handoff-done" class="primary"></button><button type="button" id="handoff-cancel" class="secondary"></button></div></div>
707
+ <div id="touchbar" hidden><button type="button" id="viewport-toggle" class="secondary"></button><button type="button" id="keyboard" class="secondary"></button><span class="grow"></span><button type="button" id="touch-handback" class="outline"></button></div>
593
708
  <div id="stage">
594
709
  <canvas id="view" tabindex="0"></canvas>
595
710
  <div id="flash" hidden></div>
711
+ <div id="pdialog" role="dialog" aria-modal="false" hidden>
712
+ <p class="kind" id="pdialog-kind"></p>
713
+ <p class="msg" id="pdialog-msg"></p>
714
+ <p class="realm" id="pdialog-realm" hidden></p>
715
+ <input id="pdialog-text" type="text" autocomplete="off" spellcheck="false" hidden>
716
+ <input id="pdialog-user" type="text" autocomplete="off" spellcheck="false" hidden>
717
+ <input id="pdialog-pass" type="password" autocomplete="off" hidden>
718
+ <div class="actions"><button type="button" id="pdialog-no" class="secondary"></button><button type="button" id="pdialog-yes" class="primary"></button></div>
719
+ <p class="hint" id="pdialog-hint" hidden></p>
720
+ </div>
596
721
  <div id="strips">
597
722
  <div id="blocked" class="strip" hidden><p><span id="blocked-label" class="label"></span> <span id="blocked-host"></span></p><button type="button" id="allow" class="primary"></button></div>
598
723
  <div id="dialog" class="strip" hidden><p><span id="dialog-label" class="label"></span> <span id="dialog-text"></span></p></div>
724
+ <div id="permission" class="strip" hidden><p><span id="permission-origin"></span> <span id="permission-label" class="label"></span> <span id="permission-name"></span></p><button type="button" id="permission-allow" class="primary"></button></div>
725
+ <div id="phonehint" class="strip" hidden><p id="phonehint-text"></p><button type="button" id="phonehint-go" class="primary"></button></div>
599
726
  <div id="notice" class="strip" role="alert" hidden><p><span id="notice-text"></span></p></div>
600
727
  </div>
601
728
  </div>
@@ -625,20 +752,20 @@
625
752
  var EMPTY_POLL_FOR_MS = 30 * 6e4;
626
753
  var STRIP_MS = 1e4;
627
754
  var PENDING_NAV_MS = 3e4;
628
- function letterbox(width, height) {
755
+ function letterbox(width, height, aspect = ASPECT) {
629
756
  let w = width;
630
- let h = Math.round(w / ASPECT);
757
+ let h = Math.round(w / aspect);
631
758
  if (h > height) {
632
759
  h = height;
633
- w = Math.round(h * ASPECT);
760
+ w = Math.round(h * aspect);
634
761
  }
635
762
  return { x: Math.round((width - w) / 2), y: Math.round((height - h) / 2), w, h };
636
763
  }
637
- function mapPoint(px, py, rect) {
764
+ function mapPoint(px, py, rect, vp = VIEWPORT) {
638
765
  const clamp = (v, max) => Math.max(0, Math.min(max, v));
639
766
  return {
640
- x: Math.round(clamp(px / rect.w, 1) * VIEWPORT.width),
641
- y: Math.round(clamp(py / rect.h, 1) * VIEWPORT.height)
767
+ x: Math.round(clamp(px / rect.w, 1) * vp.width),
768
+ y: Math.round(clamp(py / rect.h, 1) * vp.height)
642
769
  };
643
770
  }
644
771
  function mountPanel(opts) {
@@ -684,12 +811,19 @@
684
811
  let sentSize = "";
685
812
  let image = null;
686
813
  let layer = "skeleton";
814
+ let viewport = { width: VIEWPORT.width, height: VIEWPORT.height, mobile: false };
815
+ let boxDialog = null;
816
+ let permission = null;
817
+ let permissionTimer;
818
+ let phoneHinted = false;
687
819
  const compact = () => {
688
820
  const sw = win.screen?.width ?? 0;
689
821
  return sw > 0 && sw < COMPACT_BELOW;
690
822
  };
823
+ const coarse = () => win.matchMedia?.("(pointer: coarse)").matches === true;
691
824
  const text = (key) => t(locale, key);
692
- const interactive = () => !compact() && control === "user";
825
+ const interactive = () => control === "user";
826
+ const aspect = () => viewport.width / viewport.height;
693
827
  const treeEmpty = () => mode === "live" && lastState !== null && tabs.length === 0;
694
828
  function send(msg) {
695
829
  if (sock === null) return;
@@ -703,7 +837,12 @@
703
837
  interactive: () => interactive(),
704
838
  toPage: (clientX, clientY) => {
705
839
  const r = view.getBoundingClientRect();
706
- return mapPoint(clientX - r.left, clientY - r.top, { x: 0, y: 0, w: r.width, h: r.height });
840
+ return mapPoint(
841
+ clientX - r.left,
842
+ clientY - r.top,
843
+ { x: 0, y: 0, w: r.width, h: r.height },
844
+ viewport
845
+ );
707
846
  },
708
847
  label: t(locale, "view")
709
848
  });
@@ -732,6 +871,16 @@
732
871
  set("handoff-label", "handoff");
733
872
  set("handoff-done", "handoffDone");
734
873
  set("handoff-cancel", "handoffCancel");
874
+ set("permission-label", "permAsk");
875
+ set("permission-allow", "permAllow");
876
+ set("phonehint-text", "phoneHint");
877
+ set("phonehint-go", "phoneWidth");
878
+ set("keyboard", "keyboard");
879
+ set("touch-handback", "handback");
880
+ $("pdialog-user").setAttribute("aria-label", text("dlgUsername"));
881
+ $("pdialog-user").setAttribute("placeholder", text("dlgUsername"));
882
+ $("pdialog-pass").setAttribute("aria-label", text("dlgPassword"));
883
+ $("pdialog-pass").setAttribute("placeholder", text("dlgPassword"));
735
884
  input.sink.setAttribute("aria-label", text("view"));
736
885
  $("lock").setAttribute("aria-label", text("secure"));
737
886
  $("lock").setAttribute("title", text("secure"));
@@ -756,6 +905,7 @@
756
905
  let icon = "";
757
906
  let lead = null;
758
907
  let detail = null;
908
+ let waitingDetail = null;
759
909
  if (mode === "connecting") lead = "statusConnecting";
760
910
  else if (mode === "live" && control === "user") {
761
911
  if (interactive()) {
@@ -770,20 +920,29 @@
770
920
  icon = loading ? ICONS.spin : ICONS.dot;
771
921
  lead = "statusAgent";
772
922
  if (loading) detail = "statusLoading";
923
+ const waiting = lastState?.waiting;
924
+ if (waiting !== void 0 && !loading) {
925
+ lead = "statusWaiting";
926
+ const until = new Date(waiting.until);
927
+ const time = Number.isNaN(until.getTime()) ? "" : ` (${text("statusWaitingUntil")} ${until.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit" })})`;
928
+ waitingDetail = `${waiting.label}${time}`;
929
+ }
773
930
  }
774
931
  el.setAttribute("data-tone", tone);
775
932
  $("status-icon").innerHTML = icon;
776
933
  $("status-lead").textContent = lead === null ? "" : text(lead);
777
- $("status-detail").textContent = detail === null ? "" : ` · ${text(detail)}`;
934
+ $("status-detail").textContent = waitingDetail !== null ? ` · ${waitingDetail}` : detail === null ? "" : ` · ${text(detail)}`;
778
935
  }
779
936
  function renderChrome() {
780
- const watchOnly = compact();
781
937
  const readOnly = !interactive();
782
938
  const isLive = mode === "live";
783
- $("takeover").hidden = watchOnly || !isLive || control === "user";
784
- $("handback").hidden = watchOnly || !isLive || control !== "user";
785
- $("takeover").toggleAttribute("data-gone", watchOnly || isLive && control === "user");
786
- const verifying = isLive && control === "agent" && tabs.find((x) => x.active)?.blocker?.kind === "verification" && !watchOnly;
939
+ const bar = isLive && control === "user" && (compact() || coarse());
940
+ $("touchbar").hidden = !bar;
941
+ $("viewport-toggle").textContent = text(viewport.mobile ? "desktopWidth" : "phoneWidth");
942
+ $("takeover").hidden = !isLive || control === "user";
943
+ $("handback").hidden = !isLive || control !== "user" || bar;
944
+ $("takeover").toggleAttribute("data-gone", isLive && control === "user");
945
+ const verifying = isLive && control === "agent" && tabs.find((x) => x.active)?.blocker?.kind === "verification";
787
946
  $("verify").hidden = !verifying;
788
947
  $("takeover").className = verifying ? "secondary" : "primary";
789
948
  $("handoff").hidden = pendingHandoff === null || verifying;
@@ -814,9 +973,96 @@
814
973
  }
815
974
  $("blocked").hidden = blockedHost === "";
816
975
  $("blocked-host").textContent = blockedHost;
976
+ if (!isLive || control !== "user" || viewport.mobile) $("phonehint").hidden = true;
977
+ renderDialogBox();
978
+ renderPermission();
817
979
  renderStatus();
818
980
  renderLoading();
819
981
  }
982
+ function renderDialogBox() {
983
+ const d = mode === "live" && lastState !== null ? (lastState.dialogs ?? []).find((x) => x.tabId === lastState?.shown) ?? null : null;
984
+ const box = $("pdialog");
985
+ box.hidden = d === null;
986
+ if (d === null) {
987
+ boxDialog = null;
988
+ return;
989
+ }
990
+ const fresh = boxDialog?.id !== d.id;
991
+ boxDialog = d;
992
+ const kinds = {
993
+ confirm: "dlgConfirm",
994
+ prompt: "dlgPrompt",
995
+ beforeunload: "dlgLeave",
996
+ auth: "dlgAuth"
997
+ };
998
+ $("pdialog-kind").textContent = text(kinds[d.kind]);
999
+ $("pdialog-msg").textContent = d.kind === "auth" ? d.origin ?? "" : d.message;
1000
+ const realm = $("pdialog-realm");
1001
+ realm.hidden = d.kind !== "auth" || (d.realm ?? "") === "";
1002
+ realm.textContent = `${text("dlgRealm")} ${d.realm ?? ""}`;
1003
+ const answering = interactive();
1004
+ const field = $("pdialog-text");
1005
+ field.hidden = d.kind !== "prompt" || !answering;
1006
+ if (fresh) field.value = d.defaultValue ?? "";
1007
+ for (const id of ["pdialog-user", "pdialog-pass"]) {
1008
+ const input2 = $(id);
1009
+ input2.hidden = d.kind !== "auth" || !answering;
1010
+ if (fresh) input2.value = "";
1011
+ }
1012
+ const labels = {
1013
+ confirm: ["dlgOk", "dlgCancel"],
1014
+ prompt: ["dlgOk", "dlgCancel"],
1015
+ beforeunload: ["dlgLeaveGo", "dlgLeaveStay"],
1016
+ auth: ["dlgSignIn", "dlgCancel"]
1017
+ };
1018
+ const [yes, no] = labels[d.kind];
1019
+ $("pdialog-yes").textContent = text(yes);
1020
+ $("pdialog-no").textContent = text(no);
1021
+ $("pdialog-yes").hidden = !answering;
1022
+ $("pdialog-no").hidden = !answering;
1023
+ const hint = $("pdialog-hint");
1024
+ hint.hidden = answering;
1025
+ hint.textContent = text("dlgReadOnly");
1026
+ }
1027
+ function answerDialog(action) {
1028
+ const d = boxDialog;
1029
+ if (d === null || !interactive()) return;
1030
+ const pass = $("pdialog-pass");
1031
+ const msg = { t: "dialog", id: d.id, action };
1032
+ if (action === "accept" && d.kind === "prompt")
1033
+ msg.text = $("pdialog-text").value;
1034
+ if (action === "accept" && d.kind === "auth") {
1035
+ msg.username = $("pdialog-user").value;
1036
+ msg.password = pass.value;
1037
+ }
1038
+ pass.value = "";
1039
+ send(msg);
1040
+ }
1041
+ function renderPermission() {
1042
+ const p = permission;
1043
+ $("permission").hidden = p === null || mode !== "live";
1044
+ if (p === null) return;
1045
+ const names = {
1046
+ notifications: "permNotifications",
1047
+ "clipboard-read": "permClipboard",
1048
+ geolocation: "permGeolocation",
1049
+ camera: "permCamera",
1050
+ microphone: "permMicrophone"
1051
+ };
1052
+ $("permission-origin").textContent = p.origin;
1053
+ const key = names[p.permission];
1054
+ $("permission-name").textContent = key === void 0 ? p.permission : text(key);
1055
+ $("permission-allow").hidden = !p.grantable || !interactive();
1056
+ }
1057
+ function showPermission(m) {
1058
+ permission = { origin: m.origin, permission: m.permission, grantable: m.grantable };
1059
+ renderPermission();
1060
+ if (permissionTimer !== void 0) clearTimeout(permissionTimer);
1061
+ permissionTimer = setTimeout(() => {
1062
+ permission = null;
1063
+ renderPermission();
1064
+ }, STRIP_MS);
1065
+ }
820
1066
  function renderLoading() {
821
1067
  const idleMode = mode === "empty" || mode === "offline" || mode === "error" || treeEmpty();
822
1068
  let next;
@@ -1013,10 +1259,16 @@
1013
1259
  $("handoff-message").textContent = pendingHandoff?.message ?? "";
1014
1260
  tabs = s.tabs;
1015
1261
  otherTabs = s.otherTabs;
1262
+ if (s.viewport !== void 0) viewport = s.viewport;
1016
1263
  if (tabs.length === 0) image = null;
1017
1264
  const was = control;
1018
1265
  control = s.control;
1019
1266
  if (full && was === "user" && control === "agent") askMode(false);
1267
+ if (control === "agent") phoneHinted = false;
1268
+ if (was === "agent" && control === "user" && compact() && !viewport.mobile && !phoneHinted) {
1269
+ phoneHinted = true;
1270
+ $("phonehint").hidden = false;
1271
+ }
1020
1272
  if (was === "user" && control === "agent" && pendingNav?.sentOn === sock) pendingNav = null;
1021
1273
  const active = tabs.find((x) => x.active);
1022
1274
  if (doc.activeElement !== url) url.value = active?.url ?? "";
@@ -1040,8 +1292,8 @@
1040
1292
  const flash = $("flash");
1041
1293
  const r = view.getBoundingClientRect();
1042
1294
  const st = stage.getBoundingClientRect();
1043
- flash.style.left = `${r.left - st.left + x / VIEWPORT.width * r.width}px`;
1044
- flash.style.top = `${r.top - st.top + y / VIEWPORT.height * r.height}px`;
1295
+ flash.style.left = `${r.left - st.left + x / viewport.width * r.width}px`;
1296
+ flash.style.top = `${r.top - st.top + y / viewport.height * r.height}px`;
1045
1297
  flash.hidden = false;
1046
1298
  win.setTimeout(() => {
1047
1299
  flash.hidden = true;
@@ -1056,7 +1308,7 @@
1056
1308
  }
1057
1309
  if (p.sentOn !== sock && sock !== null) {
1058
1310
  p.sentOn = sock;
1059
- if (control !== "user" && !compact()) takeover();
1311
+ if (control !== "user") takeover();
1060
1312
  send({ t: "nav", url: p.url });
1061
1313
  }
1062
1314
  }
@@ -1090,14 +1342,15 @@
1090
1342
  const st = stage.getBoundingClientRect();
1091
1343
  const box = letterbox(
1092
1344
  Math.max(0, Math.floor(st.width) - 2 * STAGE_PAD),
1093
- Math.max(0, Math.floor(st.height) - 2 * STAGE_PAD)
1345
+ Math.max(0, Math.floor(st.height) - 2 * STAGE_PAD),
1346
+ aspect()
1094
1347
  );
1095
1348
  view.style.width = `${box.w}px`;
1096
1349
  view.style.height = `${box.h}px`;
1097
1350
  const dpr = win.devicePixelRatio || 1;
1098
- const cap = control === "user" || full ? VIEWPORT.width : SIDE_MAX_WIDTH;
1351
+ const cap = control === "user" || full ? viewport.width : SIDE_MAX_WIDTH;
1099
1352
  const w = Math.max(1, Math.min(cap, Math.round(box.w * Math.min(dpr, MAX_DPR))));
1100
- return { w, h: Math.max(1, Math.round(w / ASPECT)) };
1353
+ return { w, h: Math.max(1, Math.round(w / aspect())) };
1101
1354
  }
1102
1355
  function onBoxChange() {
1103
1356
  if (sock === null || mode !== "live") return;
@@ -1250,6 +1503,9 @@
1250
1503
  case "dialog":
1251
1504
  showDialog(msg);
1252
1505
  break;
1506
+ case "permission":
1507
+ showPermission(msg);
1508
+ break;
1253
1509
  case "notice":
1254
1510
  if (msg.code === "tab_in_use") notice("tabInUse", "");
1255
1511
  else if (msg.code === "tab_cap") notice("tabCap", "");
@@ -1289,7 +1545,7 @@
1289
1545
  }
1290
1546
  function takeover() {
1291
1547
  send({ t: "takeover" });
1292
- askMode(true);
1548
+ if (!compact()) askMode(true);
1293
1549
  input.focus();
1294
1550
  renderChrome();
1295
1551
  }
@@ -1400,6 +1656,30 @@
1400
1656
  closeMenu();
1401
1657
  });
1402
1658
  $("handback").addEventListener("click", handback);
1659
+ $("touch-handback").addEventListener("click", handback);
1660
+ $("viewport-toggle").addEventListener("click", () => {
1661
+ if (!interactive()) return;
1662
+ $("phonehint").hidden = true;
1663
+ send({ t: "viewport", profile: viewport.mobile ? "desktop" : "phone" });
1664
+ });
1665
+ $("phonehint-go").addEventListener("click", () => {
1666
+ $("phonehint").hidden = true;
1667
+ if (interactive()) send({ t: "viewport", profile: "phone" });
1668
+ });
1669
+ $("keyboard").addEventListener("click", () => input.keyboard());
1670
+ $("pdialog-yes").addEventListener("click", () => answerDialog("accept"));
1671
+ $("pdialog-no").addEventListener("click", () => answerDialog("dismiss"));
1672
+ for (const id of ["pdialog-text", "pdialog-pass"])
1673
+ $(id).addEventListener("keydown", (e) => {
1674
+ if (e.key === "Enter") answerDialog("accept");
1675
+ });
1676
+ $("permission-allow").addEventListener("click", () => {
1677
+ const p = permission;
1678
+ if (p === null || !p.grantable || !interactive()) return;
1679
+ send({ t: "permission", origin: p.origin, permission: p.permission, allow: true });
1680
+ permission = null;
1681
+ renderPermission();
1682
+ });
1403
1683
  $("handoff-done").addEventListener("click", () => void answerHandoff(true));
1404
1684
  $("handoff-cancel").addEventListener("click", () => void answerHandoff(false));
1405
1685
  $("allow").addEventListener("click", () => void allowHost());