dsh-builtin-browser 1.0.0 → 1.0.3

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.
Files changed (364) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/pr64-maintenance.md +1 -1
  19. package/docs/tool-reference.md +1 -1
  20. package/docs/user-guide.md +1 -1
  21. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  22. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  23. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  24. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  25. package/dsh-host-patch/README.md +4 -0
  26. package/dsh-host-patch/apply.mjs +61 -13
  27. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  28. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  29. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  30. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  31. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  32. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  33. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  34. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  35. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  36. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  37. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  38. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  39. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  40. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  41. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  42. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  43. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  44. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  45. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  46. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  47. package/dsh-host-patch/sources/manifest.json +218 -0
  48. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  49. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  50. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  51. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  52. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  53. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  54. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  55. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  56. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  57. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  58. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  59. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  60. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  61. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  62. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  63. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  64. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  65. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  66. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  67. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  68. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  69. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  70. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  71. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  72. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  73. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  74. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  75. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  76. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  77. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  78. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  79. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  80. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  81. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  82. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  83. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  84. package/dsh-host-patch/sources/series.json +260 -0
  85. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  86. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  87. package/dsh-host-patch/tauri-revision1.json +39 -0
  88. package/dsh-host-patch/tauri.json +43 -0
  89. package/dsh-host-patch/v023-alpha2.json +153 -0
  90. package/lib/browser/anti-bot.js +215 -0
  91. package/lib/browser/deep-dom.js +39 -0
  92. package/lib/browser/runtime.js +15 -0
  93. package/lib/browser/takeover-target.js +13 -6
  94. package/lib/browser/types.js +30 -1
  95. package/lib/browser-electron/authenticated-route.js +16 -2
  96. package/lib/browser-electron/automatic-maintenance.js +16 -10
  97. package/lib/browser-electron/bridge-connection.js +3 -8
  98. package/lib/browser-electron/bridge-install.js +2 -1
  99. package/lib/browser-electron/bridge-status.js +55 -26
  100. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  101. package/lib/browser-electron/desktop-identity.js +28 -5
  102. package/lib/browser-electron/desktop-shell.js +64 -0
  103. package/lib/browser-electron/electron-provision.js +105 -18
  104. package/lib/browser-electron/entry.js +129 -46
  105. package/lib/browser-electron/extension-browser.js +4 -4
  106. package/lib/browser-electron/foreground-watch.js +134 -0
  107. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  108. package/lib/browser-electron/guest-route.js +181 -32
  109. package/lib/browser-electron/guest-runtime.js +61 -10
  110. package/lib/browser-electron/guest-storage.js +2 -2
  111. package/lib/browser-electron/history-store.js +1 -5
  112. package/lib/browser-electron/host-main.js +8 -4
  113. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  114. package/lib/browser-electron/maintenance-route.js +2 -1
  115. package/lib/browser-electron/missing-system-browser.js +5 -9
  116. package/lib/browser-electron/preferred-browser.js +7 -3
  117. package/lib/browser-electron/preview-route.js +9 -13
  118. package/lib/browser-electron/process-ownership.js +1 -1
  119. package/lib/browser-electron/profile-command.js +2 -1
  120. package/lib/browser-electron/profile-extension.js +5 -0
  121. package/lib/browser-electron/profile-lease.js +152 -47
  122. package/lib/browser-electron/provider-core.js +527 -0
  123. package/lib/browser-electron/provider-interaction.js +963 -0
  124. package/lib/browser-electron/provider-media.js +518 -0
  125. package/lib/browser-electron/provider-navigation.js +301 -0
  126. package/lib/browser-electron/provider-observation.js +623 -0
  127. package/lib/browser-electron/provider-tabs.js +372 -0
  128. package/lib/browser-electron/provider.js +150 -3301
  129. package/lib/browser-electron/reference-route.js +9 -18
  130. package/lib/browser-electron/remote-host.js +79 -34
  131. package/lib/browser-electron/runtime-status.js +56 -6
  132. package/lib/browser-electron/settings-store.js +3 -6
  133. package/lib/browser-electron/sidebar-only-host.js +1 -1
  134. package/lib/browser-electron/system-browser.js +539 -172
  135. package/lib/browser-electron/tauri-host.js +208 -0
  136. package/lib/browser-electron/virtual-cursor.js +23 -13
  137. package/lib/browser-reference/service.js +22 -4
  138. package/lib/browser-reference/web-sources.js +1 -1
  139. package/lib/client.js +43409 -0
  140. package/lib/compat/host-features.js +75 -0
  141. package/lib/reference-source.js +1 -1
  142. package/lib/reference-text.js +23 -1
  143. package/lib/takeover-protocol.js +1 -1
  144. package/lib/tool-browser/block-recovery.js +69 -0
  145. package/lib/tool-browser/code-tool.js +170 -19
  146. package/lib/tool-browser/code-worker.js +115 -20
  147. package/lib/tool-browser/errors.js +34 -0
  148. package/lib/tool-browser/index.js +66 -3593
  149. package/lib/tool-browser/page-probe.js +227 -28
  150. package/lib/tool-browser/panel-page.js +2 -1
  151. package/lib/tool-browser/probe-client.js +157 -0
  152. package/lib/tool-browser/screenshot-annotations.js +108 -0
  153. package/lib/tool-browser/state.js +337 -0
  154. package/lib/tool-browser/takeover.js +1 -1
  155. package/lib/tool-browser/tools-debug.js +862 -0
  156. package/lib/tool-browser/tools-interaction.js +993 -0
  157. package/lib/tool-browser/tools-navigation.js +807 -0
  158. package/lib/tool-browser/tools-observation.js +461 -0
  159. package/lib/tool-browser/tools-reference.js +293 -0
  160. package/lib/web-guest.js +1 -0
  161. package/package.json +16 -54
  162. package/README.en.md +0 -89
  163. package/browser-extension/constants.mjs +0 -20
  164. package/browser-extension/controller.mjs +0 -293
  165. package/browser-extension/locales.mjs +0 -15
  166. package/browser-extension/manifest.json +0 -12
  167. package/browser-extension/options.html +0 -14
  168. package/browser-extension/options.mjs +0 -9
  169. package/browser-extension/permission-guard.mjs +0 -13
  170. package/browser-extension/worker.mjs +0 -74
  171. package/dist/client.cjs +0 -43167
  172. package/lib/browser-electron/package-removal.js +0 -5
  173. package/lib/browser-reference/submission-receipts.js +0 -139
  174. package/scripts/build.mjs +0 -66
  175. package/scripts/bundle-host.mjs +0 -28
  176. package/scripts/fix-exports.mjs +0 -50
  177. package/scripts/install-electron.mjs +0 -51
  178. package/scripts/verify-exports.mjs +0 -47
  179. package/scripts/verify-preview-sdk.mjs +0 -93
  180. package/skills/dsh-builtin-browser/SKILL.md +0 -73
  181. package/skills/dsh-builtin-browser/references/batch.md +0 -53
  182. package/skills/dsh-builtin-browser/references/deliver.md +0 -31
  183. package/skills/dsh-builtin-browser/references/locate.md +0 -11
  184. package/skills/dsh-builtin-browser/references/recover.md +0 -11
  185. package/skills/dsh-builtin-browser/references/verify.md +0 -13
  186. package/skills/dsh-debug-host/SKILL.md +0 -56
  187. package/skills/dsh-debug-self/SKILL.md +0 -50
  188. package/src/bridge-compatibility.ts +0 -39
  189. package/src/browser/handles.ts +0 -89
  190. package/src/browser/runtime.ts +0 -560
  191. package/src/browser/takeover-target.ts +0 -36
  192. package/src/browser/types.ts +0 -817
  193. package/src/browser-electron/authenticated-route.ts +0 -84
  194. package/src/browser-electron/automatic-maintenance.ts +0 -726
  195. package/src/browser-electron/bridge-auto.ts +0 -159
  196. package/src/browser-electron/bridge-connection.ts +0 -385
  197. package/src/browser-electron/bridge-endpoint.ts +0 -129
  198. package/src/browser-electron/bridge-install.ts +0 -289
  199. package/src/browser-electron/bridge-maintenance.ts +0 -189
  200. package/src/browser-electron/bridge-status.ts +0 -347
  201. package/src/browser-electron/desktop-bridge-host.ts +0 -251
  202. package/src/browser-electron/desktop-identity.ts +0 -320
  203. package/src/browser-electron/document-readiness.ts +0 -45
  204. package/src/browser-electron/electron-provision.ts +0 -261
  205. package/src/browser-electron/entry.ts +0 -1301
  206. package/src/browser-electron/ephemeral-profile.ts +0 -189
  207. package/src/browser-electron/extension-browser.ts +0 -223
  208. package/src/browser-electron/extension-setup.ts +0 -67
  209. package/src/browser-electron/file-write.ts +0 -31
  210. package/src/browser-electron/guest-cookie-jar.ts +0 -176
  211. package/src/browser-electron/guest-cookie-store.ts +0 -59
  212. package/src/browser-electron/guest-css-runtime.ts +0 -76
  213. package/src/browser-electron/guest-css.ts +0 -68
  214. package/src/browser-electron/guest-route.ts +0 -568
  215. package/src/browser-electron/guest-runtime.ts +0 -357
  216. package/src/browser-electron/guest-storage-runtime.ts +0 -54
  217. package/src/browser-electron/guest-storage.ts +0 -117
  218. package/src/browser-electron/history-store.ts +0 -227
  219. package/src/browser-electron/host-main.ts +0 -1381
  220. package/src/browser-electron/host-patch-maintenance.ts +0 -112
  221. package/src/browser-electron/http-body.ts +0 -65
  222. package/src/browser-electron/json-reply.ts +0 -47
  223. package/src/browser-electron/maintenance-broker.ts +0 -166
  224. package/src/browser-electron/maintenance-lifecycle.ts +0 -91
  225. package/src/browser-electron/maintenance-route.ts +0 -67
  226. package/src/browser-electron/missing-system-browser.ts +0 -113
  227. package/src/browser-electron/open-slot.ts +0 -49
  228. package/src/browser-electron/package-removal.ts +0 -4
  229. package/src/browser-electron/paths.ts +0 -25
  230. package/src/browser-electron/preferred-browser.ts +0 -120
  231. package/src/browser-electron/preview-route.ts +0 -218
  232. package/src/browser-electron/process-ownership.ts +0 -168
  233. package/src/browser-electron/process.ts +0 -23
  234. package/src/browser-electron/profile-checkpoint.ts +0 -187
  235. package/src/browser-electron/profile-command.ts +0 -46
  236. package/src/browser-electron/profile-extension.ts +0 -124
  237. package/src/browser-electron/profile-lease.ts +0 -115
  238. package/src/browser-electron/profile-residue.ts +0 -49
  239. package/src/browser-electron/provider.ts +0 -4571
  240. package/src/browser-electron/reference-route.ts +0 -608
  241. package/src/browser-electron/remote-host.ts +0 -1462
  242. package/src/browser-electron/rpc-input.ts +0 -13
  243. package/src/browser-electron/rpc-ops.ts +0 -41
  244. package/src/browser-electron/runtime-diagnostics.ts +0 -38
  245. package/src/browser-electron/runtime-route.ts +0 -105
  246. package/src/browser-electron/runtime-status.ts +0 -242
  247. package/src/browser-electron/settings-route.ts +0 -64
  248. package/src/browser-electron/settings-store.ts +0 -589
  249. package/src/browser-electron/shortcuts-route.ts +0 -112
  250. package/src/browser-electron/sidebar-only-host.ts +0 -298
  251. package/src/browser-electron/startpage-shortcuts.ts +0 -213
  252. package/src/browser-electron/system-browser.ts +0 -1497
  253. package/src/browser-electron/timing.ts +0 -16
  254. package/src/browser-electron/virtual-cursor.ts +0 -152
  255. package/src/browser-electron/windows-system.ts +0 -24
  256. package/src/browser-reference/delivery.ts +0 -384
  257. package/src/browser-reference/entry.ts +0 -631
  258. package/src/browser-reference/export.ts +0 -339
  259. package/src/browser-reference/import.ts +0 -303
  260. package/src/browser-reference/page-script.ts +0 -1537
  261. package/src/browser-reference/service.ts +0 -1315
  262. package/src/browser-reference/store.ts +0 -172
  263. package/src/browser-reference/submission-receipts.ts +0 -122
  264. package/src/browser-reference/text-quote.ts +0 -219
  265. package/src/browser-reference/types.ts +0 -195
  266. package/src/browser-reference/visible.ts +0 -367
  267. package/src/browser-reference/web-sources.ts +0 -103
  268. package/src/client/browser/BrowserController.ts +0 -693
  269. package/src/client/browser/BrowserFrame.ts +0 -78
  270. package/src/client/browser/BrowserNavigation.ts +0 -169
  271. package/src/client/browser/BrowserPage.ts +0 -23
  272. package/src/client/browser/BrowserPersistence.ts +0 -44
  273. package/src/client/browser/IframeImpl.ts +0 -176
  274. package/src/client/browser/child-tabs.ts +0 -14
  275. package/src/client/browser/iframe-reference.ts +0 -67
  276. package/src/client/browser/initialization.ts +0 -262
  277. package/src/client/browser/omnibox.ts +0 -243
  278. package/src/client/browser/store.ts +0 -38
  279. package/src/client/browser/takeover-channel.ts +0 -72
  280. package/src/client/browser/url.ts +0 -46
  281. package/src/client/browser/web-reference-source.ts +0 -52
  282. package/src/client/css-modules.d.ts +0 -4
  283. package/src/client/definition.tsx +0 -30
  284. package/src/client/electron/ElectronWebViewImpl.ts +0 -364
  285. package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
  286. package/src/client/electron/NativeChildPresentation.ts +0 -45
  287. package/src/client/electron/NativeViewPage.ts +0 -251
  288. package/src/client/electron/pages.ts +0 -23
  289. package/src/client/electron/reference-overlay.ts +0 -53
  290. package/src/client/electron/workspace.ts +0 -33
  291. package/src/client/index.ts +0 -293
  292. package/src/client/locales.ts +0 -857
  293. package/src/client/pages.ts +0 -28
  294. package/src/client/reference/client/BrowserRefLink.tsx +0 -142
  295. package/src/client/reference/client/draft-reference.ts +0 -167
  296. package/src/client/reference/client/index.ts +0 -7
  297. package/src/client/reference/client/ordered-submission.ts +0 -108
  298. package/src/client/reference/client/pending-delivery.ts +0 -216
  299. package/src/client/reference/client/plugin.ts +0 -189
  300. package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
  301. package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
  302. package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
  303. package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
  304. package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
  305. package/src/client/reference/client/production/ReferenceText.tsx +0 -36
  306. package/src/client/reference/client/production/assembly.ts +0 -471
  307. package/src/client/reference/client/production/asset-store.ts +0 -144
  308. package/src/client/reference/client/production/availability.ts +0 -74
  309. package/src/client/reference/client/production/bytes.ts +0 -36
  310. package/src/client/reference/client/production/delivery-client.ts +0 -211
  311. package/src/client/reference/client/production/draft-adapter.ts +0 -508
  312. package/src/client/reference/client/production/http-transport.ts +0 -217
  313. package/src/client/reference/client/production/production-submission.ts +0 -310
  314. package/src/client/reference/client/production/protocol.ts +0 -231
  315. package/src/client/reference/client/production/reference-card.ts +0 -240
  316. package/src/client/reference/client/production/reference-labels.ts +0 -29
  317. package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
  318. package/src/client/reference/client/production/reveal.ts +0 -215
  319. package/src/client/reference/client/production/runtime.ts +0 -1101
  320. package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
  321. package/src/client/reference/client/production/source-marker.ts +0 -63
  322. package/src/client/reference/client/production/source-opener.ts +0 -55
  323. package/src/client/reference/client/production/styles.ts +0 -104
  324. package/src/client/reference/client/production/user-text-rule.ts +0 -58
  325. package/src/client/reference/client/reveal.ts +0 -107
  326. package/src/client/reference/client/scheme.ts +0 -114
  327. package/src/client/reference/client/types.ts +0 -168
  328. package/src/client/reference/css-modules.d.ts +0 -4
  329. package/src/client/reference/index.ts +0 -11
  330. package/src/client/reference-capture-owner.ts +0 -162
  331. package/src/client/reference-intents.ts +0 -36
  332. package/src/client/settings/index.ts +0 -34
  333. package/src/client/settings/panel.ts +0 -2657
  334. package/src/client/shortcut-open.ts +0 -30
  335. package/src/client/startpage/binding.ts +0 -99
  336. package/src/client/startpage/controller.ts +0 -303
  337. package/src/client/startpage/model.ts +0 -279
  338. package/src/client/view/Browser.module.css +0 -751
  339. package/src/client/view/BrowserBody.tsx +0 -314
  340. package/src/client/view/BrowserPresentation.ts +0 -9
  341. package/src/client/view/BrowserTitle.tsx +0 -17
  342. package/src/client/view/IframePresentation.ts +0 -344
  343. package/src/client/view/StartPage.tsx +0 -597
  344. package/src/client/view/TakeoverBanner.tsx +0 -21
  345. package/src/index.ts +0 -110
  346. package/src/reference-owner.ts +0 -5
  347. package/src/reference-page.ts +0 -9
  348. package/src/reference-source.ts +0 -3
  349. package/src/reference-text.ts +0 -197
  350. package/src/startpage-settings.ts +0 -103
  351. package/src/startpage.ts +0 -71
  352. package/src/takeover-protocol.ts +0 -19
  353. package/src/tool-browser/code-tool.ts +0 -401
  354. package/src/tool-browser/code-worker.ts +0 -639
  355. package/src/tool-browser/element-fields.ts +0 -167
  356. package/src/tool-browser/index.ts +0 -3733
  357. package/src/tool-browser/page-probe.ts +0 -474
  358. package/src/tool-browser/panel-page.ts +0 -124
  359. package/src/tool-browser/screenshot-image.ts +0 -49
  360. package/src/tool-browser/takeover.ts +0 -198
  361. package/src/types/electron-shim.d.ts +0 -144
  362. package/src/types.ts +0 -85
  363. package/src/web-guest.ts +0 -34
  364. package/tools/accept-desktop.mjs +0 -148
@@ -0,0 +1,623 @@
1
+ import { DEFAULT_OPERATION_TIMEOUT_MS } from '../../assets/browser-policy.mjs';
2
+ import { BrowserError } from '../browser/types.js';
3
+ import { DEEP_DOM_SOURCE } from '../browser/deep-dom.js';
4
+ import { challengeDetectSource } from '../browser/anti-bot.js';
5
+ import { PROVIDER_TIMEOUTS, TARGET_SCRIPT_GRACE_MS, delay, pagePollSlice, withTimeout, handleSendEvaluate } from './provider-core.js';
6
+ import { ProviderNavigation } from './provider-navigation.js';
7
+ /** Page-context block / human-verification detection; the classifier lives in `browser/anti-bot.ts`. */
8
+ const CHALLENGE_DETECT_EXPRESSION = challengeDetectSource();
9
+ /** Cap on content returned by a snapshot fetch to keep the wire bounded. */
10
+ const SNAPSHOT_LABEL_MAX = 120;
11
+ export class ProviderObservation extends ProviderNavigation {
12
+ /**
13
+ * Poll until the active tab's page is ready (and optional URL/selector
14
+ * match), or the budget runs out. Returns a verdict instead of throwing on
15
+ * timeout — the caller (model) decides what a miss means. Polling evaluates
16
+ * in the CURRENT document, so after a navigation the old document may
17
+ * briefly answer; pass the expected `url` to disambiguate.
18
+ */
19
+ async waitFor(session, request, signal) {
20
+ const tab = this.activeTab(this.session(session));
21
+ signal?.throwIfAborted();
22
+ const timeoutMs = request.timeoutMs ?? DEFAULT_OPERATION_TIMEOUT_MS;
23
+ const deadline = Date.now() + timeoutMs;
24
+ const url = request.url ?? '';
25
+ const selector = request.selector ?? '';
26
+ const checkLoaded = request.loaded !== false;
27
+ const expression = `(() => {${DEEP_DOM_SOURCE}
28
+ const wantUrl = ${JSON.stringify(url)}
29
+ const wantSelector = ${JSON.stringify(selector)}
30
+ const inDoc = (_doc, sel) => { try { return __dshQuery(sel) !== null } catch { return false } }
31
+ const href = location.href
32
+ // Exact match wins; otherwise prefix-match within the SAME origin only,
33
+ // so wantUrl "https://a.com" never matches a cross-origin page whose
34
+ // host merely starts with the same characters ("https://a.com.evil.com").
35
+ let urlOk = wantUrl === '' || href === wantUrl
36
+ if (!urlOk && wantUrl !== '') {
37
+ try {
38
+ const want = new URL(wantUrl)
39
+ const got = new URL(href)
40
+ urlOk = want.origin === got.origin && href.startsWith(wantUrl)
41
+ } catch { urlOk = false }
42
+ }
43
+ const loadedOk = document.readyState === 'complete' || document.readyState === 'interactive'
44
+ const foundOk = wantSelector === '' || inDoc(document, wantSelector)
45
+ return { urlOk, loadedOk, foundOk }
46
+ })()`;
47
+ for (;;) {
48
+ const result = await withTimeout(handleSendEvaluate(tab.handle, expression), Math.min(PROVIDER_TIMEOUTS.interaction, Math.max(250, deadline - Date.now())), signal, 'browser: wait poll timed out', timedOut => { this.interrupt(tab.handle, timedOut); });
49
+ if (!result.ok) {
50
+ throw new BrowserError(`browser: wait failed: ${result.exception}`, 'BROWSER_WAIT_FAILED');
51
+ }
52
+ const state = result.value;
53
+ const urlOk = url === '' || state.urlOk === true;
54
+ const loadedOk = !checkLoaded || state.loadedOk === true;
55
+ const foundOk = selector === '' || state.foundOk === true;
56
+ if (urlOk && loadedOk && foundOk) {
57
+ return { ready: true, reason: 'condition met' };
58
+ }
59
+ if (Date.now() >= deadline) {
60
+ const misses = [];
61
+ if (!urlOk)
62
+ misses.push(`url not yet "${url}"`);
63
+ if (!loadedOk)
64
+ misses.push('page not loaded');
65
+ if (!foundOk)
66
+ misses.push(`selector "${selector}" not found`);
67
+ return { ready: false, reason: misses.join('; ') };
68
+ }
69
+ // Sleep between polls, abortable by the caller.
70
+ // Sleep between polls; delay() removes its abort listener on both paths, which the
71
+ // hand-rolled version here did not — a 30s wait leaked about 150 of them.
72
+ await delay(200, signal);
73
+ }
74
+ }
75
+ /** Produce an AI-friendly snapshot of the active tab. */
76
+ async snapshot(session, signal) {
77
+ const s = this.session(session);
78
+ const tab = this.activeTab(s);
79
+ signal?.throwIfAborted();
80
+ // A tab that has never navigated is a blank, uncommitted view. The collector cannot answer in
81
+ // it — there is no document to commit — so the call would sit out its whole budget before
82
+ // saying anything. Answering the empty page immediately is both faster and more truthful.
83
+ //
84
+ // `about:blank` needs the same answer for a different reason: it HAS a document, so the collector
85
+ // runs, finds nothing, and returns zero elements — indistinguishable from a real page with nothing
86
+ // interactive. A caller then acts on it and receives success values, which is how a carrier swap
87
+ // that started a fresh window looked like working tools operating on the wrong page (issue #37).
88
+ const blankUrl = tab.url === '' || tab.url === 'about:blank';
89
+ if (blankUrl) {
90
+ return {
91
+ url: tab.url,
92
+ elements: [],
93
+ truncated: false,
94
+ blank: true,
95
+ note: tab.url === ''
96
+ ? 'no page has been opened in this browser yet'
97
+ : 'the page is about:blank — nothing has been opened in this browser, so there is nothing to read or drive',
98
+ };
99
+ }
100
+ const script = `(() => {
101
+ const cap = ${String(this.snapshotMaxElements)}
102
+ const url = location.href
103
+ const title = document.title || undefined
104
+ // Collect interactive elements from the top document AND from shadow
105
+ // roots and same-origin iframes (cross-origin iframes stay opaque — the
106
+ // browser forbids reading them, and so does this snapshot). Elements
107
+ // inside iframes carry a frame flag so the model knows DOM selectors
108
+ // are frame-scoped; coordinates below are always top-document.
109
+ const SELECTOR = 'input, textarea, select, button, a[href], [role="button"], [role="searchbox"], [contenteditable="true"]'
110
+ const els = []
111
+ const seen = new Set()
112
+ const collect = (doc, inFrame) => {
113
+ if (seen.has(doc)) return
114
+ seen.add(doc)
115
+ const hosts = []
116
+ for (const el of doc.querySelectorAll('*')) {
117
+ if (el.matches(SELECTOR)) els.push({ el, inFrame })
118
+ if (el.shadowRoot) hosts.push({ doc: el.shadowRoot, inFrame })
119
+ if (el.tagName === 'IFRAME') {
120
+ try { const d = el.contentDocument; if (d) hosts.push({ doc: d, inFrame: true }) } catch { /* cross-origin */ }
121
+ }
122
+ }
123
+ for (const h of hosts) collect(h.doc, h.inFrame)
124
+ }
125
+ collect(document, false)
126
+ // Absolute viewport coordinates in the TOP document: iframe content is
127
+ // offset by each ancestor iframe's rect, so coordinate clicks land on
128
+ // the right element no matter which frame it lives in.
129
+ const absRect = (el, doc) => {
130
+ const r = el.getBoundingClientRect()
131
+ let x = r.x, y = r.y
132
+ let d = doc
133
+ while (d && d.defaultView && d.defaultView.frameElement) {
134
+ const fr = d.defaultView.frameElement.getBoundingClientRect()
135
+ x += fr.x; y += fr.y
136
+ d = d.defaultView.frameElement.ownerDocument
137
+ }
138
+ return { x, y, w: r.width, h: r.height }
139
+ }
140
+ const out = []
141
+ for (const { el, inFrame } of els) {
142
+ if (out.length >= cap) break
143
+ const r = el.getBoundingClientRect()
144
+ // Cheap layout check first; only force style recalc when it passes.
145
+ if (r.width < 4 || r.height < 4) continue
146
+ const cs = getComputedStyle(el)
147
+ if (cs.visibility === 'hidden' || cs.display === 'none') continue
148
+ const kind = el.tagName === 'INPUT' ? (el.type === 'checkbox' ? 'checkbox' : (el.type === 'submit' || el.type === 'button' ? 'button' : 'input'))
149
+ : el.tagName === 'TEXTAREA' ? 'textarea'
150
+ : el.tagName === 'SELECT' ? 'select'
151
+ : el.tagName === 'BUTTON' ? 'button'
152
+ : el.tagName === 'A' ? 'link' : 'other'
153
+ // An anchor wrapping only an image has no text: 4399.com's 1608 game links are all
154
+ // <a href><img alt="名字"></a>, so every label came out empty and the whole page read as
155
+ // "no interactive elements" while it was full of them.
156
+ const imageAlt = el.tagName === 'A' || el.tagName === 'BUTTON'
157
+ ? (el.querySelector('img[alt]')?.getAttribute('alt') ?? '')
158
+ : ''
159
+ const label = (el.getAttribute('aria-label') || el.placeholder || el.textContent || imageAlt
160
+ || el.value || el.name || el.id || '').toString().replace(/\\s+/g, ' ').trim().slice(0, ${String(SNAPSHOT_LABEL_MAX)})
161
+ if (!label && kind !== 'link') continue
162
+ const a = absRect(el, el.ownerDocument)
163
+ out.push({
164
+ ref: out.length + 1,
165
+ kind,
166
+ label,
167
+ selector: el.id ? '#' + CSS.escape(el.id) : (el.name ? '[name=' + JSON.stringify(el.name) + ']' : ''),
168
+ x: Math.round(a.x + a.w / 2),
169
+ y: Math.round(a.y + a.h / 2),
170
+ ...inFrame ? { frame: true } : {},
171
+ })
172
+ }
173
+ const challenge = ${CHALLENGE_DETECT_EXPRESSION}
174
+ // The page's own URL is the authority on whether there is a document. The tracked tab.url is
175
+ // a bookkeeping copy that can lag behind a navigation the browser performed itself, and a
176
+ // stale copy made this check miss on a real about:blank tab.
177
+ const blankPage = out.length === 0 && (url === '' || url === 'about:blank')
178
+ // Independent of the element list: a page can mix DOM controls with a canvas that holds the
179
+ // part the caller actually needs. Measured on sudoku.com — 60 links were collected and the
180
+ // board, drawn on a canvas, was invisible in the same result.
181
+ //
182
+ // The thresholds keep a decorative canvas from claiming a page: at least 80x80 per canvas and
183
+ // 10% of the viewport in total. Anything smaller is reported by nothing, which is right.
184
+ let canvas
185
+ if (blankPage !== true) {
186
+ let area = 0
187
+ let count = 0
188
+ for (const c of document.querySelectorAll('canvas')) {
189
+ const r = c.getBoundingClientRect()
190
+ if (r.width < 80 || r.height < 80) continue
191
+ count += 1
192
+ area += r.width * r.height
193
+ }
194
+ const view = window.innerWidth * window.innerHeight
195
+ if (count > 0 && view > 0 && area / view >= 0.1) canvas = true
196
+ }
197
+ return {
198
+ url,
199
+ title,
200
+ elements: out,
201
+ truncated: out.length >= cap,
202
+ challenge,
203
+ ...blankPage === true
204
+ ? {
205
+ blank: true,
206
+ note: 'the page is about:blank — nothing has been opened in this browser, so there is nothing to read or drive',
207
+ }
208
+ : {},
209
+ ...canvas === true
210
+ ? {
211
+ canvas: true,
212
+ note: out.length === 0
213
+ ? 'this page draws its interface on a canvas, so there is no DOM content for a snapshot. '
214
+ + 'Use dsh_browser_screenshot to see it, and coordinates with dsh_browser_click to act on it.'
215
+ : 'part of this page is drawn on a canvas, which no element list can describe. The elements '
216
+ + 'below are real; anything inside the canvas is only visible in dsh_browser_screenshot.',
217
+ }
218
+ : {},
219
+ }
220
+ })()`;
221
+ // Same hang guard as execute: a renderer that has not committed after
222
+ // navigate would otherwise block snapshot forever.
223
+ const timeoutMs = DEFAULT_OPERATION_TIMEOUT_MS;
224
+ let result;
225
+ try {
226
+ result = await withTimeout(handleSendEvaluate(tab.handle, script), timeoutMs, signal, `browser: snapshot timed out after ${timeoutMs}ms`, timedOut => { this.interrupt(tab.handle, timedOut); });
227
+ }
228
+ catch (error) {
229
+ if (error instanceof Error && error.name === 'TimeoutError') {
230
+ this.quarantine(tab.handle);
231
+ throw new BrowserError('browser: snapshot timed out; the guest is quarantined. Close this tab or explicitly reset the session.', 'BROWSER_SNAPSHOT_TIMEOUT', { cause: error });
232
+ }
233
+ throw error;
234
+ }
235
+ if (!result.ok)
236
+ throw new BrowserError(`browser: snapshot evaluation failed: ${result.exception}`, 'BROWSER_SNAPSHOT_FAILED');
237
+ const value = result.value;
238
+ return value;
239
+ }
240
+ /**
241
+ * Read the active tab's accessibility tree: semantic roles/names/states for
242
+ * every interactive node (Chrome's `computedRole`/`computedName` when
243
+ * available, tag/attribute inference otherwise). Pierces same-origin
244
+ * iframes and shadow roots like the snapshot; cross-origin frames stay
245
+ * opaque. Coordinates are top-document viewport-relative, so a node can
246
+ * also be driven by click/type.
247
+ */
248
+ async a11y(session, request, signal) {
249
+ const s = this.session(session);
250
+ const tab = this.activeTab(s);
251
+ signal?.throwIfAborted();
252
+ // Same short-circuit as `snapshot`: a tab that never navigated has no committed document, so
253
+ // the tree cannot be read and the call would spend its whole budget discovering that.
254
+ if (tab.url === '')
255
+ return { url: '', title: undefined, count: 0, nodes: [], truncated: false };
256
+ const includeHidden = request.includeHidden === true;
257
+ // 150 rather than 500. The cap fills on any real page, and 500 nodes measured 38,953
258
+ // characters — 10k-13k tokens for a single call. A caller that needs more asks for it.
259
+ const maxNodes = Math.max(10, Math.min(5000, Math.floor(request.maxNodes ?? 150)));
260
+ const script = `(() => {
261
+ const includeHidden = ${String(includeHidden)}
262
+ const maxNodes = ${String(maxNodes)}
263
+ const SKIP = new Set(['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEMPLATE', 'HEAD', 'META', 'LINK', 'TITLE'])
264
+ const ACTIONABLE = new Set(['button', 'link', 'textbox', 'searchbox', 'checkbox', 'radio', 'combobox', 'listbox', 'slider', 'spinbutton', 'tab', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'switch', 'option', 'summary', 'treeitem', 'scrollbar'])
265
+ const CONTENT_NAMED = new Set(['button', 'link', 'heading', 'summary', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'tab', 'treeitem', 'option', 'listitem', 'switch', 'checkbox', 'radio', 'searchbox', 'textbox'])
266
+ const out = []
267
+ const seen = new Set()
268
+ const ownText = (el) => Array.from(el.childNodes).filter(n => n.nodeType === Node.TEXT_NODE).map(n => n.textContent || '').join('').trim()
269
+ const visible = (el) => {
270
+ const r = el.getBoundingClientRect()
271
+ const cs = getComputedStyle(el)
272
+ return r.width >= 4 && r.height >= 4 && cs.visibility !== 'hidden' && cs.display !== 'none'
273
+ }
274
+ const roleOf = (el) => {
275
+ const computed = el.computedRole
276
+ if (typeof computed === 'string' && computed && computed !== 'none' && computed !== 'generic') return computed
277
+ const tag = el.tagName.toLowerCase()
278
+ if (el instanceof HTMLAnchorElement) return el.hasAttribute('href') ? 'link' : 'generic'
279
+ if (tag === 'button') return 'button'
280
+ if (tag === 'textarea') return 'textbox'
281
+ if (tag === 'select') return el.hasAttribute('multiple') ? 'listbox' : 'combobox'
282
+ if (tag === 'img') return el.getAttribute('alt') === '' ? 'presentation' : 'img'
283
+ if (/^h[1-6]$/.test(tag)) return 'heading'
284
+ if (tag === 'ul' || tag === 'ol') return 'list'
285
+ if (tag === 'li') return 'listitem'
286
+ if (tag === 'nav') return 'navigation'
287
+ if (tag === 'main') return 'main'
288
+ if (tag === 'form') return 'form'
289
+ if (tag === 'table') return 'table'
290
+ if (tag === 'tr') return 'row'
291
+ if (tag === 'td') return 'cell'
292
+ if (tag === 'th') return 'columnheader'
293
+ if (tag === 'dialog') return 'dialog'
294
+ if (tag === 'summary') return 'button'
295
+ if (tag === 'input') {
296
+ const t = el.type
297
+ if (t === 'checkbox') return 'checkbox'
298
+ if (t === 'radio') return 'radio'
299
+ if (t === 'range') return 'slider'
300
+ if (t === 'number') return 'spinbutton'
301
+ if (t === 'button' || t === 'submit' || t === 'reset' || t === 'image') return 'button'
302
+ if (t === 'hidden') return 'none'
303
+ if (t === 'search') return 'searchbox'
304
+ return 'textbox'
305
+ }
306
+ return 'generic'
307
+ }
308
+ const nameOf = (el, role) => {
309
+ const computed = el.computedName
310
+ if (typeof computed === 'string' && computed && computed.trim() !== '') return computed.trim()
311
+ const aria = el.getAttribute('aria-label')
312
+ if (aria) return aria
313
+ const labelledby = el.getAttribute('aria-labelledby')
314
+ if (labelledby) {
315
+ const ref = document.getElementById(labelledby.split(/\\s+/)[0])
316
+ if (ref) {
317
+ const t = (ref.textContent || '').trim()
318
+ if (t) return t
319
+ }
320
+ }
321
+ if (el.hasAttribute('alt')) return el.getAttribute('alt')
322
+ if (el.hasAttribute('title')) return el.getAttribute('title')
323
+ if (el.placeholder) return el.placeholder
324
+ if (CONTENT_NAMED.has(role)) {
325
+ const t = ownText(el)
326
+ if (t) return t
327
+ }
328
+ if (el.id) {
329
+ const lbl = document.querySelector('label[for=' + JSON.stringify(el.id) + ']')
330
+ if (lbl) {
331
+ const t = (lbl.textContent || '').trim()
332
+ if (t) return t
333
+ }
334
+ }
335
+ return ''
336
+ }
337
+ const valueOf = (el) => {
338
+ if (el instanceof HTMLInputElement) return el.type === 'checkbox' || el.type === 'radio' ? null : el.value
339
+ if (el instanceof HTMLTextAreaElement) return el.value
340
+ if (el instanceof HTMLSelectElement) {
341
+ const o = el.options[el.selectedIndex]
342
+ return o ? (o.textContent || '').trim() : null
343
+ }
344
+ if (el.isContentEditable) return (el.textContent || '').trim()
345
+ return null
346
+ }
347
+ const statesOf = (el) => {
348
+ const st = []
349
+ if (!el.disabled) st.push('enabled'); else st.push('disabled')
350
+ if (el.checked) st.push('checked'); else if (el.getAttribute('aria-checked') === 'false') st.push('unchecked')
351
+ const expanded = el.getAttribute('aria-expanded')
352
+ if (expanded === 'true') st.push('expanded')
353
+ if (expanded === 'false') st.push('collapsed')
354
+ if (el.required) st.push('required')
355
+ if (el.readOnly) st.push('readonly')
356
+ if (el.selected) st.push('selected')
357
+ const pressed = el.getAttribute('aria-pressed')
358
+ if (pressed === 'true') st.push('pressed')
359
+ return st
360
+ }
361
+ const depthOf = (el) => {
362
+ let d = 0
363
+ let p = el.parentElement
364
+ while (p) { d++; p = p.parentElement }
365
+ return d
366
+ }
367
+ const absRect = (el, doc) => {
368
+ const r = el.getBoundingClientRect()
369
+ let x = r.x, y = r.y
370
+ let d = doc
371
+ while (d && d.defaultView && d.defaultView.frameElement) {
372
+ const fr = d.defaultView.frameElement.getBoundingClientRect()
373
+ x += fr.x; y += fr.y
374
+ d = d.defaultView.frameElement.ownerDocument
375
+ }
376
+ return { x, y, w: r.width, h: r.height }
377
+ }
378
+ const walk = (doc, inFrame, baseDepth) => {
379
+ if (seen.has(doc)) return
380
+ seen.add(doc)
381
+ for (const el of doc.querySelectorAll('*')) {
382
+ if (out.length >= maxNodes) return
383
+ if (SKIP.has(el.tagName)) continue
384
+ if (el.shadowRoot) walk(el.shadowRoot, inFrame, baseDepth + 1)
385
+ if (el.tagName === 'IFRAME') {
386
+ try { const d = el.contentDocument; if (d) walk(d, true, baseDepth + 1) } catch { /* cross-origin */ }
387
+ }
388
+ const role = roleOf(el)
389
+ if (role === 'none' || role === 'presentation' || role === 'generic') continue
390
+ if (!includeHidden && !visible(el)) continue
391
+ const name = nameOf(el, role)
392
+ if (!name && !ACTIONABLE.has(role)) continue
393
+ const a = absRect(el, el.ownerDocument)
394
+ out.push({
395
+ ref: out.length + 1,
396
+ role,
397
+ name: name.slice(0, 120),
398
+ value: valueOf(el),
399
+ states: statesOf(el),
400
+ depth: baseDepth + depthOf(el),
401
+ // Same derivation as the snapshot collector: an id or a name is what makes a node
402
+ // something the caller can point at without guessing at its text. The tool-layer
403
+ // schema declared this field before this line existed, so the schema was promising
404
+ // a value the tool never sent.
405
+ selector: el.id ? '#' + CSS.escape(el.id) : (el.name ? '[name=' + JSON.stringify(el.name) + ']' : ''),
406
+ tag: el.tagName.toLowerCase(),
407
+ x: Math.round(a.x + a.w / 2),
408
+ y: Math.round(a.y + a.h / 2),
409
+ ...inFrame ? { frame: true } : {},
410
+ })
411
+ }
412
+ }
413
+ walk(document, false, 0)
414
+ return { url: location.href, title: document.title || undefined, count: out.length, nodes: out, truncated: out.length >= maxNodes }
415
+ })()`;
416
+ const timeoutMs = DEFAULT_OPERATION_TIMEOUT_MS;
417
+ let result;
418
+ try {
419
+ result = await withTimeout(handleSendEvaluate(tab.handle, script), timeoutMs, signal, `browser: a11y timed out after ${timeoutMs}ms`, timedOut => { this.interrupt(tab.handle, timedOut); });
420
+ }
421
+ catch (error) {
422
+ if (error instanceof Error && error.name === 'TimeoutError') {
423
+ this.quarantine(tab.handle);
424
+ throw new BrowserError('browser: a11y timed out; the guest is quarantined. Close this tab or explicitly reset the session.', 'BROWSER_A11Y_TIMEOUT', { cause: error });
425
+ }
426
+ throw error;
427
+ }
428
+ if (!result.ok)
429
+ throw new BrowserError(`browser: a11y evaluation failed: ${result.exception}`, 'BROWSER_A11Y_FAILED');
430
+ const value = result.value;
431
+ this.record(s, 'a11y', { includeHidden, maxNodes }, true, { result: `${value.count} nodes` });
432
+ return value;
433
+ }
434
+ /** Check whether a human-verification challenge is blocking the active tab. */
435
+ async detectChallenge(session, signal) {
436
+ const s = this.session(session);
437
+ const tab = this.activeTab(s);
438
+ signal?.throwIfAborted();
439
+ const timeoutMs = PROVIDER_TIMEOUTS.action;
440
+ const result = await withTimeout(handleSendEvaluate(tab.handle, CHALLENGE_DETECT_EXPRESSION), timeoutMs, signal, `browser: challenge detection timed out after ${timeoutMs}ms`, timedOut => { this.interrupt(tab.handle, timedOut); });
441
+ if (!result.ok) {
442
+ throw new BrowserError(`browser: challenge detection failed: ${result.exception}`, 'BROWSER_CHALLENGE_DETECT_FAILED');
443
+ }
444
+ const value = result.value;
445
+ return {
446
+ blocked: value.blocked === true,
447
+ kind: value.kind,
448
+ reason: value.reason,
449
+ ...value.recovery !== undefined ? { recovery: value.recovery } : {},
450
+ ...typeof value.status === 'number' ? { status: value.status } : {},
451
+ };
452
+ }
453
+ /** Fetch page content in a requested format. */
454
+ async content(session, request, signal) {
455
+ const tab = this.activeTab(this.session(session));
456
+ signal?.throwIfAborted();
457
+ const selector = request.selector ?? '';
458
+ const format = request.format;
459
+ // Per-format caps. A full HTML document is enormous, but the same limit applied to
460
+ // plain text is no limit at all (a whole page of text measured 25,882 characters).
461
+ // This bounds the common case instead of letting one call spend 25k-33k tokens.
462
+ //
463
+ // The plugin config overrides the lot when it is set — see `contentMaxChars`. The caller's
464
+ // own `maxChars` still outranks both: an explicit per-call bound is the most specific
465
+ // statement of intent there is.
466
+ const maxChars = request.maxChars
467
+ ?? this.contentMaxChars
468
+ ?? (format === 'html' || format === 'json' ? 50_000 : 20_000);
469
+ const script = `(() => {${DEEP_DOM_SOURCE}
470
+ const root = ${selector === '' ? 'document.body' : `__dshQuery(${JSON.stringify(selector)})`}
471
+ if (!root) return { ok: false, reason: 'selector not found' }
472
+ const fmt = ${JSON.stringify(format)}
473
+ // Both walkers pierce shadow roots and same-origin iframes (cross-origin
474
+ // iframes stay opaque — the browser forbids reading them).
475
+ let content = ''
476
+ if (fmt === 'txt') {
477
+ // Prefer the browser's own rendered text.
478
+ //
479
+ // Walking text nodes and joining them is not equivalent: pages that wrap
480
+ // every character in its own element — one-character spans for a
481
+ // per-character animation, which is common — produce one text node per
482
+ // letter, and joining those with spaces turns every word into a column of
483
+ // letters. The rendered text reassembles them the way a reader sees them,
484
+ // and it also honours visibility, so hidden text does not leak out.
485
+ // (No backticks in this comment: it lives inside a template literal.)
486
+ const rendered = typeof root.innerText === 'string' ? root.innerText : ''
487
+ if (rendered.trim() !== '') {
488
+ content = rendered
489
+ } else {
490
+ // Fallback for nodes without layout (a detached root, or a fragment):
491
+ // collect text directly, still piercing shadow roots and same-origin
492
+ // iframes, and join without inventing separators beyond what the markup
493
+ // already implies.
494
+ const parts = []
495
+ const textWalk = (node) => {
496
+ if (node.nodeType === Node.TEXT_NODE) { const t = (node.textContent || '').trim(); if (t) parts.push(t); return }
497
+ if (node.nodeType !== Node.ELEMENT_NODE) return
498
+ const tag = node.tagName.toLowerCase()
499
+ if (tag === 'script' || tag === 'style' || tag === 'noscript') return
500
+ if (tag === 'iframe') {
501
+ try { const d = node.contentDocument; if (d && d.body) for (const c of d.body.childNodes) textWalk(c) } catch { /* cross-origin */ }
502
+ return
503
+ }
504
+ if (node.shadowRoot) for (const c of node.shadowRoot.childNodes) textWalk(c)
505
+ for (const child of node.childNodes) textWalk(child)
506
+ }
507
+ textWalk(root)
508
+ content = parts.join(' ')
509
+ }
510
+ }
511
+ else if (fmt === 'html') content = root.outerHTML || ''
512
+ // A DOM element has no own enumerable properties — everything lives on the prototype
513
+ // chain — so JSON.stringify(root) is always "{}". That is not a structured view of
514
+ // the page, it is an empty object the caller will read as "no data here" and then
515
+ // retry with other selectors. Serialise the markup instead, which is what a caller
516
+ // asking for JSON of an element can actually use.
517
+ else if (fmt === 'json') content = JSON.stringify({ html: root.outerHTML, tag: root.tagName.toLowerCase() })
518
+ else {
519
+ // markdown: headings, paragraphs, links, lists (best-effort)
520
+ const parts = []
521
+ const walk = (node) => {
522
+ if (node.nodeType === Node.TEXT_NODE) { const t = (node.textContent || '').trim(); if (t) parts.push(t); return }
523
+ if (node.nodeType !== Node.ELEMENT_NODE) return
524
+ const tag = node.tagName.toLowerCase()
525
+ if (tag === 'script' || tag === 'style' || tag === 'noscript') return
526
+ if (tag === 'iframe') {
527
+ try { const d = node.contentDocument; if (d && d.body) for (const c of d.body.childNodes) walk(c) } catch { /* cross-origin */ }
528
+ return
529
+ }
530
+ if (node.shadowRoot) for (const c of node.shadowRoot.childNodes) walk(c)
531
+ if (tag === 'h1' || tag === 'h2' || tag === 'h3' || tag === 'h4') parts.push('\\n' + '#'.repeat(Number(tag[1])) + ' ' + (node.textContent || '').trim() + '\\n')
532
+ else if (tag === 'a') { const t = (node.textContent || '').trim(); if (t) parts.push('[' + t + '](' + (node.href || '') + ')') }
533
+ else if (tag === 'li') parts.push(' - ' + (node.textContent || '').trim())
534
+ else if (tag === 'p' || tag === 'div' || tag === 'section' || tag === 'article') { const t = (node.textContent || '').trim(); if (t) parts.push(t + '\\n') }
535
+ else { for (const child of node.childNodes) walk(child) }
536
+ }
537
+ walk(root)
538
+ // Join without a separator: each part already carries its own trailing
539
+ // newline, so a space join would smear headings/links into run-on text.
540
+ content = parts.join('')
541
+ }
542
+ const truncated = content.length > ${String(maxChars)}
543
+ return { ok: true, content: content.slice(0, ${String(maxChars)}), truncated }
544
+ })()`;
545
+ // Honor a per-call timeout: content evaluation can hang on a heavy page,
546
+ // so a caller-supplied budget bounds it. Unlike a bare signal entry check,
547
+ // withTimeout also interrupts a call already in flight.
548
+ const timeoutMs = request.timeoutMs ?? DEFAULT_OPERATION_TIMEOUT_MS;
549
+ const result = await withTimeout(handleSendEvaluate(tab.handle, script), timeoutMs, signal, `browser: content timed out after ${timeoutMs}ms`, timedOut => { this.interrupt(tab.handle, timedOut); });
550
+ if (!result.ok)
551
+ throw new BrowserError(`browser: content evaluation failed: ${result.exception}`, 'BROWSER_CONTENT_FAILED');
552
+ const value = result.value;
553
+ if (!value.ok)
554
+ throw new BrowserError(`browser: content fetch failed: ${value.reason ?? 'unknown'}`, 'BROWSER_CONTENT_FAILED');
555
+ return { content: value.content ?? '', truncated: value.truncated ?? false };
556
+ }
557
+ /**
558
+ * Extract structured data from repeated DOM items (static CSS, CSP-safe —
559
+ * no arbitrary code runs). Waits for the item selector, then maps each item
560
+ * through the field selectors; `selector@attr` reads an attribute instead
561
+ * of text (`a@href` yields an absolute URL).
562
+ */
563
+ async scrape(session, request, signal) {
564
+ const s = this.session(session);
565
+ const tab = this.activeTab(s);
566
+ signal?.throwIfAborted();
567
+ const timeoutMs = request.timeoutMs ?? PROVIDER_TIMEOUTS.interaction;
568
+ const script = (sliceMs, last) => `(async () => {${DEEP_DOM_SOURCE}
569
+ const itemSel = ${JSON.stringify(request.item)}
570
+ const fields = ${JSON.stringify(request.fields)}
571
+ const sliceMs = ${String(sliceMs)}
572
+ const last = ${String(last)}
573
+ const sleep = ms => new Promise(r => setTimeout(r, ms))
574
+ const parseField = f => {
575
+ const m = /^(.*)@([A-Za-z][A-Za-z0-9_-]*)$/.exec(f.selector.trim())
576
+ if (m) return { base: m[1].trim(), attr: m[2] }
577
+ return { base: f.selector, attr: null }
578
+ }
579
+ const deadline = Date.now() + sliceMs
580
+ let items = []
581
+ for (;;) {
582
+ // Immediate, like match() above: an unparseable selector can never match.
583
+ try { items = __dshQueryAll(itemSel) }
584
+ catch (error) { return { ok: false, error: 'invalid CSS selector ' + JSON.stringify(itemSel) + ' (' + String((error && error.message) || error) + ')' } }
585
+ if (items.length > 0) break
586
+ if (Date.now() >= deadline) return last ? { ok: false, error: 'no elements matched: ' + itemSel } : { pending: true }
587
+ await sleep(100)
588
+ }
589
+ const out = []
590
+ for (const it of items) {
591
+ const row = {}
592
+ for (const f of fields) {
593
+ const { base, attr } = parseField(f)
594
+ let el = null
595
+ try { el = base === '' ? it : it.querySelector(base) } catch { el = null }
596
+ if (!el) { row[f.name] = null; continue }
597
+ if (attr !== null) {
598
+ const v = el.getAttribute(attr)
599
+ row[f.name] = attr === 'href' && el.tagName === 'A' && v ? new URL(v, el.baseURI).href : v
600
+ continue
601
+ }
602
+ row[f.name] = (el.textContent || '').trim()
603
+ }
604
+ out.push(row)
605
+ }
606
+ return { ok: true, count: out.length, items: out }
607
+ })()`;
608
+ const deadline = Date.now() + timeoutMs;
609
+ let value;
610
+ do {
611
+ const { sliceMs, last } = pagePollSlice(deadline);
612
+ const result = await withTimeout(handleSendEvaluate(tab.handle, script(sliceMs, last)), Math.max(sliceMs, deadline - Date.now()) + TARGET_SCRIPT_GRACE_MS, signal, `browser: scrape timed out after ${timeoutMs}ms`, timedOut => { this.interrupt(tab.handle, timedOut); });
613
+ if (!result.ok)
614
+ throw new BrowserError(`browser: scrape evaluation failed: ${result.exception}`, 'BROWSER_SCRAPE_FAILED');
615
+ value = result.value;
616
+ } while (value?.pending === true);
617
+ if (value.ok !== true)
618
+ throw new BrowserError(`browser: scrape failed: ${value.error ?? 'unknown'}`, 'BROWSER_SCRAPE_FAILED');
619
+ const items = value.items ?? [];
620
+ this.record(s, 'scrape', { item: request.item, fields: request.fields.map(f => f.name) }, true, { result: `${items.length} items` });
621
+ return { count: items.length, items };
622
+ }
623
+ }