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
@@ -1,357 +0,0 @@
1
- import { guestReferenceHandlerScript } from '../browser-reference/page-script.ts'
2
- import { guestStorageScript, type GuestStorageConfig } from './guest-storage-runtime.ts'
3
- import { guestCssRuntimeScript } from './guest-css-runtime.ts'
4
-
5
- /** Early, self-contained interception for documents served from the guest proxy. */
6
- export function guestRuntimeScript(pageUrl: string, storage?: GuestStorageConfig): string {
7
- return `(() => {
8
- if (window.__dshGuestRuntime) return;
9
- window.__dshGuestRuntime = true;
10
- let real = ${JSON.stringify(pageUrl).replace(/</gu, '\\u003c')};
11
- const route = '/dsh-builtin-browser/browser-view/isolated-guest';
12
- const attempt = fn => { try { return fn(); } catch {} };
13
- attempt(() => {
14
- const cache = { match: async () => undefined, matchAll: async () => [], keys: async () => [],
15
- add: async () => {}, addAll: async () => {}, put: async () => {}, delete: async () => false };
16
- const caches = { open: async () => cache, match: async () => undefined, has: async () => false,
17
- delete: async () => false, keys: async () => [] };
18
- Object.defineProperty(window, 'caches', { configurable: true, enumerable: true, get: () => caches });
19
- });
20
- ${storage === undefined ? '' : 'attempt(() => { ' + guestStorageScript(storage) + ' });'}
21
- const storageContext = ${JSON.stringify(storage?.context ?? '')};
22
- const contextual = value => {
23
- if (!storageContext) return value;
24
- const url = new URL(value, location.href);
25
- url.searchParams.set('storage-context', storageContext);
26
- return value.startsWith('/') ? url.pathname + url.search + url.hash : url.href;
27
- };
28
- const realURL = value => {
29
- const raw = String(value);
30
- const proxyURL = new URL(raw, location.origin + '/');
31
- if (proxyURL.origin === location.origin && proxyURL.pathname === route) {
32
- const inner = proxyURL.searchParams.get('u');
33
- if (inner) return new URL(inner);
34
- }
35
- let url = new URL(raw, real);
36
- if (url.origin === location.origin) {
37
- url = new URL(url.pathname + url.search + url.hash, new URL(real).origin);
38
- }
39
- return url;
40
- };
41
- const toProxy = value => {
42
- try {
43
- const raw = String(value);
44
- const hostURL = new URL(raw, location.origin + '/');
45
- if (hostURL.origin === location.origin && hostURL.pathname === route) return contextual(raw);
46
- const url = realURL(raw);
47
- return /^https?:$/.test(url.protocol) ? contextual(route + '?u=' + encodeURIComponent(url.href)) : raw;
48
- } catch { return value; }
49
- };
50
- window.__dshGuestToProxy = toProxy;
51
- const nativeFetch = window.fetch && window.fetch.bind(window);
52
- window.__dshGuestFetch = nativeFetch;
53
- attempt(() => {
54
- window.fetch = (input, init) => {
55
- try {
56
- const isRequest = input instanceof Request;
57
- const url = toProxy(isRequest ? input.url : input);
58
- if (!/^https?:$/.test(new URL(url, location.href).protocol)) return nativeFetch(input, init);
59
- const headers = new Headers(init && init.headers || (isRequest ? input.headers : undefined));
60
- headers.set('x-dsh-guest-headers', [...headers.keys()].filter(name => !name.startsWith('x-dsh-')).join(','));
61
- headers.set('x-dsh-guest-sub', '1');
62
- const options = Object.assign({}, init, { headers, mode: 'cors', credentials: 'omit' });
63
- return nativeFetch(isRequest ? new Request(new URL(url, location.href), input) : url, options);
64
- } catch (error) { return Promise.reject(error); }
65
- };
66
- });
67
- attempt(() => {
68
- const open = XMLHttpRequest.prototype.open;
69
- const send = XMLHttpRequest.prototype.send;
70
- const header = XMLHttpRequest.prototype.setRequestHeader;
71
- const names = new WeakMap();
72
- XMLHttpRequest.prototype.open = function(method, url, ...args) {
73
- const result = open.call(this, method, toProxy(url), ...args);
74
- names.set(this, new Set());
75
- attempt(() => this.setRequestHeader('x-dsh-guest-sub', '1'));
76
- return result;
77
- };
78
- XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
79
- const result = header.call(this, name, value);
80
- const key = String(name).toLowerCase();
81
- if (!key.startsWith('x-dsh-')) names.get(this)?.add(key);
82
- return result;
83
- };
84
- XMLHttpRequest.prototype.send = function(...args) {
85
- this.withCredentials = false;
86
- header.call(this, 'x-dsh-guest-headers', [...(names.get(this) || [])].join(','));
87
- return send.apply(this, args);
88
- };
89
- });
90
- attempt(() => {
91
- navigator.sendBeacon = (url, data) => {
92
- try {
93
- nativeFetch(toProxy(url), { method: 'POST', body: data, keepalive: true,
94
- headers: { 'x-dsh-guest-sub': '1' } }).catch(() => {});
95
- return true;
96
- } catch { return false; }
97
- };
98
- });
99
- let childRequestId = 0;
100
- const childError = code => {
101
- const error = new Error(code + ': this sidebar supports URL-only tabs, not native child windows or opener relationships');
102
- error.name = 'NotSupportedError'; error.code = code;
103
- return error;
104
- };
105
- const childRequest = (mode, url) => {
106
- if (loadId === undefined) throw childError('sidebar-tab-owner-not-ready');
107
- parent.postMessage({ type: 'dsh.browser.guest.child.request', loadId, requestId: ++childRequestId, mode, url }, '*');
108
- };
109
- const nativeChild = url => {
110
- attempt(() => childRequest('native-opener', url));
111
- throw childError('BROWSER_NATIVE_CHILD_UNAVAILABLE');
112
- };
113
- const detached = features => String(features || '').split(',').some(feature => {
114
- const [key, value] = feature.trim().toLowerCase().split(/\\s*=\\s*/);
115
- return ['noopener', 'noreferrer'].includes(key) && !['0', 'no', 'false'].includes(value);
116
- });
117
- attempt(() => { window.open = (url, target = '_blank', features = '') => {
118
- const name = String(target || '_blank').toLowerCase();
119
- if (name !== '_self' && (name !== '_blank' || !detached(features))) return nativeChild(String(url || ''));
120
- const next = realURL(url == null || String(url) === '' ? 'about:blank' : url);
121
- if (!/^https?:$/.test(next.protocol)) throw childError('invalid-child-url');
122
- if (name === '_self') { location.assign(toProxy(next.href)); return window; }
123
- childRequest('url-only', next.href);
124
- return null;
125
- }; });
126
- for (const name of ['pushState', 'replaceState']) attempt(() => {
127
- const original = history[name];
128
- history[name] = function(state, title, url) {
129
- if (url == null) return original.call(this, state, title, url);
130
- const next = attempt(() => realURL(url));
131
- const result = original.call(this, state, title, toProxy(url));
132
- if (next && /^https?:$/.test(next.protocol)) real = next.href;
133
- report();
134
- return result;
135
- };
136
- });
137
- let loadId;
138
- const documentId = String(Date.now()) + ':' + String(Math.random());
139
- let referenceRequestId = 0;
140
- const reference = ${guestReferenceHandlerScript()};
141
- const report = () => attempt(() => parent.postMessage({ type: 'dsh.browser.guest.navigation', url: real, depth: history.length, loadId, documentId, ready: document.readyState !== 'loading' }, '*'));
142
- attempt(() => window.addEventListener('message', event => {
143
- if (event.source !== parent || !event.data) return;
144
- if (event.data.type === 'dsh.browser.guest.navigation.request') {
145
- if (!Number.isSafeInteger(event.data.loadId) || event.data.loadId <= 0) return;
146
- loadId = event.data.loadId;
147
- report();
148
- } else if (event.data.type === 'dsh.browser.guest.reference.request') {
149
- const data = event.data;
150
- if (event.origin !== location.origin || data.loadId !== loadId || loadId === undefined || data.documentId !== documentId
151
- || !Number.isSafeInteger(data.requestId) || data.requestId <= referenceRequestId) return;
152
- referenceRequestId = data.requestId;
153
- const ack = { type: 'dsh.browser.guest.reference.ack', requestId: data.requestId, loadId, documentId, url: real };
154
- try {
155
- const current = new URL(real), source = new URL(data.url);
156
- current.hash = ''; source.hash = '';
157
- if (current.href !== source.href || document.readyState === 'loading') throw new Error('source document is not ready');
158
- if (!data.spec || typeof data.spec !== 'object' || Array.isArray(data.spec) || !['text', 'highlight', 'element', 'summary'].includes(data.operation)) throw new Error('invalid reference command');
159
- if (data.operation !== 'element' && (!Number.isSafeInteger(data.spec.maxChars) || data.spec.maxChars <= 0
160
- || data.spec.maxChars > 2000000 || typeof data.spec.legacy !== 'boolean')) throw new Error('invalid text specification');
161
- if (data.operation === 'element' && (!['image', 'table'].includes(data.spec.kind)
162
- || !data.spec.anchor || typeof data.spec.anchor !== 'object' || Array.isArray(data.spec.anchor))) throw new Error('invalid element specification');
163
- if (data.operation === 'highlight' && (!Number.isSafeInteger(data.spec.start) || !Number.isSafeInteger(data.spec.end)
164
- || data.spec.start < 0 || data.spec.end <= data.spec.start)) throw new Error('invalid text positions');
165
- const value = data.operation === 'summary'
166
- ? { url: real, title: String(document.title || '').slice(0, 1000), snapshotHint: reference('text', { maxChars: 1500, legacy: false }).text, fresh: true }
167
- : reference(data.operation, data.spec);
168
- parent.postMessage({ ...ack, ok: true, value }, event.origin);
169
- } catch (error) { parent.postMessage({ ...ack, ok: false, reason: String(error).slice(0, 200) }, event.origin); }
170
- } else if (event.data.type === 'dsh.browser.guest.history') {
171
- if (event.data.delta === -1) history.back();
172
- else if (event.data.delta === 1) history.forward();
173
- }
174
- }));
175
- attempt(() => window.addEventListener('DOMContentLoaded', report));
176
- attempt(() => window.addEventListener('popstate', () => {
177
- const next = attempt(() => realURL(location.href));
178
- if (next) real = next.href;
179
- report();
180
- }));
181
- attempt(() => {
182
- const proxyResource = value => {
183
- if (/^(#|data:|blob:|about:|javascript:)/i.test(value.trim())) return value;
184
- return toProxy(value);
185
- };
186
- ${guestCssRuntimeScript()}
187
- const proxySrcset = value => {
188
- let result = '', position = 0;
189
- while (position < value.length) {
190
- const start = position;
191
- while (position < value.length && /[\\s,]/.test(value[position])) position++;
192
- result += value.slice(start, position);
193
- if (position === value.length) break;
194
- const urlStart = position;
195
- while (position < value.length && !/\\s/.test(value[position])) position++;
196
- let urlEnd = position;
197
- while (urlEnd > urlStart && value[urlEnd - 1] === ',') urlEnd--;
198
- result += proxyResource(value.slice(urlStart, urlEnd)) + value.slice(urlEnd, position);
199
- if (urlEnd < position) continue;
200
- const descriptors = position;
201
- while (position < value.length && value[position] !== ',') position++;
202
- result += value.slice(descriptors, position);
203
- }
204
- return result;
205
- };
206
- const resourceAttribute = (name, value) => name.toLowerCase() === 'style' ? proxyCss(value)
207
- : name.toLowerCase() === 'srcset' ? proxySrcset(String(value)) : proxyResource(String(value));
208
- const set = Element.prototype.setAttribute;
209
- Element.prototype.setAttribute = function(name, value) {
210
- if (this.tagName === 'LINK' && /^integrity$/i.test(name)) {
211
- this.removeAttribute('integrity');
212
- return;
213
- }
214
- return set.call(this, name, /^(src|href|action|poster|srcset|style)$/i.test(name) ? resourceAttribute(name, value) : value);
215
- };
216
- for (const [name, prop] of [['HTMLImageElement', 'src'], ['HTMLScriptElement', 'src'],
217
- ['HTMLIFrameElement', 'src'], ['HTMLLinkElement', 'href'], ['HTMLSourceElement', 'src'],
218
- ['HTMLImageElement', 'srcset'], ['HTMLSourceElement', 'srcset'], ['HTMLVideoElement', 'poster']]) attempt(() => {
219
- const proto = window[name].prototype;
220
- const descriptor = Object.getOwnPropertyDescriptor(proto, prop);
221
- if (!descriptor || !descriptor.set) return;
222
- Object.defineProperty(proto, prop, Object.assign({}, descriptor, {
223
- set(value) { descriptor.set.call(this, resourceAttribute(prop, value)); }
224
- }));
225
- });
226
- const rewriteResource = node => {
227
- if (!node || node.nodeType !== 1) return;
228
- if (node.tagName === 'LINK' && node.hasAttribute('integrity')) node.removeAttribute('integrity');
229
- rewriteStyleText(node);
230
- const attributes = /^(A|FORM)$/.test(node.tagName) ? ['style'] : ['src', 'href', 'srcset', 'poster', 'style'];
231
- for (const attribute of attributes) attempt(() => {
232
- const value = node.getAttribute(attribute);
233
- if (!value || !value.trim()) return;
234
- const next = resourceAttribute(attribute, value);
235
- if (next !== value) node.setAttribute(attribute, next);
236
- });
237
- };
238
- const rewriteTree = node => {
239
- rewriteResource(node);
240
- if (node && node.querySelectorAll) {
241
- for (const descendant of node.querySelectorAll('[src],[href],[srcset],[poster],[style],[integrity],style')) rewriteResource(descendant);
242
- }
243
- };
244
- for (const name of ['Node', 'Element', 'Document', 'DocumentFragment']) {
245
- for (const method of ['appendChild', 'insertBefore', 'replaceChild', 'append', 'prepend', 'before', 'after', 'replaceWith', 'replaceChildren', 'insertAdjacentElement']) attempt(() => {
246
- const proto = window[name].prototype;
247
- if (!Object.prototype.hasOwnProperty.call(proto, method)) return;
248
- const original = proto[method];
249
- proto[method] = function(...args) {
250
- if (isStyle(this)) args = args.map(value => {
251
- if (typeof value === 'string') return proxyCss(value);
252
- if (value && value.nodeType === 3) value.textContent = proxyCss(value.textContent);
253
- return value;
254
- });
255
- for (const node of args) if (node && typeof node === 'object') rewriteTree(node);
256
- return original.apply(this, args);
257
- };
258
- });
259
- }
260
- const html = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
261
- let inert;
262
- const rewriteMarkup = (value, context) => {
263
- if (!inert) inert = document.implementation.createHTMLDocument('');
264
- const container = context && context.nodeType === 1
265
- ? inert.createElementNS(context.namespaceURI, context.localName) : inert.createElement('div');
266
- html.set.call(container, value);
267
- rewriteTree(container.content || container);
268
- return html.get.call(container);
269
- };
270
- for (const prop of ['innerHTML', 'outerHTML']) attempt(() => {
271
- const descriptor = Object.getOwnPropertyDescriptor(Element.prototype, prop);
272
- Object.defineProperty(Element.prototype, prop, Object.assign({}, descriptor, {
273
- set(value) { descriptor.set.call(this, rewriteMarkup(value, prop === 'innerHTML' ? this : this.parentElement)); }
274
- }));
275
- });
276
- attempt(() => {
277
- const original = Element.prototype.insertAdjacentHTML;
278
- Element.prototype.insertAdjacentHTML = function(position, value) {
279
- const outside = /^(beforebegin|afterend)$/i.test(position);
280
- return original.call(this, position, rewriteMarkup(value, outside ? this.parentElement : this));
281
- };
282
- });
283
- attempt(() => {
284
- const original = window.Range.prototype.createContextualFragment;
285
- window.Range.prototype.createContextualFragment = function(value) {
286
- const context = this.startContainer.nodeType === 1 ? this.startContainer : this.startContainer.parentElement;
287
- return original.call(this, rewriteMarkup(value, context));
288
- };
289
- });
290
- const observer = new MutationObserver(records => {
291
- for (const record of records) attempt(() => {
292
- if (record.type === 'attributes') rewriteResource(record.target);
293
- else if (record.type === 'characterData') rewriteStyleText(record.target.parentNode);
294
- else for (const node of record.addedNodes) rewriteTree(node);
295
- });
296
- });
297
- observer.observe(document, { childList: true, subtree: true, attributes: true, characterData: true,
298
- attributeFilter: ['src', 'href', 'srcset', 'poster', 'action', 'style', 'integrity'] });
299
- rewriteTree(document.documentElement);
300
- });
301
- attempt(() => document.addEventListener('click', event => {
302
- attempt(() => {
303
- let node = event.target;
304
- while (node && node.tagName !== 'A') node = node.parentNode;
305
- if (!node || !node.hasAttribute('href') || node.hasAttribute('download')) return;
306
- const href = node.getAttribute('href');
307
- const url = realURL(href);
308
- if (!/^https?:$/.test(url.protocol)) return;
309
- event.preventDefault();
310
- const target = (node.getAttribute('target') || '_self').toLowerCase();
311
- if (target !== '_self') {
312
- const opener = /(?:^|\\s)opener(?:\\s|$)/i.test(node.getAttribute('rel') || '');
313
- try { if (target !== '_blank' || opener) nativeChild(url.href); else childRequest('url-only', url.href); }
314
- catch (error) { console.error('[dsh-browser]', error); }
315
- return;
316
- }
317
- location.assign(toProxy(href));
318
- });
319
- }, true));
320
- const prepareForm = (form, submitter) => {
321
- const action = submitter && submitter.getAttribute('formaction') || form.getAttribute('action') || real;
322
- const method = (submitter && submitter.getAttribute('formmethod') || form.getAttribute('method') || 'GET').toUpperCase();
323
- const url = realURL(action);
324
- if (!/^https?:$/.test(url.protocol)) return false;
325
- const target = (submitter && submitter.getAttribute('formtarget') || form.getAttribute('target') || '_self').toLowerCase();
326
- if (target !== '_self' && (target !== '_blank' || method !== 'GET'
327
- || /(?:^|\\s)opener(?:\\s|$)/i.test(form.getAttribute('rel') || ''))) {
328
- try { nativeChild(url.href); } catch (error) { console.error('[dsh-browser]', error); }
329
- return true;
330
- }
331
- if (method === 'GET') {
332
- const params = new URLSearchParams();
333
- const data = submitter ? new FormData(form, submitter) : new FormData(form);
334
- for (const [key, value] of data) params.append(key, typeof value === 'string' ? value : value.name);
335
- url.search = params.toString();
336
- if (target === '_blank') {
337
- try { childRequest('url-only', url.href); } catch (error) { console.error('[dsh-browser]', error); }
338
- } else location.assign(toProxy(url.href));
339
- return true;
340
- }
341
- form.setAttribute('action', toProxy(url.href));
342
- form.setAttribute('target', '_self');
343
- if (submitter && submitter.hasAttribute('formaction')) submitter.setAttribute('formaction', toProxy(url.href));
344
- if (submitter && submitter.hasAttribute('formtarget')) submitter.setAttribute('formtarget', '_self');
345
- return false;
346
- };
347
- attempt(() => document.addEventListener('submit', event => {
348
- attempt(() => { if (event.target && event.target.tagName === 'FORM' && prepareForm(event.target, event.submitter)) event.preventDefault(); });
349
- }, true));
350
- attempt(() => {
351
- const submit = HTMLFormElement.prototype.submit;
352
- HTMLFormElement.prototype.submit = function() {
353
- if (!attempt(() => prepareForm(this))) return submit.call(this);
354
- };
355
- });
356
- })();`;
357
- }
@@ -1,54 +0,0 @@
1
- export interface GuestStorageConfig { readonly token: string; readonly context: string; readonly cookies?: string }
2
-
3
- /** Synchronous Web Storage remains isolated from the application's real origin. */
4
- export function guestStorageScript(config: GuestStorageConfig): string {
5
- return `(() => {
6
- const config = ${JSON.stringify(config).replace(/</gu, '\\u003c')};
7
- const XHR = XMLHttpRequest, open = XHR.prototype.open, send = XHR.prototype.send, header = XHR.prototype.setRequestHeader;
8
- const rpc = (area, op, key, value) => {
9
- const endpoint = location.pathname + '?u=' + encodeURIComponent(real) + '&storage-token=' + encodeURIComponent(config.token);
10
- const xhr = new XHR();
11
- open.call(xhr, 'POST', endpoint, false);
12
- header.call(xhr, 'content-type', 'text/plain;charset=UTF-8');
13
- send.call(xhr, JSON.stringify({ area, op, key, value }));
14
- let response;
15
- try { response = JSON.parse(xhr.responseText); } catch { throw new DOMException('Guest storage is unavailable', 'UnknownError'); }
16
- if (xhr.status !== 200 || !response.ok) throw new DOMException('Guest storage request failed', response.name || 'UnknownError');
17
- return response.value;
18
- };
19
- const cookieSnapshots = new Map([[real, config.cookies || '']]);
20
- Object.defineProperty(Document.prototype, 'cookie', { configurable: true, enumerable: true,
21
- get: function cookie() {
22
- if (this !== document) throw new TypeError('Illegal invocation');
23
- try { const value = rpc('cookies', 'get'); cookieSnapshots.set(real, value); return value; }
24
- catch (error) { if (error.name === 'NetworkError') return cookieSnapshots.get(real) || ''; throw error; }
25
- },
26
- set: function cookie(value) {
27
- if (this !== document) throw new TypeError('Illegal invocation');
28
- cookieSnapshots.set(real, rpc('cookies', 'set', undefined, String(value)));
29
- }
30
- });
31
- for (const area of ['local', 'session']) {
32
- const storage = Object.create(Storage.prototype);
33
- const entries = () => rpc(area, 'entries');
34
- Object.defineProperties(storage, {
35
- getItem: { configurable: true, value: function(key) { if (!arguments.length) throw new TypeError('A key is required'); return rpc(area, 'get', String(key)); } },
36
- setItem: { configurable: true, value: function(key, value) { if (arguments.length < 2) throw new TypeError('A key and value are required'); rpc(area, 'set', String(key), String(value)); } },
37
- removeItem: { configurable: true, value: function(key) { if (!arguments.length) throw new TypeError('A key is required'); rpc(area, 'remove', String(key)); } },
38
- clear: { configurable: true, value: () => { rpc(area, 'clear'); } },
39
- key: { configurable: true, value: function(index) { if (!arguments.length) throw new TypeError('An index is required'); return entries()[Number(index) >>> 0]?.[0] ?? null; } },
40
- length: { configurable: true, get: () => entries().length }
41
- });
42
- const proxy = new Proxy(storage, {
43
- get: (target, key) => typeof key !== 'string' || key in target ? Reflect.get(target, key) : rpc(area, 'get', key) ?? undefined,
44
- set: (_, key, value) => { if (typeof key !== 'string') return false; rpc(area, 'set', key, String(value)); return true; },
45
- deleteProperty: (_, key) => { if (typeof key !== 'string') return false; rpc(area, 'remove', key); return true; },
46
- has: (target, key) => key in target || (typeof key === 'string' && rpc(area, 'get', key) !== null),
47
- ownKeys: target => [...Reflect.ownKeys(target), ...entries().map(pair => pair[0]).filter(key => !Object.hasOwn(target, key))],
48
- getOwnPropertyDescriptor: (target, key) => Object.getOwnPropertyDescriptor(target, key)
49
- || (typeof key === 'string' && rpc(area, 'get', key) !== null ? { configurable: true, enumerable: true, writable: true, value: rpc(area, 'get', key) } : undefined)
50
- });
51
- Object.defineProperty(window, area + 'Storage', { configurable: true, get: () => proxy });
52
- }
53
- })();`
54
- }
@@ -1,117 +0,0 @@
1
- import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
2
- import { createHmac, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto'
3
- import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
4
- import { join } from 'node:path'
5
- import { dshHome } from './paths.ts'
6
-
7
- type Entries = Map<string, string>
8
- type Partitions = Map<string, Entries>
9
- const MAX_STORE_BYTES = 64 * 1024 * 1024
10
- const serialized = (partitions: Partitions): string => JSON.stringify([...partitions].map(([origin, entries]) => [origin, [...entries]]))
11
-
12
- function fail(name: string): never { throw Object.assign(new Error(name), { name }) }
13
-
14
- /** Storage capabilities are issued only in browser navigation responses, never fetchable HTML. */
15
- export class GuestStorage {
16
- private readonly secret = randomBytes(32)
17
- private local: Partitions = new Map()
18
- private session: Partitions = new Map()
19
-
20
- constructor(private readonly directory?: string, private readonly quota = 5 * 1024 * 1024) {
21
- if (directory === undefined) return
22
- let fd: number | undefined
23
- try {
24
- fd = openSync(join(directory, 'storage.json'), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0))
25
- if (!fstatSync(fd).isFile() || fstatSync(fd).size > MAX_STORE_BYTES) return
26
- fchmodSync(fd, 0o600)
27
- const saved: unknown = JSON.parse(readFileSync(fd, 'utf8'))
28
- if (!saved || typeof saved !== 'object' || !('version' in saved) || saved.version !== 1
29
- || !('origins' in saved) || !Array.isArray(saved.origins)) return
30
- for (const item of saved.origins) {
31
- if (!Array.isArray(item) || item.length !== 2 || typeof item[0] !== 'string' || !Array.isArray(item[1])) continue
32
- try { if (new URL(item[0]).origin !== item[0] || !/^https?:/u.test(item[0])) continue } catch { continue }
33
- const entries: Entries = new Map()
34
- for (const pair of item[1]) {
35
- if (Array.isArray(pair) && pair.length === 2 && pair.every(value => typeof value === 'string')) entries.set(pair[0], pair[1])
36
- }
37
- if (this.size(entries) <= quota) this.local.set(item[0], entries)
38
- }
39
- } catch {} finally { if (fd !== undefined) closeSync(fd) }
40
- }
41
-
42
- issue(origin: string, context: string): string {
43
- const payload = Buffer.from(JSON.stringify({ origin, context })).toString('base64url')
44
- return payload + '.' + createHmac('sha256', this.secret).update(payload).digest('base64url')
45
- }
46
-
47
- authorize(token: string, origin: string): { readonly context: string } {
48
- if (token.length > 8192) fail('SecurityError')
49
- const [payload, signature, extra] = token.split('.')
50
- const expected = createHmac('sha256', this.secret).update(payload ?? '').digest()
51
- const received = Buffer.from(signature ?? '', 'base64url')
52
- if (extra !== undefined || received.length !== expected.length || !timingSafeEqual(received, expected)) fail('SecurityError')
53
- let scope: { origin?: unknown; context?: unknown }
54
- try { scope = JSON.parse(Buffer.from(payload!, 'base64url').toString('utf8')) } catch { fail('SecurityError') }
55
- if (scope?.origin !== origin || typeof scope.context !== 'string') fail('SecurityError')
56
- return { context: scope.context }
57
- }
58
-
59
- execute(token: string, origin: string, input: unknown): unknown {
60
- const scope = this.authorize(token, origin)
61
- if (!input || typeof input !== 'object' || Array.isArray(input)) fail('TypeError')
62
- const { area, op, key, value } = input as Record<string, unknown>
63
- if (area !== 'local' && area !== 'session') fail('TypeError')
64
- if (!['entries', 'get', 'set', 'remove', 'clear'].includes(String(op))) fail('TypeError')
65
- if (op !== 'entries' && op !== 'clear' && typeof key !== 'string') fail('TypeError')
66
- if (op === 'set' && typeof value !== 'string') fail('TypeError')
67
- const partitions = area === 'local' ? this.local : this.session
68
- const partition = area === 'local' ? origin : JSON.stringify([scope.context, origin])
69
- const current = partitions.get(partition) ?? new Map<string, string>()
70
- if (op === 'entries') return [...current]
71
- if (op === 'get') return current.get(key as string) ?? null
72
- const next = new Map(current)
73
- if (op === 'clear') next.clear()
74
- else if (op === 'remove') next.delete(key as string)
75
- else next.set(key as string, value as string)
76
- if (this.size(next) > this.quota) fail('QuotaExceededError')
77
- const updated = new Map(partitions)
78
- if (next.size === 0) updated.delete(partition)
79
- else updated.set(partition, next)
80
- if (Buffer.byteLength(serialized(updated), 'utf8') > MAX_STORE_BYTES) fail('QuotaExceededError')
81
- if (area === 'local') {
82
- this.persist(updated)
83
- this.local = updated
84
- } else this.session = updated
85
- return null
86
- }
87
-
88
- private size(entries: Entries): number {
89
- return [...entries].reduce((size, [key, value]) => size + 2 * (key.length + value.length), 0)
90
- }
91
-
92
- private persist(origins: Partitions): void {
93
- if (this.directory === undefined) return
94
- const file = join(this.directory, 'storage.json'), temporary = file + '.' + randomUUID() + '.tmp'
95
- let fd: number | undefined
96
- try {
97
- mkdirSync(this.directory, { recursive: true, mode: 0o700 })
98
- fd = openSync(temporary, 'wx', 0o600)
99
- fchmodSync(fd, 0o600)
100
- writeFileSync(fd, '{"version":1,"origins":' + serialized(origins) + '}')
101
- fsyncSync(fd)
102
- closeSync(fd); fd = undefined
103
- renameSync(temporary, file)
104
- } catch { fail('UnknownError') } finally {
105
- if (fd !== undefined) closeSync(fd)
106
- try { rmSync(temporary, { force: true }) } catch {}
107
- }
108
- }
109
- }
110
-
111
- const stores = new Map<string, GuestStorage>()
112
- export function localGuestStorage(): GuestStorage {
113
- const directory = join(dshHome(), BROWSER_PROFILE_DIR, 'web-storage')
114
- let store = stores.get(directory)
115
- if (store === undefined) { store = new GuestStorage(directory); stores.set(directory, store) }
116
- return store
117
- }