dsh-builtin-browser 1.0.3 → 1.0.4

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 (293) hide show
  1. package/README.en.md +89 -0
  2. package/browser-extension/constants.mjs +20 -0
  3. package/browser-extension/controller.mjs +293 -0
  4. package/browser-extension/locales.mjs +15 -0
  5. package/browser-extension/manifest.json +12 -0
  6. package/browser-extension/options.html +14 -0
  7. package/browser-extension/options.mjs +9 -0
  8. package/browser-extension/permission-guard.mjs +13 -0
  9. package/browser-extension/worker.mjs +74 -0
  10. package/package.json +20 -2
  11. package/scripts/build-client.mjs +305 -0
  12. package/scripts/build.mjs +69 -0
  13. package/scripts/bundle-host.mjs +28 -0
  14. package/scripts/fix-exports.mjs +40 -0
  15. package/scripts/install-electron.mjs +101 -0
  16. package/scripts/pack.mjs +99 -0
  17. package/scripts/publish-manifest.mjs +56 -0
  18. package/scripts/verify-exports.mjs +58 -0
  19. package/scripts/verify-preview-sdk.mjs +93 -0
  20. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  21. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  22. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  23. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  24. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  25. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  26. package/skills/dsh-debug-host/SKILL.md +56 -0
  27. package/skills/dsh-debug-self/SKILL.md +50 -0
  28. package/src/bridge-compatibility.ts +39 -0
  29. package/src/browser/anti-bot.ts +251 -0
  30. package/src/browser/deep-dom.ts +40 -0
  31. package/src/browser/handles.ts +89 -0
  32. package/src/browser/runtime.ts +578 -0
  33. package/src/browser/takeover-target.ts +45 -0
  34. package/src/browser/types.ts +870 -0
  35. package/src/browser-electron/authenticated-route.ts +109 -0
  36. package/src/browser-electron/automatic-maintenance.ts +736 -0
  37. package/src/browser-electron/bridge-auto.ts +159 -0
  38. package/src/browser-electron/bridge-connection.ts +386 -0
  39. package/src/browser-electron/bridge-endpoint.ts +129 -0
  40. package/src/browser-electron/bridge-install.ts +290 -0
  41. package/src/browser-electron/bridge-maintenance.ts +189 -0
  42. package/src/browser-electron/bridge-status.ts +386 -0
  43. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  44. package/src/browser-electron/desktop-identity.ts +353 -0
  45. package/src/browser-electron/desktop-shell.ts +100 -0
  46. package/src/browser-electron/document-readiness.ts +45 -0
  47. package/src/browser-electron/electron-provision.ts +347 -0
  48. package/src/browser-electron/entry.ts +1378 -0
  49. package/src/browser-electron/ephemeral-profile.ts +189 -0
  50. package/src/browser-electron/extension-browser.ts +230 -0
  51. package/src/browser-electron/extension-setup.ts +67 -0
  52. package/src/browser-electron/file-write.ts +31 -0
  53. package/src/browser-electron/foreground-watch.ts +142 -0
  54. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  55. package/src/browser-electron/guest-cookie-store.ts +59 -0
  56. package/src/browser-electron/guest-css-runtime.ts +76 -0
  57. package/src/browser-electron/guest-css.ts +68 -0
  58. package/src/browser-electron/guest-route.ts +716 -0
  59. package/src/browser-electron/guest-runtime.ts +408 -0
  60. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  61. package/src/browser-electron/guest-storage.ts +120 -0
  62. package/src/browser-electron/history-store.ts +224 -0
  63. package/src/browser-electron/host-main.ts +1385 -0
  64. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  65. package/src/browser-electron/http-body.ts +65 -0
  66. package/src/browser-electron/json-reply.ts +47 -0
  67. package/src/browser-electron/maintenance-broker.ts +166 -0
  68. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  69. package/src/browser-electron/maintenance-route.ts +68 -0
  70. package/src/browser-electron/missing-system-browser.ts +114 -0
  71. package/src/browser-electron/open-slot.ts +49 -0
  72. package/src/browser-electron/paths.ts +25 -0
  73. package/src/browser-electron/preferred-browser.ts +130 -0
  74. package/src/browser-electron/preview-route.ts +215 -0
  75. package/src/browser-electron/process-ownership.ts +174 -0
  76. package/src/browser-electron/process.ts +23 -0
  77. package/src/browser-electron/profile-checkpoint.ts +187 -0
  78. package/src/browser-electron/profile-command.ts +47 -0
  79. package/src/browser-electron/profile-extension.ts +129 -0
  80. package/src/browser-electron/profile-lease.ts +211 -0
  81. package/src/browser-electron/profile-residue.ts +49 -0
  82. package/src/browser-electron/provider-core.ts +1107 -0
  83. package/src/browser-electron/provider-interaction.ts +1034 -0
  84. package/src/browser-electron/provider-media.ts +589 -0
  85. package/src/browser-electron/provider-navigation.ts +323 -0
  86. package/src/browser-electron/provider-observation.ts +664 -0
  87. package/src/browser-electron/provider-tabs.ts +372 -0
  88. package/src/browser-electron/provider.ts +666 -0
  89. package/src/browser-electron/reference-route.ts +598 -0
  90. package/src/browser-electron/remote-host.ts +1538 -0
  91. package/src/browser-electron/rpc-input.ts +13 -0
  92. package/src/browser-electron/rpc-ops.ts +41 -0
  93. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  94. package/src/browser-electron/runtime-route.ts +105 -0
  95. package/src/browser-electron/runtime-status.ts +309 -0
  96. package/src/browser-electron/settings-route.ts +64 -0
  97. package/src/browser-electron/settings-store.ts +593 -0
  98. package/src/browser-electron/shortcuts-route.ts +112 -0
  99. package/src/browser-electron/sidebar-only-host.ts +300 -0
  100. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  101. package/src/browser-electron/system-browser.ts +1850 -0
  102. package/src/browser-electron/tauri-host.ts +194 -0
  103. package/src/browser-electron/timing.ts +16 -0
  104. package/src/browser-electron/virtual-cursor.ts +162 -0
  105. package/src/browser-electron/windows-system.ts +24 -0
  106. package/src/browser-reference/delivery.ts +384 -0
  107. package/src/browser-reference/entry.ts +631 -0
  108. package/src/browser-reference/export.ts +339 -0
  109. package/src/browser-reference/import.ts +303 -0
  110. package/src/browser-reference/page-script.ts +1537 -0
  111. package/src/browser-reference/service.ts +1346 -0
  112. package/src/browser-reference/store.ts +172 -0
  113. package/src/browser-reference/text-quote.ts +219 -0
  114. package/src/browser-reference/types.ts +195 -0
  115. package/src/browser-reference/visible.ts +367 -0
  116. package/src/browser-reference/web-sources.ts +106 -0
  117. package/src/client/apply-guard.ts +22 -0
  118. package/src/client/browser/BrowserController.ts +693 -0
  119. package/src/client/browser/BrowserFrame.ts +78 -0
  120. package/src/client/browser/BrowserNavigation.ts +169 -0
  121. package/src/client/browser/BrowserPage.ts +23 -0
  122. package/src/client/browser/BrowserPersistence.ts +44 -0
  123. package/src/client/browser/IframeImpl.ts +182 -0
  124. package/src/client/browser/child-tabs.ts +14 -0
  125. package/src/client/browser/frame-history.ts +125 -0
  126. package/src/client/browser/frame-state.ts +27 -0
  127. package/src/client/browser/iframe-reference.ts +67 -0
  128. package/src/client/browser/initialization.ts +262 -0
  129. package/src/client/browser/omnibox.ts +243 -0
  130. package/src/client/browser/store.ts +38 -0
  131. package/src/client/browser/takeover-channel.ts +72 -0
  132. package/src/client/browser/url.ts +46 -0
  133. package/src/client/browser/web-reference-source.ts +56 -0
  134. package/src/client/css-modules.d.ts +4 -0
  135. package/src/client/definition.tsx +36 -0
  136. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  137. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  138. package/src/client/electron/NativeChildPresentation.ts +53 -0
  139. package/src/client/electron/NativeViewPage.ts +265 -0
  140. package/src/client/electron/pages.ts +23 -0
  141. package/src/client/electron/reference-overlay.ts +53 -0
  142. package/src/client/electron/workspace.ts +33 -0
  143. package/src/client/index.ts +333 -0
  144. package/src/client/locales.ts +860 -0
  145. package/src/client/pages.ts +28 -0
  146. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  147. package/src/client/reference/client/draft-reference.ts +167 -0
  148. package/src/client/reference/client/index.ts +7 -0
  149. package/src/client/reference/client/ordered-submission.ts +108 -0
  150. package/src/client/reference/client/pending-delivery.ts +216 -0
  151. package/src/client/reference/client/plugin.ts +208 -0
  152. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  153. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  154. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  155. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  156. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  157. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  158. package/src/client/reference/client/production/assembly.ts +447 -0
  159. package/src/client/reference/client/production/asset-store.ts +144 -0
  160. package/src/client/reference/client/production/availability.ts +72 -0
  161. package/src/client/reference/client/production/bytes.ts +36 -0
  162. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  163. package/src/client/reference/client/production/delivery-client.ts +211 -0
  164. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  165. package/src/client/reference/client/production/http-transport.ts +212 -0
  166. package/src/client/reference/client/production/production-submission.ts +70 -0
  167. package/src/client/reference/client/production/protocol.ts +234 -0
  168. package/src/client/reference/client/production/reference-card.ts +240 -0
  169. package/src/client/reference/client/production/reference-labels.ts +29 -0
  170. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  171. package/src/client/reference/client/production/reveal.ts +215 -0
  172. package/src/client/reference/client/production/runtime.ts +1056 -0
  173. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  174. package/src/client/reference/client/production/source-marker.ts +99 -0
  175. package/src/client/reference/client/production/source-opener.ts +55 -0
  176. package/src/client/reference/client/production/styles.ts +104 -0
  177. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  178. package/src/client/reference/client/reveal.ts +109 -0
  179. package/src/client/reference/client/scheme.ts +114 -0
  180. package/src/client/reference/client/session-schedule.ts +36 -0
  181. package/src/client/reference/client/types.ts +168 -0
  182. package/src/client/reference/css-modules.d.ts +4 -0
  183. package/src/client/reference/index.ts +11 -0
  184. package/src/client/reference-capture-owner.ts +162 -0
  185. package/src/client/reference-intents.ts +36 -0
  186. package/src/client/settings/index.ts +42 -0
  187. package/src/client/settings/mount-guard.ts +31 -0
  188. package/src/client/settings/panel.ts +2768 -0
  189. package/src/client/shortcut-open.ts +30 -0
  190. package/src/client/startpage/binding.ts +99 -0
  191. package/src/client/startpage/controller.ts +300 -0
  192. package/src/client/startpage/model.ts +279 -0
  193. package/src/client/view/Browser.module.css +751 -0
  194. package/src/client/view/BrowserBody.tsx +315 -0
  195. package/src/client/view/BrowserPresentation.ts +9 -0
  196. package/src/client/view/BrowserTitle.tsx +17 -0
  197. package/src/client/view/IframePresentation.ts +365 -0
  198. package/src/client/view/StartPage.tsx +598 -0
  199. package/src/client/view/TakeoverBanner.tsx +21 -0
  200. package/src/compat/host-features.ts +92 -0
  201. package/src/index.ts +110 -0
  202. package/src/reference-owner.ts +5 -0
  203. package/src/reference-page.ts +9 -0
  204. package/src/reference-source.ts +3 -0
  205. package/src/reference-text.ts +219 -0
  206. package/src/startpage-settings.ts +103 -0
  207. package/src/startpage.ts +71 -0
  208. package/src/takeover-protocol.ts +28 -0
  209. package/src/tool-browser/block-recovery.ts +85 -0
  210. package/src/tool-browser/code-tool.ts +555 -0
  211. package/src/tool-browser/code-worker.ts +725 -0
  212. package/src/tool-browser/element-fields.ts +167 -0
  213. package/src/tool-browser/errors.ts +40 -0
  214. package/src/tool-browser/index.ts +265 -0
  215. package/src/tool-browser/page-probe.ts +675 -0
  216. package/src/tool-browser/panel-page.ts +126 -0
  217. package/src/tool-browser/probe-client.ts +183 -0
  218. package/src/tool-browser/screenshot-annotations.ts +131 -0
  219. package/src/tool-browser/screenshot-image.ts +49 -0
  220. package/src/tool-browser/state.ts +375 -0
  221. package/src/tool-browser/takeover.ts +199 -0
  222. package/src/tool-browser/tools-debug.ts +806 -0
  223. package/src/tool-browser/tools-interaction.ts +956 -0
  224. package/src/tool-browser/tools-navigation.ts +786 -0
  225. package/src/tool-browser/tools-observation.ts +474 -0
  226. package/src/tool-browser/tools-reference.ts +294 -0
  227. package/src/types/electron-shim.d.ts +144 -0
  228. package/src/types.ts +85 -0
  229. package/src/web-guest.ts +35 -0
  230. package/tools/accept-desktop.mjs +148 -0
  231. package/dist/client.d.cts +0 -516
  232. package/dist/client.d.mts +0 -516
  233. package/dist/index.cjs +0 -92
  234. package/dist/index.d.mts +0 -2960
  235. package/dist/index.mjs +0 -24
  236. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  237. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  238. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  239. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  240. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  241. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  242. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  243. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  244. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  245. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  246. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  247. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  248. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  249. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  250. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  256. package/dsh-host-patch/sources/manifest.json +0 -218
  257. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  258. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  259. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  260. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  261. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  262. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  263. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  264. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  265. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  266. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  267. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  268. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  269. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  293. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Anti-bot block handling: one classifier for challenge and block pages, the recovery each kind
3
+ * calls for, and the public routes to the same information when a site refuses automation.
4
+ *
5
+ * The signatures are data, so the page-context detector (generated by {@link challengeDetectSource})
6
+ * and the Web proxy's server-side probe ({@link classifyBlock} on raw HTML) cannot drift apart.
7
+ * Nothing here solves a CAPTCHA or evades a block: interactive checks go to the human, network
8
+ * (IP) blocks are reported as an environment limit, and the rest get one paced retry and then
9
+ * other public sources.
10
+ * @module dsh-browser/browser/anti-bot
11
+ */
12
+
13
+ import type { BrowserChallenge } from './types.ts'
14
+
15
+ /** What the agent should do about a blocked page. */
16
+ export type BlockRecovery =
17
+ /** A human verification (CAPTCHA, slider, press-and-hold): hand the tab to the human. */
18
+ | 'takeover'
19
+ /** A self-clearing JavaScript interstitial: wait for it in the same tab, then re-check. */
20
+ | 'wait'
21
+ /** A refusal that a fresh session and slower pacing may get past once; then fall back. */
22
+ | 'retry'
23
+ /** The network itself is refused (datacenter/VPN IP): an environment limit, use other sources. */
24
+ | 'environment'
25
+
26
+ /** Facts about a loaded page, as the classifier sees them. */
27
+ export interface BlockEvidence {
28
+ /** HTTP status of the main document, when known. */
29
+ readonly status?: number
30
+ readonly title?: string
31
+ /** Visible text (or raw HTML on the server side). */
32
+ readonly text?: string
33
+ /** Space-separated `src` of the page's iframes. */
34
+ readonly frames?: string
35
+ /** Visible challenge widgets found in the DOM, by kind (page context only). */
36
+ readonly widgets?: readonly string[]
37
+ }
38
+
39
+ interface Signature {
40
+ readonly kind: string
41
+ readonly recovery: BlockRecovery
42
+ readonly reason: string
43
+ /** Matched against the lower-cased title + text. */
44
+ readonly text?: string
45
+ /** Matched against the lower-cased iframe sources. */
46
+ readonly frames?: string
47
+ /** A visible widget of this kind (page context). */
48
+ readonly widget?: string
49
+ /** Only counts on an error status (>= 400), so a page that merely mentions the words is not a block. */
50
+ readonly errorOnly?: boolean
51
+ }
52
+
53
+ /**
54
+ * Ordered: the first match wins, so interactive checks come before the interstitials that host
55
+ * them and network blocks come before generic refusals.
56
+ */
57
+ const SIGNATURES: readonly Signature[] = [
58
+ { kind: 'hcaptcha', recovery: 'takeover', reason: 'hCaptcha verification', widget: 'hcaptcha', frames: 'hcaptcha\\.com/captcha' },
59
+ { kind: 'recaptcha', recovery: 'takeover', reason: 'Google reCAPTCHA verification', widget: 'recaptcha', frames: 'recaptcha/(?:api2|enterprise)/bframe' },
60
+ { kind: 'turnstile', recovery: 'takeover', reason: 'Cloudflare Turnstile verification', widget: 'turnstile', frames: 'challenges\\.cloudflare\\.com/cdn-cgi/challenge-platform/.*turnstile' },
61
+ { kind: 'perimeterx', recovery: 'takeover', reason: 'PerimeterX "Press & Hold" verification', text: 'press (?:&|and) hold|px-captcha', widget: 'perimeterx' },
62
+ { kind: 'datadome', recovery: 'takeover', reason: 'DataDome verification', frames: 'captcha-delivery\\.com|geo\\.captcha-delivery' },
63
+ { kind: 'slider', recovery: 'takeover', reason: 'Slider / puzzle verification', text: '\u6ed1\u52a8.{0,8}(?:\u9a8c\u8bc1|\u6ed1\u5757|\u62fc\u56fe)|\u62d6\u52a8.{0,12}(?:\u6ed1\u5757|\u62fc\u56fe)|slide to verify|drag the slider|geetest', widget: 'slider' },
64
+ { kind: 'google-sorry', recovery: 'environment', reason: 'Google "unusual traffic from your computer network" block', text: 'unusual traffic from your computer network|our systems have detected unusual traffic' },
65
+ { kind: 'ip-block', recovery: 'environment', reason: 'The site refuses this network (IP / hosting provider block)', text: 'your ip(?: address)? (?:has been|is|was) (?:blocked|banned|blacklisted)|requests from your (?:ip|network) |datacenter|data center ip|hosting provider|vpn or proxy', errorOnly: true },
66
+ { kind: 'cloudflare', recovery: 'wait', reason: 'Cloudflare "Just a moment" interstitial', widget: 'cloudflare', text: 'just a moment\\.\\.\\.|checking your browser|checking if the site connection is secure|cf-browser-verification|cf_chl_|cf-chl-' },
67
+ { kind: 'baidu-verify', recovery: 'takeover', reason: 'Baidu security verification (\u767e\u5ea6\u5b89\u5168\u9a8c\u8bc1)', text: 'wappass\\.baidu\\.com|\u767e\u5ea6\u5b89\u5168\u9a8c\u8bc1' },
68
+ { kind: 'human-check', recovery: 'takeover', reason: 'Human-verification challenge', text: 'verify you are (?:a )?human|verify you are not a robot|are you a robot|\u4eba\u673a\u9a8c\u8bc1|\u5b89\u5168\u9a8c\u8bc1|\u8bf7\u5b8c\u6210\u9a8c\u8bc1' },
69
+ { kind: 'rate-limit', recovery: 'retry', reason: 'Rate limited (HTTP 429)', text: '', errorOnly: true },
70
+ { kind: 'access-denied', recovery: 'retry', reason: 'Access denied by the site\'s bot protection', text: 'access denied|attention required|request blocked|you have been blocked|forbidden|not authorized to access|bot detected|automated (?:access|requests|queries)|enable javascript and cookies|pardon our interruption|\u8bbf\u95ee\u88ab\u62d2\u7edd|\u8bbf\u95ee\u53d7\u9650', errorOnly: true },
71
+ ]
72
+
73
+ /** Signatures as JSON-safe data for the page-context detector. */
74
+ const SIGNATURE_DATA = SIGNATURES.map(s => ({ ...s }))
75
+
76
+ /**
77
+ * Classify a page. The same function runs in the page (through {@link challengeDetectSource}) and
78
+ * in Node, so it must stay self-contained: no imports, no closures over module state.
79
+ * @param evidence - what the page shows.
80
+ * @param signatures - the signature table.
81
+ * @returns the challenge verdict.
82
+ */
83
+ function classify(evidence: BlockEvidence, signatures: readonly Signature[]): BrowserChallenge {
84
+ const status = typeof evidence.status === 'number' ? evidence.status : 0
85
+ const text = ((evidence.title ?? '') + '\n' + (evidence.text ?? '')).toLowerCase()
86
+ const frames = (evidence.frames ?? '').toLowerCase()
87
+ const widgets = evidence.widgets ?? []
88
+ for (const s of signatures) {
89
+ if (s.errorOnly === true && status < 400) continue
90
+ if (s.kind === 'rate-limit') {
91
+ if (status === 429) return { blocked: true, kind: s.kind, reason: s.reason, recovery: s.recovery, ...status > 0 ? { status } : {} }
92
+ continue
93
+ }
94
+ const hit = (s.widget !== undefined && widgets.includes(s.widget))
95
+ || (s.frames !== undefined && new RegExp(s.frames, 'i').test(frames))
96
+ || (s.text !== undefined && s.text !== '' && new RegExp(s.text, 'i').test(text))
97
+ if (hit) return { blocked: true, kind: s.kind, reason: s.reason, recovery: s.recovery, ...status > 0 ? { status } : {} }
98
+ }
99
+ // An error page with almost nothing on it, served to a browser, is a refusal in all but name.
100
+ if ((status === 403 || status === 503) && text.replace(/\s+/g, ' ').trim().length < 400) {
101
+ return { blocked: true, kind: 'access-denied', reason: `HTTP ${status} with an empty page (likely a bot block)`, recovery: 'retry', status }
102
+ }
103
+ return { blocked: false }
104
+ }
105
+
106
+ /**
107
+ * Classify a page from what it shows.
108
+ * @param evidence - status, title, text, iframe sources and visible widgets.
109
+ * @returns `{ blocked: false }` or the kind, reason and recovery.
110
+ */
111
+ export function classifyBlock(evidence: BlockEvidence): BrowserChallenge {
112
+ return classify(evidence, SIGNATURES)
113
+ }
114
+
115
+ /**
116
+ * The page-context detector: collects the evidence (main-document status, visible text including
117
+ * open shadow roots and same-origin frames, iframe sources, and challenge widgets that are actually
118
+ * visible, so an invisible reCAPTCHA v3 badge on a login page is not a block) and classifies it.
119
+ * @returns a JavaScript expression evaluating to a {@link BrowserChallenge}.
120
+ */
121
+ export function challengeDetectSource(): string {
122
+ return `(() => {
123
+ try {
124
+ const visible = el => { if (!el) return false; const r = el.getBoundingClientRect(); if (r.width < 30 || r.height < 30) return false; const cs = getComputedStyle(el); return cs.visibility !== 'hidden' && cs.display !== 'none' && Number(cs.opacity) > 0.05 }
125
+ let extra = ''
126
+ const frames = []
127
+ const widgets = new Set()
128
+ const seen = new Set()
129
+ const scan = doc => {
130
+ if (seen.has(doc)) return
131
+ seen.add(doc)
132
+ for (const el of doc.querySelectorAll('*')) {
133
+ if (el.shadowRoot) { extra += '\\n' + (el.shadowRoot.textContent || '').slice(0, 2000); scan(el.shadowRoot) }
134
+ if (el.tagName === 'IFRAME') {
135
+ const src = el.src || ''
136
+ frames.push(src)
137
+ if (visible(el)) {
138
+ if (/hcaptcha\\.com/i.test(src)) widgets.add('hcaptcha')
139
+ if (/recaptcha\\/(?:api2|enterprise)\\/(?:anchor|bframe)/i.test(src)) widgets.add('recaptcha')
140
+ if (/challenges\\.cloudflare\\.com/i.test(src)) widgets.add('turnstile')
141
+ }
142
+ try { const d = el.contentDocument; if (d) { extra += '\\n' + ((d.body && d.body.innerText) || '').slice(0, 2000); scan(d) } } catch { /* cross-origin */ }
143
+ }
144
+ }
145
+ }
146
+ scan(document)
147
+ for (const [selector, kind] of [['.h-captcha', 'hcaptcha'], ['.g-recaptcha', 'recaptcha'], ['.cf-turnstile', 'turnstile'], ['#px-captcha', 'perimeterx'], ['.geetest_panel, .geetest_slider, .nc_wrapper, .captcha-slider, #slider-captcha', 'slider']]) {
148
+ for (const el of document.querySelectorAll(selector)) if (visible(el)) widgets.add(kind)
149
+ }
150
+ if (document.querySelector('#challenge-running, #challenge-stage, #cf-chl-container, #cf-challenge-running')) widgets.add('cloudflare')
151
+ const nav = performance.getEntriesByType && performance.getEntriesByType('navigation')[0]
152
+ const status = nav && typeof nav.responseStatus === 'number' ? nav.responseStatus : 0
153
+ const evidence = { status, title: document.title || '', text: ((document.body && document.body.innerText) || '').slice(0, 4000) + extra.slice(0, 4000), frames: frames.join(' '), widgets: [...widgets] }
154
+ return (${classify.toString()})(evidence, ${JSON.stringify(SIGNATURE_DATA)})
155
+ } catch { return { blocked: false } }
156
+ })()`
157
+ }
158
+
159
+ /**
160
+ * How long to pause before the one retry a refused page gets, so the retry reads as a person
161
+ * coming back rather than a script hammering. `DSH_BROWSER_BLOCK_RETRY_MS` tunes it (tests use 0).
162
+ * @returns the pause in milliseconds.
163
+ */
164
+ export function blockRetryDelayMs(): number {
165
+ const raw = Number(process.env.DSH_BROWSER_BLOCK_RETRY_MS)
166
+ return Number.isFinite(raw) && raw >= 0 ? Math.min(raw, 60_000) : 2500
167
+ }
168
+
169
+ /** One alternative public route to the information a blocked page holds. */
170
+ export interface FallbackRoute {
171
+ readonly kind: 'api' | 'search' | 'archive'
172
+ readonly url: string
173
+ readonly note: string
174
+ }
175
+
176
+ const enc = encodeURIComponent
177
+
178
+ function safeDecode(text: string): string {
179
+ try { return decodeURIComponent(text) } catch { return text }
180
+ }
181
+
182
+ /**
183
+ * Public, documented endpoints of well-known sites that serve the same content without a browser.
184
+ * @param url - the blocked page.
185
+ * @returns the site's own API routes, most specific first.
186
+ */
187
+ function siteApis(url: URL): FallbackRoute[] {
188
+ const host = url.hostname.replace(/^(?:www|m|old|new)\./u, '')
189
+ const parts = url.pathname.split('/').filter(Boolean)
190
+ const out: FallbackRoute[] = []
191
+ if (host === 'reddit.com') {
192
+ out.push({ kind: 'api', url: `https://www.reddit.com${url.pathname.replace(/\/$/u, '')}.json${url.search}`, note: 'Reddit JSON view of the same listing or thread' })
193
+ } else if (host === 'github.com' && parts.length >= 2) {
194
+ const [owner, repo, section, ...rest] = parts
195
+ const base = `https://api.github.com/repos/${owner}/${repo}`
196
+ const tail = section === 'issues' || section === 'pull' ? `/${section === 'pull' ? 'pulls' : 'issues'}${rest[0] !== undefined ? `/${rest[0]}` : ''}` : section === 'releases' ? '/releases' : ''
197
+ out.push({ kind: 'api', url: base + tail, note: 'GitHub REST API' })
198
+ } else if (/(?:^|\.)wikipedia\.org$/u.test(host) && parts[0] === 'wiki' && parts[1] !== undefined) {
199
+ out.push({ kind: 'api', url: `https://${url.hostname}/api/rest_v1/page/html/${parts.slice(1).join('/')}`, note: 'Wikipedia REST API (page HTML)' })
200
+ } else if (host === 'news.ycombinator.com' && url.searchParams.get('id') !== null) {
201
+ out.push({ kind: 'api', url: `https://hacker-news.firebaseio.com/v0/item/${enc(url.searchParams.get('id')!)}.json`, note: 'Hacker News Firebase API' })
202
+ } else if (host === 'stackoverflow.com' && parts[0] === 'questions' && parts[1] !== undefined) {
203
+ out.push({ kind: 'api', url: `https://api.stackexchange.com/2.3/questions/${parts[1]}?site=stackoverflow&filter=withbody`, note: 'Stack Exchange API' })
204
+ } else if (host === 'npmjs.com' && parts[0] === 'package' && parts[1] !== undefined) {
205
+ out.push({ kind: 'api', url: `https://registry.npmjs.org/${parts.slice(1).join('/')}`, note: 'npm registry metadata' })
206
+ } else if (host === 'pypi.org' && parts[0] === 'project' && parts[1] !== undefined) {
207
+ out.push({ kind: 'api', url: `https://pypi.org/pypi/${parts[1]}/json`, note: 'PyPI JSON API' })
208
+ } else if ((host === 'youtube.com' && url.searchParams.get('v') !== null) || host === 'youtu.be') {
209
+ out.push({ kind: 'api', url: `https://www.youtube.com/oembed?format=json&url=${enc(url.href)}`, note: 'YouTube oEmbed (title, channel)' })
210
+ }
211
+ return out
212
+ }
213
+
214
+ /**
215
+ * Other public routes to a blocked page's information, in the order worth trying: the site's own
216
+ * API, search-engine results (snippets and other copies), then web archives.
217
+ * @param target - the blocked page's URL.
218
+ * @returns the routes; empty for a non-HTTP URL.
219
+ */
220
+ export function fallbackRoutes(target: string): FallbackRoute[] {
221
+ let url: URL
222
+ try { url = new URL(target) } catch { return [] }
223
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return []
224
+ // Third parties get the page's address only: a query, fragment or userinfo can carry a session
225
+ // token or a signature, and these routes are fetched from other services.
226
+ const page = `${url.protocol}//${url.host}${url.pathname}`
227
+ const bare = page.replace(/^https?:\/\//u, '')
228
+ const terms = `${url.hostname} ${safeDecode(url.pathname).replace(/[/_-]+/gu, ' ').trim()}`.trim()
229
+ return [
230
+ ...siteApis(url),
231
+ { kind: 'search', url: `https://www.bing.com/search?q=${enc(terms)}`, note: 'Bing results: snippets and other copies of the page' },
232
+ { kind: 'search', url: `https://duckduckgo.com/html/?q=${enc(terms)}`, note: 'DuckDuckGo HTML results' },
233
+ { kind: 'archive', url: `https://web.archive.org/web/2/${page}`, note: 'Wayback Machine: latest archived copy' },
234
+ { kind: 'archive', url: `https://archive.ph/newest/${bare}`, note: 'archive.today: latest snapshot' },
235
+ ]
236
+ }
237
+
238
+ /**
239
+ * What the agent is told to do for a verdict: one line, static per kind so it stays cache friendly.
240
+ * @param challenge - the verdict.
241
+ * @returns the instruction, or '' when the page is not blocked.
242
+ */
243
+ export function recoveryAdvice(challenge: BrowserChallenge): string {
244
+ if (challenge.blocked !== true) return ''
245
+ switch (challenge.recovery) {
246
+ case 'takeover': return 'Human verification: never solve it or retry it yourself. Call dsh_browser_request_takeover so the human completes it in the browser, then re-read the page. If takeover is skipped or unavailable, use the fallback routes.'
247
+ case 'wait': return 'A self-clearing interstitial: dsh_browser_wait (a few seconds) and re-check; if it turns into a human check, request takeover; if it persists, use the fallback routes.'
248
+ case 'environment': return 'The site refuses this network (an environment limit, not something to work around): do not retry. Use the fallback routes and report the block.'
249
+ default: return 'The site refused automated access. One paced retry in a fresh session was already made when it says so; do not hammer the site. Use the fallback routes for the same public information.'
250
+ }
251
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Page-side DOM traversal shared by every page script that looks elements up.
3
+ *
4
+ * Browser Use reads into same-origin iframes and open shadow roots; a lookup that only asks
5
+ * `document` misses what the snapshot just listed. Inject {@link DEEP_DOM_SOURCE} at the top of a
6
+ * page script, then use `__dshRoots()`, `__dshQuery(selector)` and `__dshQueryAll(selector)`.
7
+ * Cross-origin frames and closed shadow roots stay opaque, as the browser requires.
8
+ * @module dsh-browser/browser/deep-dom
9
+ */
10
+
11
+ export const DEEP_DOM_SOURCE = `
12
+ const __dshRoots = (start) => {
13
+ const roots = []
14
+ const seen = new Set()
15
+ const visit = (root) => {
16
+ if (!root || seen.has(root)) return
17
+ seen.add(root)
18
+ roots.push(root)
19
+ for (const el of root.querySelectorAll('*')) {
20
+ if (el.shadowRoot) visit(el.shadowRoot)
21
+ if (el.tagName === 'IFRAME' || el.tagName === 'FRAME') {
22
+ try { const d = el.contentDocument; if (d) visit(d) } catch (error) { /* cross-origin */ }
23
+ }
24
+ }
25
+ }
26
+ visit(start || document)
27
+ return roots
28
+ }
29
+ const __dshQuery = (selector) => {
30
+ const top = document.querySelector(selector)
31
+ if (top) return top
32
+ for (const root of __dshRoots()) { const found = root.querySelector(selector); if (found) return found }
33
+ return null
34
+ }
35
+ const __dshQueryAll = (selector) => {
36
+ const all = Array.from(document.querySelectorAll(selector))
37
+ for (const root of __dshRoots().slice(1)) all.push(...root.querySelectorAll(selector))
38
+ return all
39
+ }
40
+ `
@@ -0,0 +1,89 @@
1
+ import type { BrowserTab } from './types.ts'
2
+
3
+ export interface BrowserOwnerHandle {
4
+ readonly owner: string
5
+ }
6
+
7
+ export interface BrowserSessionHandle extends BrowserOwnerHandle {
8
+ readonly session: string
9
+ }
10
+
11
+ export interface BrowserTabHandle extends BrowserSessionHandle {
12
+ readonly tab: string
13
+ }
14
+
15
+ export type BrowserSessionWireId = string & { readonly __browserSessionWireId: unique symbol }
16
+ export type BrowserTabWireId = string & { readonly __browserTabWireId: unique symbol }
17
+
18
+ function identity(value: unknown): asserts value is string {
19
+ if (typeof value !== 'string' || value.length === 0) throw new Error('browser: handle identity must be a nonempty string')
20
+ }
21
+
22
+ export function browserSessionHandle(owner: string, session: string): BrowserSessionHandle {
23
+ identity(owner)
24
+ identity(session)
25
+ if (session.startsWith('dsh-session:')) {
26
+ const handle = resolveSessionHandle(session)
27
+ if (handle.owner !== owner) throw new Error('browser: session handle belongs to another owner')
28
+ return handle
29
+ }
30
+ return { owner, session }
31
+ }
32
+
33
+ export function resolveSessionHandle(wire: string): BrowserSessionHandle {
34
+ let values: unknown
35
+ try {
36
+ if (!wire.startsWith('dsh-session:v1:')) throw new Error()
37
+ values = JSON.parse(decodeURIComponent(wire.slice('dsh-session:v1:'.length)))
38
+ if (!Array.isArray(values) || values.length !== 2) throw new Error()
39
+ for (const value of values) identity(value)
40
+ } catch {
41
+ throw new Error('browser: invalid session handle')
42
+ }
43
+ const [owner, session] = values as [string, string]
44
+ const handle = { owner, session }
45
+ if (sessionWireId(handle) !== wire) throw new Error('browser: noncanonical session handle')
46
+ return handle
47
+ }
48
+
49
+ export function sessionWireId(scope: BrowserSessionHandle): BrowserSessionWireId {
50
+ identity(scope.owner)
51
+ identity(scope.session)
52
+ return `dsh-session:v1:${encodeURIComponent(JSON.stringify([scope.owner, scope.session]))}` as BrowserSessionWireId
53
+ }
54
+
55
+ export function tabWireId(handle: BrowserTabHandle): BrowserTabWireId {
56
+ identity(handle.owner)
57
+ identity(handle.session)
58
+ identity(handle.tab)
59
+ return `dsh-tab:v1:${encodeURIComponent(JSON.stringify([handle.owner, handle.session, handle.tab]))}` as BrowserTabWireId
60
+ }
61
+
62
+ export function scopedTabs(scope: BrowserSessionHandle, tabs: readonly BrowserTab[]): readonly (Omit<BrowserTab, 'id'> & { readonly id: BrowserTabWireId })[] {
63
+ return tabs.map(tab => ({ ...tab, id: tab.id.startsWith('dsh-tab:')
64
+ ? tabWireId(resolveTabHandle(scope, tab.id))
65
+ : tabWireId({ ...scope, tab: tab.id }) }))
66
+ }
67
+
68
+ export function readTabHandle(wire: string): BrowserTabHandle {
69
+ let values: unknown
70
+ try {
71
+ if (!wire.startsWith('dsh-tab:v1:')) throw new Error()
72
+ values = JSON.parse(decodeURIComponent(wire.slice('dsh-tab:v1:'.length)))
73
+ if (!Array.isArray(values) || values.length !== 3) throw new Error()
74
+ for (const value of values) identity(value)
75
+ } catch {
76
+ throw new Error('browser: invalid tab handle; use the id returned by dsh_browser_list_tabs')
77
+ }
78
+ const [owner, session, tab] = values as [string, string, string]
79
+ const handle = { owner, session, tab }
80
+ if (tabWireId(handle) !== wire) throw new Error('browser: noncanonical tab handle')
81
+ return handle
82
+ }
83
+
84
+ export function resolveTabHandle(scope: BrowserSessionHandle, wire: string): BrowserTabHandle {
85
+ const handle = readTabHandle(wire)
86
+ const { owner, session } = handle
87
+ if (owner !== scope.owner || session !== scope.session) throw new Error('browser: tab handle is not open in this owner/session; list tabs again')
88
+ return handle
89
+ }