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
@@ -5,13 +5,13 @@ import { access } from 'node:fs/promises';
5
5
  import { readTabHandle, resolveSessionHandle, resolveTabHandle, sessionWireId, tabWireId } from '../browser/handles.js';
6
6
  import { dshHome } from './paths.js';
7
7
  class LazyNativeBrowserClient {
8
- directory;
9
- browser;
10
8
  client;
11
9
  loading;
12
10
  disposed = false;
13
11
  detail = 'Optional browser extension is not connected; managed CDP fallback is available.';
14
12
  listeners = new Set();
13
+ directory;
14
+ browser;
15
15
  constructor(directory, browser) {
16
16
  this.directory = directory;
17
17
  this.browser = browser;
@@ -68,13 +68,13 @@ export function extensionInstallHelp(browser) {
68
68
  };
69
69
  }
70
70
  export class ExtensionBrowserViewHost {
71
- browser;
72
- client;
73
71
  get referenceOverlayOwner() { return 'client'; }
74
72
  views = new Map();
75
73
  detaching = new Map();
76
74
  unsubscribe;
77
75
  disposed = false;
76
+ browser;
77
+ client;
78
78
  constructor(browser, client = new LazyNativeBrowserClient(extensionDirectory(browser), browser)) {
79
79
  this.browser = browser;
80
80
  this.client = client;
@@ -0,0 +1,134 @@
1
+ import { spawn } from 'node:child_process';
2
+ const POLL_MS = 500;
3
+ const PARENT_CHECK_MS = 4000;
4
+ /*
5
+ * A foreground hook reports each activation within a millisecond; the poll only catches the
6
+ * foreground window moving on or off the displays, and a Stopwatch checks parent liveness
7
+ * every 4 s regardless of foreground event frequency.
8
+ */
9
+ const script = (parent, browserPid) => [
10
+ `$parent = ${parent}; $browser = ${browserPid}`,
11
+ 'try {',
12
+ 'Add-Type -TypeDefinition @"',
13
+ 'using System; using System.Diagnostics; using System.Runtime.InteropServices;',
14
+ 'public static class DshForeground {',
15
+ ' [StructLayout(LayoutKind.Sequential)] public struct Rect { public int Left, Top, Right, Bottom; }',
16
+ ' [StructLayout(LayoutKind.Sequential)] public struct InputInfo { public uint Size, Time; }',
17
+ ' [StructLayout(LayoutKind.Sequential)] public struct Msg { public IntPtr Hwnd; public uint Message; public IntPtr W, L; public uint Time; public int X, Y; }',
18
+ ' public delegate void Hook(IntPtr hook, uint e, IntPtr h, int o, int c, uint t, uint time);',
19
+ ' [DllImport("user32.dll")] static extern IntPtr SetWinEventHook(uint min, uint max, IntPtr mod, Hook f, uint pid, uint tid, uint flags);',
20
+ ' [DllImport("user32.dll")] static extern uint MsgWaitForMultipleObjects(uint n, IntPtr[] h, bool all, uint ms, uint mask);',
21
+ ' [DllImport("user32.dll")] static extern bool PeekMessage(out Msg m, IntPtr h, uint a, uint b, uint remove);',
22
+ ' [DllImport("user32.dll")] static extern bool TranslateMessage(ref Msg m);',
23
+ ' [DllImport("user32.dll")] static extern IntPtr DispatchMessage(ref Msg m);',
24
+ ' [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();',
25
+ ' [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint p);',
26
+ ' [DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr h, out Rect r);',
27
+ ' [DllImport("user32.dll")] static extern bool IsIconic(IntPtr h);',
28
+ ' [DllImport("user32.dll")] static extern uint GetDpiForWindow(IntPtr h);',
29
+ ' [DllImport("user32.dll")] static extern IntPtr MonitorFromRect(ref Rect r, uint flags);',
30
+ ' [DllImport("user32.dll")] public static extern bool SetProcessDpiAwarenessContext(IntPtr c);',
31
+ ' [DllImport("user32.dll")] public static extern bool SetProcessDPIAware();',
32
+ ' [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr h);',
33
+ ' [DllImport("user32.dll")] static extern bool AttachThreadInput(uint a, uint b, bool f);',
34
+ ' [DllImport("kernel32.dll")] static extern uint GetCurrentThreadId();',
35
+ ' [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref InputInfo i);',
36
+ ' static uint LastInput() { var i = new InputInfo(); i.Size = 8; GetLastInputInfo(ref i); return i.Time; }',
37
+ ' static Hook keep; static string last = ""; static uint input, prevPid, browser; static IntPtr prev;',
38
+ ' static void Sample() {',
39
+ ' uint before = LastInput(), p; IntPtr h = GetForegroundWindow();',
40
+ // Transient null foreground (lock screen, UAC, window switch): keep prev intact instead of clearing it.
41
+ ' if (h == IntPtr.Zero) { input = before; return; }',
42
+ ' uint thread = GetWindowThreadProcessId(h, out p);',
43
+ ' Rect r; GetWindowRect(h, out r);',
44
+ // Physical pixels from GetWindowRect, so dividing by the window DPI gives DIPs at any scaling.
45
+ ' int off = IsIconic(h) || r.Right <= r.Left || MonitorFromRect(ref r, 0) != IntPtr.Zero ? 0 : 1;',
46
+ ' uint dpi = GetDpiForWindow(h); if (dpi == 0) dpi = 96;',
47
+ ' string line = p + " " + off + " " + Math.Round(r.Left * 96.0 / dpi) + " " + Math.Round(r.Top * 96.0 / dpi);',
48
+ // Chrome activates its own window for a tab a click opens; with no input since before the last read, no person did it.
49
+ // Always mark yielded even if SetForegroundWindow(prev) fails (e.g. elevated prev window under UIPI),
50
+ // and keep prev/prevPid unchanged so follow-up samples before focus settles cannot bypass the guard.
51
+ ' bool yielded = false;',
52
+ ' if (p == browser && off == 1 && prevPid != browser && prev != IntPtr.Zero && LastInput() == input) {',
53
+ ' yielded = true; line += " 1";',
54
+ ' uint me = GetCurrentThreadId(); AttachThreadInput(me, thread, true);',
55
+ ' SetForegroundWindow(prev);',
56
+ ' AttachThreadInput(me, thread, false);',
57
+ ' }',
58
+ ' if (line != last) { Console.Out.WriteLine(line); Console.Out.Flush(); last = line; }',
59
+ ' if (!yielded) { prev = h; prevPid = p; }',
60
+ ' input = before;',
61
+ ' }',
62
+ ' public static void Run(int parent, uint browserPid) {',
63
+ ' browser = browserPid; input = LastInput(); keep = (a, e, h, o, c, t, time) => Sample();',
64
+ ' SetWinEventHook(3, 3, IntPtr.Zero, keep, 0, 0, 0);',
65
+ ' var parentClock = Stopwatch.StartNew();',
66
+ ' Sample(); Msg m;',
67
+ ' for (;;) {',
68
+ ` if (MsgWaitForMultipleObjects(0, null, false, ${POLL_MS}, 0x4FF) == 0x102) Sample();`,
69
+ ' while (PeekMessage(out m, IntPtr.Zero, 0, 0, 1)) { TranslateMessage(ref m); DispatchMessage(ref m); }',
70
+ ` if (parentClock.ElapsedMilliseconds >= ${PARENT_CHECK_MS}) {`,
71
+ ' parentClock.Restart();',
72
+ ' try { Process.GetProcessById(parent).Dispose(); } catch (ArgumentException) { return; }',
73
+ ' }',
74
+ ' }',
75
+ ' }',
76
+ '}',
77
+ '"@',
78
+ '} catch { exit 3 }',
79
+ 'if (-not [DshForeground]::SetProcessDpiAwarenessContext([IntPtr](-4))) { [void][DshForeground]::SetProcessDPIAware() }',
80
+ 'try { [DshForeground]::Run($parent, $browser) } catch { exit 4 }',
81
+ ].join('\n');
82
+ /** One line of the watcher's output, `<pid> <0|1> [<left> <top> [1]]`, the last `1` when it gave the foreground back. */
83
+ export function parseForegroundLine(line) {
84
+ const match = /^(\d+) ([01])(?: (-?\d+) (-?\d+)( 1)?)?$/u.exec(line.trim());
85
+ if (match === null)
86
+ return undefined;
87
+ const event = { pid: Number(match[1]), offscreen: match[2] === '1' };
88
+ if (match[3] === undefined)
89
+ return event;
90
+ return { ...event, left: Number(match[3]), top: Number(match[4]), ...match[5] === undefined ? {} : { yielded: true } };
91
+ }
92
+ /**
93
+ * Report the foreground window's process, and whether that window is off every display, each time
94
+ * either changes. Windows only: CDP cannot tell a person activating a window from Chrome activating
95
+ * it for a tab an agent's click opened, but only the person's leaves input. The watcher exits with this process.
96
+ */
97
+ export const watchForeground = (onChange, onFail, browserPid = 0) => {
98
+ if (process.platform !== 'win32')
99
+ return undefined;
100
+ let child;
101
+ try {
102
+ child = spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand',
103
+ Buffer.from(script(process.pid, browserPid), 'utf16le').toString('base64')], { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
104
+ }
105
+ catch (error) {
106
+ onFail(String(error));
107
+ return undefined;
108
+ }
109
+ let stopped = false;
110
+ let failed = false;
111
+ const fail = (reason) => { if (!stopped && !failed) {
112
+ failed = true;
113
+ onFail(reason);
114
+ } };
115
+ child.on('error', error => fail(String(error)));
116
+ child.on('exit', (code, signal) => fail(`exited (${signal ?? code})`));
117
+ child.unref();
118
+ let buffer = '';
119
+ child.stdout?.setEncoding('utf8');
120
+ child.stdout?.on('data', (chunk) => {
121
+ buffer += chunk;
122
+ for (let end = buffer.indexOf('\n'); end >= 0; end = buffer.indexOf('\n')) {
123
+ const event = parseForegroundLine(buffer.slice(0, end));
124
+ buffer = buffer.slice(end + 1);
125
+ if (event !== undefined)
126
+ onChange(event);
127
+ }
128
+ });
129
+ child.stdout?.unref?.();
130
+ return { stop: () => { stopped = true; try {
131
+ child.kill();
132
+ }
133
+ catch { /* already gone */ } } };
134
+ };
@@ -1,7 +1,7 @@
1
1
  /*! Includes tldts and tldts-core (MIT); see guest-cookie-jar.LICENSE.txt. */
2
2
  import { isIP } from "node:net";
3
3
  import { domainToASCII } from "node:url";
4
- // node_modules/tldts-core/dist/es6/src/domain.js
4
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/domain.js
5
5
  /**
6
6
  * Check if `vhost` is a valid suffix of `hostname` (top-domain)
7
7
  *
@@ -39,7 +39,7 @@ function getDomain$1(suffix, hostname, options) {
39
39
  if (suffix.length === hostname.length - numberOfLeadingDots) return null;
40
40
  return extractDomainWithSuffix(hostname, suffix);
41
41
  }
42
- // node_modules/tldts-core/dist/es6/src/domain-without-suffix.js
42
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/domain-without-suffix.js
43
43
  /**
44
44
  * Return the part of domain without suffix.
45
45
  *
@@ -48,7 +48,7 @@ function getDomain$1(suffix, hostname, options) {
48
48
  function getDomainWithoutSuffix(domain, suffix) {
49
49
  return domain.slice(0, -suffix.length - 1);
50
50
  }
51
- // node_modules/tldts-core/dist/es6/src/extract-hostname.js
51
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/extract-hostname.js
52
52
  /**
53
53
  * @param url - URL we want to extract a hostname from.
54
54
  * @param urlIsValidHostname - hint from caller; true if `url` is already a valid hostname.
@@ -103,7 +103,7 @@ function extractHostname(url, urlIsValidHostname) {
103
103
  if (hasUpper) return hostname.toLowerCase();
104
104
  return hostname;
105
105
  }
106
- // node_modules/tldts-core/dist/es6/src/is-ip.js
106
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/is-ip.js
107
107
  /**
108
108
  * Check if a hostname is an IP. You should be aware that this only works
109
109
  * because `hostname` is already garanteed to be a valid hostname!
@@ -144,7 +144,7 @@ function isProbablyIpv6(hostname) {
144
144
  function isIp(hostname) {
145
145
  return isProbablyIpv6(hostname) || isProbablyIpv4(hostname);
146
146
  }
147
- // node_modules/tldts-core/dist/es6/src/is-valid.js
147
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/is-valid.js
148
148
  /**
149
149
  * Implements fast shallow verification of hostnames. This does not perform a
150
150
  * struct check on the content of labels (classes of Unicode characters, etc.)
@@ -179,7 +179,7 @@ function is_valid_default(hostname) {
179
179
  }
180
180
  return len - lastDotIndex - 1 <= 63 && lastCharCode !== 45;
181
181
  }
182
- // node_modules/tldts-core/dist/es6/src/options.js
182
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/options.js
183
183
  function setDefaultsImpl({ allowIcannDomains = true, allowPrivateDomains = false, detectIp = true, extractHostname = true, mixedInputs = true, validHosts = null, validateHostname = true }) {
184
184
  return {
185
185
  allowIcannDomains,
@@ -196,7 +196,7 @@ function setDefaults(options) {
196
196
  if (options === void 0) return DEFAULT_OPTIONS;
197
197
  return setDefaultsImpl(options);
198
198
  }
199
- // node_modules/tldts-core/dist/es6/src/subdomain.js
199
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/subdomain.js
200
200
  /**
201
201
  * Returns the subdomain of a hostname string
202
202
  */
@@ -204,7 +204,7 @@ function getSubdomain(hostname, domain) {
204
204
  if (domain.length === hostname.length) return "";
205
205
  return hostname.slice(0, -domain.length - 1);
206
206
  }
207
- // node_modules/tldts-core/dist/es6/src/factory.js
207
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/factory.js
208
208
  /**
209
209
  * Implement a factory allowing to plug different implementations of suffix
210
210
  * lookup (e.g.: using a trie or the packed hashes datastructures). This is used
@@ -256,7 +256,7 @@ function parseImpl(url, step, suffixLookup, partialOptions, result) {
256
256
  result.domainWithoutSuffix = getDomainWithoutSuffix(result.domain, result.publicSuffix);
257
257
  return result;
258
258
  }
259
- // node_modules/tldts-core/dist/es6/src/lookup/fast-path.js
259
+ // ../../../node_modules/.pnpm/tldts-core@6.1.86/node_modules/tldts-core/dist/es6/src/lookup/fast-path.js
260
260
  function fast_path_default(hostname, options, out) {
261
261
  if (!options.allowPrivateDomains && hostname.length > 3) {
262
262
  const last = hostname.length - 1;
@@ -298,7 +298,7 @@ function fast_path_default(hostname, options, out) {
298
298
  }
299
299
  return false;
300
300
  }
301
- // node_modules/tldts/dist/es6/src/data/trie.js
301
+ // ../../../node_modules/.pnpm/tldts@6.1.86/node_modules/tldts/dist/es6/src/data/trie.js
302
302
  const exceptions = (function() {
303
303
  const _0 = [1, {}], _1 = [2, {}], _2 = [0, { "city": _0 }];
304
304
  return [0, {
@@ -10337,7 +10337,7 @@ const rules = (function() {
10337
10337
  "zuerich": _3
10338
10338
  }];
10339
10339
  })();
10340
- // node_modules/tldts/dist/es6/src/suffix-trie.js
10340
+ // ../../../node_modules/.pnpm/tldts@6.1.86/node_modules/tldts/dist/es6/src/suffix-trie.js
10341
10341
  /**
10342
10342
  * Lookup parts of domain in Trie
10343
10343
  */
@@ -10383,7 +10383,7 @@ function suffixLookup(hostname, options, out) {
10383
10383
  out.isPrivate = false;
10384
10384
  out.publicSuffix = (_a = hostnameParts[hostnameParts.length - 1]) !== null && _a !== void 0 ? _a : null;
10385
10385
  }
10386
- // node_modules/tldts/dist/es6/index.js
10386
+ // ../../../node_modules/.pnpm/tldts@6.1.86/node_modules/tldts/dist/es6/index.js
10387
10387
  const RESULT = getEmptyResult();
10388
10388
  function getDomain(url, options = {}) {
10389
10389
  resetResult(RESULT);
@@ -10446,8 +10446,8 @@ function pathMatches(pathname, path) {
10446
10446
  return pathname === path || pathname.startsWith(path) && (path.endsWith("/") || pathname[path.length] === "/");
10447
10447
  }
10448
10448
  var GuestCookieJar = class {
10449
- changed;
10450
10449
  store = /* @__PURE__ */ new Map();
10450
+ changed;
10451
10451
  constructor(changed, saved = []) {
10452
10452
  this.changed = changed;
10453
10453
  for (const value of saved) {
@@ -1,11 +1,16 @@
1
1
  import { hostMessages } from '../../assets/browser-messages.mjs';
2
- import { GUEST_ROUTE } from '../../assets/browser-policy.mjs';
2
+ import { GUEST_ROUTE, RELAXED_BROWSER_SANDBOX, WEB_BROWSER_SANDBOX } from '../../assets/browser-policy.mjs';
3
3
  import { promises as dns } from 'node:dns';
4
+ import { Agent, fetch as undiciFetch } from 'undici';
5
+ import { networkInterfaces } from 'node:os';
4
6
  import { randomUUID } from 'node:crypto';
5
7
  import { guestRuntimeScript } from './guest-runtime.js';
8
+ import { blockRetryDelayMs, classifyBlock } from '../browser/anti-bot.js';
6
9
  import { localGuestCookies } from './guest-cookie-store.js';
7
10
  import { rewriteCss } from './guest-css.js';
8
11
  import { localGuestStorage } from './guest-storage.js';
12
+ /** Captured at load time so production uses undici's matching fetch while tests mocking globalThis.fetch still work. */
13
+ const defaultGlobalFetch = globalThis.fetch;
9
14
  /** Prefix every proxied document and subresource lives under. */
10
15
  /**
11
16
  * Whether a proxied target is this machine (or this host) itself.
@@ -35,6 +40,69 @@ function isSelfTarget(url) {
35
40
  return false;
36
41
  }
37
42
  export { GUEST_ROUTE };
43
+ function blockedTarget(url, host) {
44
+ return !/^https?:$/u.test(url.protocol) || url.username !== '' || url.password !== ''
45
+ || isSelfTarget(url) || url.hostname.toLowerCase().replace(/\.$/u, '') === host;
46
+ }
47
+ async function lookupAll(hostname) {
48
+ return await dns.lookup(hostname.replace(/^\[|\]$/gu, ''), { all: true });
49
+ }
50
+ async function addressesFor(hostname) {
51
+ return (await lookupAll(hostname)).map(record => record.address);
52
+ }
53
+ async function vettedAddress(url, host, ownAddresses) {
54
+ if (blockedTarget(url, host))
55
+ return undefined;
56
+ const records = await lookupAll(url.hostname);
57
+ const hostUrl = host === '' ? undefined : new URL('http://' + host);
58
+ const hostAddresses = hostUrl === undefined || isSelfTarget(hostUrl) ? [] : await addressesFor(host).catch(() => []);
59
+ const unsafe = records.length === 0 || records.some(({ address }) => {
60
+ const literal = new URL('http://' + (address.includes(':') ? '[' + address + ']' : address));
61
+ return isSelfTarget(literal) || hostAddresses.includes(address) || ownAddresses.includes(address);
62
+ });
63
+ return unsafe ? undefined : records;
64
+ }
65
+ async function blockedResolvedTarget(url, host, ownAddresses) {
66
+ return await vettedAddress(url, host, ownAddresses) === undefined;
67
+ }
68
+ /**
69
+ * Connect to the address that was vetted, so a second DNS answer (rebinding) never picks the peer.
70
+ *
71
+ * Uses `undici`'s own `fetch` alongside its `Agent` so the dispatcher protocol stays paired across
72
+ * Node major versions (e.g. Node 24 vs Node 26+). When a test replaces `globalThis.fetch`, defer
73
+ * to that mock without injecting an external `undici` dispatcher into it.
74
+ */
75
+ async function fetchVetted(url, init, host, ownAddresses) {
76
+ const addresses = await vettedAddress(url, host, ownAddresses);
77
+ if (addresses === undefined)
78
+ throw new UnsafeGuestTargetError('local and DSH host targets are not allowed');
79
+ if (globalThis.fetch !== defaultGlobalFetch) {
80
+ return await globalThis.fetch(url, init);
81
+ }
82
+ const dispatcher = new Agent({
83
+ connect: {
84
+ lookup: (_hostname, options, callback) => {
85
+ const done = typeof options === 'function' ? options : callback;
86
+ const all = typeof options === 'object' && options !== null && options.all === true;
87
+ if (all)
88
+ done(null, addresses.map(record => ({ ...record })));
89
+ else
90
+ done(null, addresses[0]?.address, addresses[0]?.family);
91
+ },
92
+ },
93
+ });
94
+ const headers = init.headers === undefined ? undefined : Array.from(new Headers(init.headers));
95
+ try {
96
+ return await undiciFetch(url, {
97
+ ...init,
98
+ ...(headers === undefined ? {} : { headers }),
99
+ dispatcher,
100
+ });
101
+ }
102
+ finally {
103
+ void dispatcher.close().catch(() => { });
104
+ }
105
+ }
38
106
  class UnsafeGuestTargetError extends Error {
39
107
  }
40
108
  /** HTML responses larger than this pass through without rewriting. */
@@ -90,6 +158,21 @@ const SAFE_REQUEST_HEADERS = new Set([
90
158
  'x-csrf-token', 'x-xsrf-token', 'range', 'if-range',
91
159
  'if-none-match', 'if-modified-since', 'cache-control',
92
160
  ]);
161
+ function guestReferer(page, target, policy) {
162
+ const sameOrigin = page.origin === target.origin;
163
+ const downgrade = page.protocol === 'https:' && target.protocol === 'http:';
164
+ const origin = page.origin + '/';
165
+ switch (policy) {
166
+ case 'no-referrer': return undefined;
167
+ case 'unsafe-url': return page.href;
168
+ case 'origin': return origin;
169
+ case 'same-origin': return sameOrigin ? page.href : undefined;
170
+ case 'strict-origin': return downgrade ? undefined : origin;
171
+ case 'origin-when-cross-origin': return sameOrigin ? page.href : origin;
172
+ case 'no-referrer-when-downgrade': return downgrade ? undefined : page.href;
173
+ default: return downgrade ? undefined : sameOrigin ? page.href : origin;
174
+ }
175
+ }
93
176
  function siteHeader(name) {
94
177
  return /^[!#$%&'*+.^_`|~\da-z-]+$/u.test(name)
95
178
  && !/^(?:cookie2?|authorization|host|origin|referer|connection|content-length|accept-encoding|user-agent|proxy-.*|sec-.*|x-dsh-.*|x-forwarded-.*|x-real-ip)$/u.test(name);
@@ -242,9 +325,9 @@ export function relayTag(_sessionId) {
242
325
  });
243
326
  </script>`;
244
327
  }
245
- function guestPolicy(authority) {
328
+ function guestPolicy(authority, framed) {
246
329
  const sources = ['http:', 'https:'].map(protocol => new URL(protocol + '//' + authority).origin + GUEST_ROUTE).join(' ');
247
- return "sandbox allow-scripts allow-forms; default-src " + sources
330
+ return "sandbox " + (framed ? RELAXED_BROWSER_SANDBOX : WEB_BROWSER_SANDBOX) + "; default-src " + sources
248
331
  + "; script-src " + sources + " 'unsafe-inline' 'unsafe-eval'; style-src " + sources
249
332
  + " 'unsafe-inline'; img-src " + sources + " data: blob:; font-src " + sources + " data:; connect-src " + sources
250
333
  + "; frame-src " + sources + "; form-action " + sources
@@ -259,7 +342,7 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
259
342
  response.end('guest proxy: invalid host');
260
343
  return;
261
344
  }
262
- const policy = guestPolicy(authority);
345
+ const policy = guestPolicy(authority, request.headers['sec-fetch-dest'] === 'iframe');
263
346
  const writeHead = (status, headers = {}) => {
264
347
  response.writeHead(status, { ...headers, 'content-security-policy': policy });
265
348
  };
@@ -270,7 +353,7 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
270
353
  const requested = String(request.headers['access-control-request-headers'] ?? '').toLowerCase().split(',').map(name => name.trim());
271
354
  writeHead(204, {
272
355
  'access-control-allow-methods': 'GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS',
273
- 'access-control-allow-headers': [...new Set([...SAFE_REQUEST_HEADERS, 'x-dsh-guest-sub', 'x-dsh-guest-headers', ...requested.filter(siteHeader)])].join(', '),
356
+ 'access-control-allow-headers': [...new Set([...SAFE_REQUEST_HEADERS, 'x-dsh-guest-sub', 'x-dsh-guest-headers', 'x-dsh-guest-referer', 'x-dsh-guest-referrer-policy', ...requested.filter(siteHeader)])].join(', '),
274
357
  });
275
358
  response.end();
276
359
  return;
@@ -288,27 +371,9 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
288
371
  host = new URL('http://' + (request.headers.host ?? '')).hostname.toLowerCase().replace(/\.$/u, '');
289
372
  }
290
373
  catch { }
291
- const blocked = (url) => {
292
- return !/^https?:$/u.test(url.protocol) || url.username !== '' || url.password !== ''
293
- || isSelfTarget(url) || url.hostname.toLowerCase().replace(/\.$/u, '') === host;
294
- };
295
- const addressesFor = async (hostname) => (await dns.lookup(hostname.replace(/^\[|\]$/gu, ''), { all: true })).map(record => record.address);
296
- const blockedResolved = async (url) => {
297
- if (blocked(url))
298
- return true;
299
- const addresses = await addressesFor(url.hostname);
300
- const hostUrl = host === '' ? undefined : new URL('http://' + host);
301
- const hostAddresses = hostUrl === undefined || isSelfTarget(hostUrl) ? [] : await addressesFor(host).catch(() => []);
302
- return addresses.length === 0 || addresses.some(address => {
303
- const literal = new URL('http://' + (address.includes(':') ? '[' + address + ']' : address));
304
- return isSelfTarget(literal) || hostAddresses.includes(address) || address === request.socket.localAddress;
305
- });
306
- };
307
- const fetchTarget = async (url, options) => {
308
- if (await blockedResolved(url))
309
- throw new UnsafeGuestTargetError('local and DSH host targets are not allowed');
310
- return fetch(url, options);
311
- };
374
+ const blocked = (url) => blockedTarget(url, host);
375
+ const blockedResolved = (url) => blockedResolvedTarget(url, host, request.socket.localAddress === undefined ? [] : [request.socket.localAddress]);
376
+ const fetchTarget = (url, options) => fetchVetted(url, options, host, request.socket.localAddress === undefined ? [] : [request.socket.localAddress]);
312
377
  if (blocked(target)) {
313
378
  writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
314
379
  response.end('guest proxy: local and DSH host targets are not allowed');
@@ -412,6 +477,20 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
412
477
  }
413
478
  catch { }
414
479
  }
480
+ const pageReferer = request.headers['x-dsh-guest-referer'];
481
+ if (subRequest && !headers.has('referer') && typeof pageReferer === 'string') {
482
+ try {
483
+ const page = new URL(pageReferer);
484
+ page.hash = '';
485
+ page.username = '';
486
+ page.password = '';
487
+ const policy = request.headers['x-dsh-guest-referrer-policy'];
488
+ const value = blocked(page) ? undefined : guestReferer(page, target, typeof policy === 'string' ? policy : '');
489
+ if (value !== undefined)
490
+ headers.set('referer', value);
491
+ }
492
+ catch { }
493
+ }
415
494
  let cookieJar;
416
495
  try {
417
496
  cookieJar = cookies ?? localGuestCookies();
@@ -496,15 +575,17 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
496
575
  }
497
576
  upstream = await fetchTarget(target, { method, headers, body: body, redirect: 'manual' });
498
577
  cookieJar.setCookies(target, upstream.headers.getSetCookie?.() ?? []);
499
- // 反爬挑战识别 + 一次重试:站点(百度 `/s?wd=…`)在没有「先访问过站点」的痕迹时回「安全验证」。
500
- // 罐子里可能已经带着上次挑战页的 Cookie,所以这里不看有没有 Cookie,而是看**内容**:
501
- // 命中挑战就先取站点根补一次 Cookie,带上根的 Referer 重试一次。仍失败就把挑战页交给上层。
502
- const looksLikeChallenge = /安全验证|wappass|cf-browser-verification|Just a moment/iu;
578
+ // 反爬拦截识别 + 一次重试(分类器与页面内检测共用 `browser/anti-bot.ts`):站点(百度 `/s?wd=…`)在没有
579
+ // 「先访问过站点」的痕迹时回「安全验证」。罐子里可能已经带着上次挑战页的 Cookie,所以看**内容**而不看有没有 Cookie。
580
+ // 只对「可重试」类(拒绝访问 / 429 / 空 403)与需人工验证类做一次放慢节奏的重试:先停一下,取站点根补 Cookie、
581
+ // 带上根的 Referer 再请求一次。仍失败就把原页交给上层(页内检测会给出接管或换路的建议);网络(IP)封锁不重试。
503
582
  if (safeNavigation && target.pathname !== '/' && /^text\/html/iu.test(upstream.headers.get('content-type') ?? '')
504
583
  && Number(upstream.headers.get('content-length') ?? '0') <= MAX_REWRITE_BYTES) {
505
584
  const probe = await upstream.clone().text();
506
- if (looksLikeChallenge.test(probe)) {
585
+ const verdict = classifyBlock({ status: upstream.status, text: probe.slice(0, 64 * 1024) });
586
+ if (verdict.blocked && verdict.recovery !== 'environment') {
507
587
  try {
588
+ await new Promise(resolve => setTimeout(resolve, blockRetryDelayMs()));
508
589
  await warmRoot();
509
590
  const retried = await fetchTarget(target, { method, headers, redirect: 'manual' });
510
591
  await upstream.body?.cancel();
@@ -579,7 +660,7 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
579
660
  const storageConfig = (destination === 'iframe' || destination === 'document') && request.headers['sec-fetch-mode'] === 'navigate'
580
661
  && /^[\w:-]{16,128}$/u.test(context)
581
662
  ? { token: (storage ?? localGuestStorage()).issue(target.origin, context), context, cookies: cookieJar.getDocumentCookie(target) } : undefined;
582
- const runtime = '<script data-dsh-guest-runtime="1">' + guestRuntimeScript(target.href, storageConfig) + '</script>';
663
+ const runtime = '<script data-dsh-guest-runtime="1">' + guestRuntimeScript(target.href, storageConfig, upstream.headers.get('referrer-policy') ?? '') + '</script>';
583
664
  let body = rewriteDocument(raw, target);
584
665
  if (/<head\b[^>]*>/iu.test(body))
585
666
  body = body.replace(/<head\b[^>]*>/iu, match => match + runtime);
@@ -601,3 +682,71 @@ export async function handleGuest(request, response, overlayScript, sessionId, c
601
682
  failUpstream('response', error);
602
683
  }
603
684
  }
685
+ function realGuestUrl(raw) {
686
+ const parsed = new URL(raw, 'http://guest.invalid');
687
+ const inner = parsed.pathname === GUEST_ROUTE ? guestTarget(parsed.pathname + parsed.search) : undefined;
688
+ if (inner !== undefined)
689
+ return inner;
690
+ if (parsed.origin === 'http://guest.invalid')
691
+ throw new UnsafeGuestTargetError('a guest resource URL must be absolute');
692
+ return parsed;
693
+ }
694
+ /**
695
+ * Fetch one resource a guest page loaded, on the server and under the proxy's own target rules.
696
+ * The Web sidebar's guest is an iframe with no browser session, so this is the only way a frozen
697
+ * quote can get an image's bytes. It sends what the proxy sent when the page loaded the image:
698
+ * guest documents are no-referrer, so no referer and the cookie jar's unscoped cookies, and it
699
+ * keeps the cookies each redirect hop sets.
700
+ */
701
+ export async function fetchGuestResource(raw, options) {
702
+ const own = Object.values(networkInterfaces()).flatMap(list => (list ?? []).map(entry => entry.address));
703
+ let host = '';
704
+ try {
705
+ host = options.dshHost === undefined ? '' : new URL('http://' + options.dshHost).hostname.toLowerCase().replace(/[.]$/u, '');
706
+ }
707
+ catch { }
708
+ let url = realGuestUrl(raw);
709
+ let jar;
710
+ try {
711
+ jar = options.cookies ?? localGuestCookies();
712
+ }
713
+ catch {
714
+ jar = undefined;
715
+ }
716
+ for (let hop = 0; hop <= 5; hop++) {
717
+ const headers = new Headers({
718
+ 'user-agent': DESKTOP_UA, accept: 'image/avif,image/webp,image/apng,image/*,*/*;q=0.8', 'accept-encoding': 'identity',
719
+ });
720
+ const cookie = jar?.getCookieHeader(url);
721
+ if (cookie !== undefined && cookie !== '')
722
+ headers.set('cookie', cookie);
723
+ const response = await fetchVetted(url, { headers, redirect: 'manual', ...options.signal === undefined ? {} : { signal: options.signal } }, host, own);
724
+ jar?.setCookies(url, response.headers.getSetCookie?.() ?? []);
725
+ const location = response.headers.get('location');
726
+ if (response.status >= 300 && response.status < 400 && location !== null) {
727
+ await response.body?.cancel();
728
+ url = new URL(location, url);
729
+ continue;
730
+ }
731
+ if (!response.ok) {
732
+ await response.body?.cancel();
733
+ throw new Error('guest resource answered ' + response.status);
734
+ }
735
+ const chunks = [];
736
+ let size = 0;
737
+ const reader = response.body?.getReader();
738
+ while (reader !== undefined) {
739
+ const { done, value } = await reader.read();
740
+ if (done)
741
+ break;
742
+ size += value.byteLength;
743
+ if (size > options.maxBytes) {
744
+ await reader.cancel();
745
+ throw new Error('guest resource exceeds ' + options.maxBytes + ' bytes');
746
+ }
747
+ chunks.push(value);
748
+ }
749
+ return Buffer.concat(chunks);
750
+ }
751
+ throw new Error('guest resource redirected too many times');
752
+ }