dsh-builtin-browser 1.0.3 → 1.1.0

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 (305) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.en.md +89 -0
  3. package/browser-extension/constants.mjs +20 -0
  4. package/browser-extension/controller.mjs +293 -0
  5. package/browser-extension/locales.mjs +15 -0
  6. package/browser-extension/manifest.json +12 -0
  7. package/browser-extension/options.html +14 -0
  8. package/browser-extension/options.mjs +9 -0
  9. package/browser-extension/permission-guard.mjs +13 -0
  10. package/browser-extension/worker.mjs +74 -0
  11. package/desktop-bridge/desktop-identity.json +10 -2
  12. package/desktop-bridge/install.mjs +28 -2
  13. package/docs/issue-replies-2026-11-28.md +141 -0
  14. package/dsh-host-patch/apply.mjs +1 -1
  15. package/dsh-host-patch/rc3.json +4 -4
  16. package/dsh-host-patch/rc5.json +4 -4
  17. package/dsh-host-patch/v023-alpha2.json +2 -2
  18. package/lib/browser-electron/bridge-status.js +24 -1
  19. package/lib/browser-electron/desktop-identity.js +47 -8
  20. package/lib/client.js +2 -1
  21. package/native-host/install.mjs +5 -0
  22. package/package.json +20 -2
  23. package/scripts/build-client.mjs +305 -0
  24. package/scripts/build.mjs +69 -0
  25. package/scripts/bundle-host.mjs +28 -0
  26. package/scripts/fix-exports.mjs +40 -0
  27. package/scripts/install-electron.mjs +101 -0
  28. package/scripts/pack.mjs +99 -0
  29. package/scripts/publish-manifest.mjs +56 -0
  30. package/scripts/verify-exports.mjs +58 -0
  31. package/scripts/verify-preview-sdk.mjs +93 -0
  32. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  33. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  34. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  35. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  36. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  37. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  38. package/skills/dsh-debug-host/SKILL.md +56 -0
  39. package/skills/dsh-debug-self/SKILL.md +50 -0
  40. package/src/bridge-compatibility.ts +39 -0
  41. package/src/browser/anti-bot.ts +251 -0
  42. package/src/browser/deep-dom.ts +40 -0
  43. package/src/browser/handles.ts +89 -0
  44. package/src/browser/runtime.ts +578 -0
  45. package/src/browser/takeover-target.ts +45 -0
  46. package/src/browser/types.ts +870 -0
  47. package/src/browser-electron/authenticated-route.ts +109 -0
  48. package/src/browser-electron/automatic-maintenance.ts +736 -0
  49. package/src/browser-electron/bridge-auto.ts +159 -0
  50. package/src/browser-electron/bridge-connection.ts +386 -0
  51. package/src/browser-electron/bridge-endpoint.ts +129 -0
  52. package/src/browser-electron/bridge-install.ts +290 -0
  53. package/src/browser-electron/bridge-maintenance.ts +189 -0
  54. package/src/browser-electron/bridge-status.ts +412 -0
  55. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  56. package/src/browser-electron/desktop-identity.ts +400 -0
  57. package/src/browser-electron/desktop-shell.ts +100 -0
  58. package/src/browser-electron/document-readiness.ts +45 -0
  59. package/src/browser-electron/electron-provision.ts +347 -0
  60. package/src/browser-electron/entry.ts +1378 -0
  61. package/src/browser-electron/ephemeral-profile.ts +189 -0
  62. package/src/browser-electron/extension-browser.ts +230 -0
  63. package/src/browser-electron/extension-setup.ts +67 -0
  64. package/src/browser-electron/file-write.ts +31 -0
  65. package/src/browser-electron/foreground-watch.ts +142 -0
  66. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  67. package/src/browser-electron/guest-cookie-store.ts +59 -0
  68. package/src/browser-electron/guest-css-runtime.ts +76 -0
  69. package/src/browser-electron/guest-css.ts +68 -0
  70. package/src/browser-electron/guest-route.ts +716 -0
  71. package/src/browser-electron/guest-runtime.ts +408 -0
  72. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  73. package/src/browser-electron/guest-storage.ts +120 -0
  74. package/src/browser-electron/history-store.ts +224 -0
  75. package/src/browser-electron/host-main.ts +1385 -0
  76. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  77. package/src/browser-electron/http-body.ts +65 -0
  78. package/src/browser-electron/json-reply.ts +47 -0
  79. package/src/browser-electron/maintenance-broker.ts +166 -0
  80. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  81. package/src/browser-electron/maintenance-route.ts +68 -0
  82. package/src/browser-electron/missing-system-browser.ts +114 -0
  83. package/src/browser-electron/open-slot.ts +49 -0
  84. package/src/browser-electron/paths.ts +25 -0
  85. package/src/browser-electron/preferred-browser.ts +130 -0
  86. package/src/browser-electron/preview-route.ts +215 -0
  87. package/src/browser-electron/process-ownership.ts +174 -0
  88. package/src/browser-electron/process.ts +23 -0
  89. package/src/browser-electron/profile-checkpoint.ts +187 -0
  90. package/src/browser-electron/profile-command.ts +47 -0
  91. package/src/browser-electron/profile-extension.ts +129 -0
  92. package/src/browser-electron/profile-lease.ts +211 -0
  93. package/src/browser-electron/profile-residue.ts +49 -0
  94. package/src/browser-electron/provider-core.ts +1107 -0
  95. package/src/browser-electron/provider-interaction.ts +1034 -0
  96. package/src/browser-electron/provider-media.ts +589 -0
  97. package/src/browser-electron/provider-navigation.ts +323 -0
  98. package/src/browser-electron/provider-observation.ts +664 -0
  99. package/src/browser-electron/provider-tabs.ts +372 -0
  100. package/src/browser-electron/provider.ts +666 -0
  101. package/src/browser-electron/reference-route.ts +598 -0
  102. package/src/browser-electron/remote-host.ts +1538 -0
  103. package/src/browser-electron/rpc-input.ts +13 -0
  104. package/src/browser-electron/rpc-ops.ts +41 -0
  105. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  106. package/src/browser-electron/runtime-route.ts +105 -0
  107. package/src/browser-electron/runtime-status.ts +309 -0
  108. package/src/browser-electron/settings-route.ts +64 -0
  109. package/src/browser-electron/settings-store.ts +593 -0
  110. package/src/browser-electron/shortcuts-route.ts +112 -0
  111. package/src/browser-electron/sidebar-only-host.ts +300 -0
  112. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  113. package/src/browser-electron/system-browser.ts +1850 -0
  114. package/src/browser-electron/tauri-host.ts +194 -0
  115. package/src/browser-electron/timing.ts +16 -0
  116. package/src/browser-electron/virtual-cursor.ts +162 -0
  117. package/src/browser-electron/windows-system.ts +24 -0
  118. package/src/browser-reference/delivery.ts +384 -0
  119. package/src/browser-reference/entry.ts +631 -0
  120. package/src/browser-reference/export.ts +339 -0
  121. package/src/browser-reference/import.ts +303 -0
  122. package/src/browser-reference/page-script.ts +1537 -0
  123. package/src/browser-reference/service.ts +1346 -0
  124. package/src/browser-reference/store.ts +172 -0
  125. package/src/browser-reference/text-quote.ts +219 -0
  126. package/src/browser-reference/types.ts +195 -0
  127. package/src/browser-reference/visible.ts +367 -0
  128. package/src/browser-reference/web-sources.ts +106 -0
  129. package/src/client/apply-guard.ts +22 -0
  130. package/src/client/browser/BrowserController.ts +693 -0
  131. package/src/client/browser/BrowserFrame.ts +78 -0
  132. package/src/client/browser/BrowserNavigation.ts +169 -0
  133. package/src/client/browser/BrowserPage.ts +23 -0
  134. package/src/client/browser/BrowserPersistence.ts +44 -0
  135. package/src/client/browser/IframeImpl.ts +182 -0
  136. package/src/client/browser/child-tabs.ts +14 -0
  137. package/src/client/browser/frame-history.ts +125 -0
  138. package/src/client/browser/frame-state.ts +27 -0
  139. package/src/client/browser/iframe-reference.ts +67 -0
  140. package/src/client/browser/initialization.ts +262 -0
  141. package/src/client/browser/omnibox.ts +243 -0
  142. package/src/client/browser/store.ts +38 -0
  143. package/src/client/browser/takeover-channel.ts +72 -0
  144. package/src/client/browser/url.ts +46 -0
  145. package/src/client/browser/web-reference-source.ts +56 -0
  146. package/src/client/css-modules.d.ts +4 -0
  147. package/src/client/definition.tsx +36 -0
  148. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  149. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  150. package/src/client/electron/NativeChildPresentation.ts +53 -0
  151. package/src/client/electron/NativeViewPage.ts +265 -0
  152. package/src/client/electron/pages.ts +23 -0
  153. package/src/client/electron/reference-overlay.ts +53 -0
  154. package/src/client/electron/workspace.ts +33 -0
  155. package/src/client/index.ts +333 -0
  156. package/src/client/locales.ts +860 -0
  157. package/src/client/pages.ts +28 -0
  158. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  159. package/src/client/reference/client/draft-reference.ts +167 -0
  160. package/src/client/reference/client/index.ts +7 -0
  161. package/src/client/reference/client/ordered-submission.ts +108 -0
  162. package/src/client/reference/client/pending-delivery.ts +216 -0
  163. package/src/client/reference/client/plugin.ts +208 -0
  164. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  165. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  166. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  167. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  168. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  169. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  170. package/src/client/reference/client/production/assembly.ts +447 -0
  171. package/src/client/reference/client/production/asset-store.ts +144 -0
  172. package/src/client/reference/client/production/availability.ts +72 -0
  173. package/src/client/reference/client/production/bytes.ts +36 -0
  174. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  175. package/src/client/reference/client/production/delivery-client.ts +211 -0
  176. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  177. package/src/client/reference/client/production/http-transport.ts +212 -0
  178. package/src/client/reference/client/production/production-submission.ts +70 -0
  179. package/src/client/reference/client/production/protocol.ts +234 -0
  180. package/src/client/reference/client/production/reference-card.ts +240 -0
  181. package/src/client/reference/client/production/reference-labels.ts +29 -0
  182. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  183. package/src/client/reference/client/production/reveal.ts +215 -0
  184. package/src/client/reference/client/production/runtime.ts +1056 -0
  185. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  186. package/src/client/reference/client/production/source-marker.ts +99 -0
  187. package/src/client/reference/client/production/source-opener.ts +55 -0
  188. package/src/client/reference/client/production/styles.ts +104 -0
  189. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  190. package/src/client/reference/client/reveal.ts +109 -0
  191. package/src/client/reference/client/scheme.ts +114 -0
  192. package/src/client/reference/client/session-schedule.ts +36 -0
  193. package/src/client/reference/client/types.ts +168 -0
  194. package/src/client/reference/css-modules.d.ts +4 -0
  195. package/src/client/reference/index.ts +11 -0
  196. package/src/client/reference-capture-owner.ts +162 -0
  197. package/src/client/reference-intents.ts +36 -0
  198. package/src/client/settings/index.ts +42 -0
  199. package/src/client/settings/mount-guard.ts +31 -0
  200. package/src/client/settings/panel.ts +2773 -0
  201. package/src/client/shortcut-open.ts +30 -0
  202. package/src/client/startpage/binding.ts +99 -0
  203. package/src/client/startpage/controller.ts +300 -0
  204. package/src/client/startpage/model.ts +279 -0
  205. package/src/client/view/Browser.module.css +751 -0
  206. package/src/client/view/BrowserBody.tsx +315 -0
  207. package/src/client/view/BrowserPresentation.ts +9 -0
  208. package/src/client/view/BrowserTitle.tsx +17 -0
  209. package/src/client/view/IframePresentation.ts +365 -0
  210. package/src/client/view/StartPage.tsx +598 -0
  211. package/src/client/view/TakeoverBanner.tsx +21 -0
  212. package/src/compat/host-features.ts +92 -0
  213. package/src/index.ts +110 -0
  214. package/src/reference-owner.ts +5 -0
  215. package/src/reference-page.ts +9 -0
  216. package/src/reference-source.ts +3 -0
  217. package/src/reference-text.ts +219 -0
  218. package/src/startpage-settings.ts +103 -0
  219. package/src/startpage.ts +71 -0
  220. package/src/takeover-protocol.ts +28 -0
  221. package/src/tool-browser/block-recovery.ts +85 -0
  222. package/src/tool-browser/code-tool.ts +555 -0
  223. package/src/tool-browser/code-worker.ts +725 -0
  224. package/src/tool-browser/element-fields.ts +167 -0
  225. package/src/tool-browser/errors.ts +40 -0
  226. package/src/tool-browser/index.ts +265 -0
  227. package/src/tool-browser/page-probe.ts +675 -0
  228. package/src/tool-browser/panel-page.ts +126 -0
  229. package/src/tool-browser/probe-client.ts +183 -0
  230. package/src/tool-browser/screenshot-annotations.ts +131 -0
  231. package/src/tool-browser/screenshot-image.ts +49 -0
  232. package/src/tool-browser/state.ts +375 -0
  233. package/src/tool-browser/takeover.ts +199 -0
  234. package/src/tool-browser/tools-debug.ts +806 -0
  235. package/src/tool-browser/tools-interaction.ts +956 -0
  236. package/src/tool-browser/tools-navigation.ts +786 -0
  237. package/src/tool-browser/tools-observation.ts +474 -0
  238. package/src/tool-browser/tools-reference.ts +294 -0
  239. package/src/types/electron-shim.d.ts +144 -0
  240. package/src/types.ts +85 -0
  241. package/src/web-guest.ts +35 -0
  242. package/tools/accept-desktop.mjs +148 -0
  243. package/dist/client.d.cts +0 -516
  244. package/dist/client.d.mts +0 -516
  245. package/dist/index.cjs +0 -92
  246. package/dist/index.d.mts +0 -2960
  247. package/dist/index.mjs +0 -24
  248. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  249. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  250. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  256. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  257. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  258. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  259. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  260. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  261. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  262. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  263. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  264. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  265. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  266. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  267. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  268. package/dsh-host-patch/sources/manifest.json +0 -218
  269. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  293. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  294. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  295. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  296. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  297. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  298. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  299. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  300. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  301. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  302. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  303. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  304. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  305. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,13 @@
1
+ import type { Socket } from 'node:net'
2
+ import { createInterface, type Interface } from 'node:readline'
3
+
4
+ /** Read RPC lines while keeping transport errors owned by the socket. */
5
+ export function createRpcLineReader(socket: Socket, onError: (error: Error) => void): Interface {
6
+ socket.on('error', onError)
7
+ const reader = createInterface({ input: socket })
8
+ // readline forwards input errors as its own 'error' event. The socket
9
+ // listener above already reports that same error; receive the forwarded
10
+ // event too so a transport failure does not become uncaughtException.
11
+ reader.on('error', () => {})
12
+ return reader
13
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The RPC operation vocabulary, in one place.
3
+ *
4
+ * The child (`host-main.ts`) switches on these names and the parent (`remote-host.ts`) sends
5
+ * them. Both spelled them out independently and nothing connected the two, so a rename on one
6
+ * side compiled fine and failed at run time as "unknown op" — and this pair has already
7
+ * produced one silent failure of that shape (`noteStartFailure`'s dedupe comparison, which was
8
+ * never true and meant a log line that never appeared).
9
+ *
10
+ * The lists are the source of truth for a test that reads both switch statements and asserts
11
+ * they agree, which is what makes a one-sided rename fail loudly instead of at run time.
12
+ */
13
+
14
+ /** Operations the parent asks the child to perform. */
15
+ export const RPC_OPS = [
16
+ 'ping',
17
+ 'createView',
18
+ 'destroyView',
19
+ 'showView',
20
+ 'groupView',
21
+ 'focus',
22
+ 'command',
23
+ 'capture',
24
+ 'download',
25
+ 'flushAuth',
26
+ 'restoreAuth',
27
+ 'navigate',
28
+ 'new-tab',
29
+ 'activate',
30
+ 'close',
31
+ 'back',
32
+ 'forward',
33
+ 'reload',
34
+ 'userActionError',
35
+ ] as const
36
+
37
+ /** Notifications the child sends the parent, which carry no reply. */
38
+ export const RPC_NOTIFICATIONS = ['userAction', 'viewClosed'] as const
39
+
40
+ /** One operation name. */
41
+ export type RpcOp = (typeof RPC_OPS)[number]
@@ -0,0 +1,38 @@
1
+ /** Versions reported by the running child, never inferred from an npm package or path. */
2
+ interface RuntimeVersions {
3
+ readonly electron?: string
4
+ readonly chrome?: string
5
+ readonly node?: string
6
+ }
7
+
8
+ /**
9
+ * Startup diagnostics only: an explicit runtime remains the user's choice.
10
+ * Keep this pure so availability checks never spawn Electron or download it.
11
+ */
12
+ export function electronRuntimeDiagnosticLines(
13
+ versions: RuntimeVersions,
14
+ stamp = new Date().toISOString(),
15
+ ): string[] {
16
+ const electron = versions.electron?.trim() || 'unknown'
17
+ const lines = [
18
+ `${stamp} runtime: electron=${electron} chromium=${versions.chrome?.trim() || 'unknown'} node=${versions.node?.trim() || 'unknown'}`,
19
+ ]
20
+ const parsed = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(electron)
21
+ const continuing = 'continuing with the selected runtime. Update its installation, or change/remove ELECTRON_PATH if that override selects it.'
22
+ if (parsed === null || Number(parsed[1]) !== 44) {
23
+ // Other maintained branches can be patched for the advisory below. An
24
+ // untested major is a compatibility warning, not a vulnerability claim.
25
+ lines.push(`${stamp} warning: Electron ${electron} is not verified for this plugin; expected stable Electron 44.x >=44.9.1; ${continuing}`)
26
+ return lines
27
+ }
28
+ const minor = Number(parsed[2])
29
+ const patch = Number(parsed[3])
30
+ const prerelease = parsed[4] !== undefined
31
+ // A prerelease of 44.9.1 sorts before the patched stable release.
32
+ if (minor < 9 || (minor === 9 && (patch < 1 || (patch === 1 && prerelease)))) {
33
+ lines.push(`${stamp} warning: Electron ${electron} is below the 44.x security minimum 44.9.1 (GHSA-jr5w-w6x2-84p9); ${continuing}`)
34
+ } else if (prerelease) {
35
+ lines.push(`${stamp} warning: Electron ${electron} is a prerelease and is not verified for this plugin; expected stable Electron 44.x >=44.9.1; ${continuing}`)
36
+ }
37
+ return lines
38
+ }
@@ -0,0 +1,105 @@
1
+ import { RUNTIME_STATUS_ROUTE, RUNTIME_PROVISION_ROUTE } from '../../assets/browser-policy.mjs'
2
+ /**
3
+ * The readiness endpoints the settings panel reads.
4
+ *
5
+ * The host authenticates both routes with its signed browser-session cookie. The read returns
6
+ * readiness, while a POST starts runtime preparation and also passes the settings write-origin
7
+ * checks.
8
+ *
9
+ * Both answer with the whole report rather than a delta: the panel replaces what it shows with what
10
+ * it is told, so a stale poll can never leave a wrong state on screen.
11
+ * @module dsh-browser/browser-electron/runtime-route
12
+ */
13
+ import type { IncomingMessage, ServerResponse } from 'node:http'
14
+ import type { ProvisionSnapshot } from './electron-provision.ts'
15
+ import { replyJson } from './json-reply.ts'
16
+ import { sameOrigin } from './settings-route.ts'
17
+ import type { RuntimeStatusReport } from './runtime-status.ts'
18
+
19
+ /** Where the panel reads readiness. */
20
+ export { RUNTIME_STATUS_ROUTE }
21
+
22
+ /**
23
+ * Where the panel asks for the bundled runtime.
24
+ *
25
+ * Non-blocking by design: it starts (or joins) the one background attempt and answers immediately
26
+ * with the state that attempt is in, which is `preparing`. A request that waited for the download
27
+ * would time out in the browser long before a slow network finished, and would hold a connection
28
+ * open for something the panel can poll instead.
29
+ */
30
+ export { RUNTIME_PROVISION_ROUTE }
31
+
32
+ /** What both handlers need. */
33
+ export interface RuntimeRouteDeps {
34
+ /** The current report; a cheap read, never a spawn. */
35
+ readonly report: () => RuntimeStatusReport | Promise<RuntimeStatusReport>
36
+ /**
37
+ * Start (or join) a provision and return the state it is in now.
38
+ *
39
+ * Must not throw: a failure belongs in the report as a 200 with a `failed` state, because a user
40
+ * looking at a panel needs to read the reason, not an HTTP status.
41
+ */
42
+ readonly provision: () => ProvisionSnapshot
43
+ }
44
+
45
+ /**
46
+ * Read readiness: `{ ok, runtime }`.
47
+ * @param request - the incoming request.
48
+ * @param response - the response to write.
49
+ * @param deps - the readers.
50
+ */
51
+ export async function handleRuntimeStatus(
52
+ request: IncomingMessage,
53
+ response: ServerResponse,
54
+ deps: RuntimeRouteDeps,
55
+ ): Promise<void> {
56
+ if (request.method !== 'GET') {
57
+ replyJson(response, 405, { error: 'method-not-allowed' })
58
+ return
59
+ }
60
+ if (!sameOrigin(request)) {
61
+ replyJson(response, 403, { error: 'not-same-origin' })
62
+ return
63
+ }
64
+ replyJson(response, 200, { ok: true, runtime: await deps.report() })
65
+ }
66
+
67
+ /**
68
+ * Start (or join) a provision, then answer with the state it is in.
69
+ *
70
+ * Always 200 once admitted, whatever happened: the state carries `failed` with its reason, and a
71
+ * panel that had to distinguish 4xx from 5xx to say "the download failed" would show a network
72
+ * error where the user needs the sentence explaining it.
73
+ * @param request - the incoming request.
74
+ * @param response - the response to write.
75
+ * @param deps - the readers.
76
+ */
77
+ export async function handleRuntimeProvision(
78
+ request: IncomingMessage,
79
+ response: ServerResponse,
80
+ deps: RuntimeRouteDeps,
81
+ ): Promise<void> {
82
+ if (request.method !== 'POST') {
83
+ replyJson(response, 405, { error: 'method-not-allowed' })
84
+ return
85
+ }
86
+ // `true`: starting a download is a write, and is admitted the way a settings write is.
87
+ if (!sameOrigin(request, true)) {
88
+ replyJson(response, 403, { error: 'not-same-origin' })
89
+ return
90
+ }
91
+ let snapshot: ProvisionSnapshot
92
+ try {
93
+ snapshot = deps.provision()
94
+ } catch (error) {
95
+ // `provision` is documented not to throw; if a caller breaks that contract the panel still gets
96
+ // an answer it can render, rather than a dropped connection it cannot tell from a hang.
97
+ replyJson(response, 200, {
98
+ ok: true,
99
+ runtime: await deps.report(),
100
+ provisionError: String(error),
101
+ })
102
+ return
103
+ }
104
+ replyJson(response, 200, { ok: true, runtime: await deps.report(), provision: snapshot })
105
+ }
@@ -0,0 +1,309 @@
1
+ /**
2
+ * One answer to "can I use the browser right now", assembled from the three things that decide it.
3
+ *
4
+ * WHY THIS EXISTS
5
+ * Installing this plugin made the browser work with no setup, and that property got silently
6
+ * weaker as the carriers were added: the standalone Electron runtime downloads on first need
7
+ * (issue #41 — the download had to leave `postinstall`), so on a fresh install the first browser
8
+ * call can arrive before or while that download is running, and the only trace anywhere in the
9
+ * product was a log line the settings panel cannot read. A user who saw "cannot locate a spawnable
10
+ * Electron binary" had no way to learn that they could prepare it from the panel, and no button to
11
+ * retry it once it failed.
12
+ *
13
+ * So the readiness of each part is computed ONCE here, in a pure function over injectable readers:
14
+ * the settings panel renders it, and a test drives it without touching Electron, a desktop install
15
+ * or the file system.
16
+ *
17
+ * Everything here is a cheap environment check. The launch path's own binary probes resolve the
18
+ * bundled/managed runtime and installed system browsers; bridge readers inspect the installation
19
+ * and its published endpoint. Available files establish availability, while browser calls establish
20
+ * whether a particular page can be driven. Nothing spawns anything.
21
+ * @module dsh-browser/browser-electron/runtime-status
22
+ */
23
+ import type { BridgeStatus } from './bridge-status.ts'
24
+ import type { DesktopShellReport } from './desktop-shell.ts'
25
+ import type { BridgeEndpointState } from './bridge-endpoint.ts'
26
+ import type { ProvisionSnapshot } from './electron-provision.ts'
27
+ import type { ExtensionConnectionStatus } from '../../native-host/client.mjs'
28
+ import type { extensionInstallHelp } from './extension-browser.ts'
29
+ import { createRequire } from 'node:module'
30
+ import { detectBrowser, type BrowserChannel, type DetectedBrowser, type SystemBrowserLaunchDiagnostic } from './system-browser.ts'
31
+
32
+ /** This plugin's own resolver, used when a caller does not inject one. */
33
+ const pluginRequire = createRequire(import.meta.url)
34
+
35
+ /** The host peers this plugin imports; read from the manifest so the list cannot drift. */
36
+ const HOST_PEERS: readonly string[] = (() => {
37
+ try {
38
+ const manifest = pluginRequire('../../package.json') as { peerDependencies?: Record<string, string> }
39
+ return Object.freeze(Object.keys(manifest.peerDependencies ?? {}))
40
+ } catch { return Object.freeze([] as string[]) }
41
+ })()
42
+
43
+ /** The part of the carrier the channel names, in the terms the panel has to explain. */
44
+ export type CarrierKind = 'sidebar' | 'bundled' | 'system' | 'extension' | 'cdp' | 'auto'
45
+
46
+ /** Whether the chosen carrier's required files or running bridge are available. */
47
+ export type Readiness = 'ready' | 'blocked'
48
+
49
+ /** The system-browser discovery result, obtained without launching an executable. */
50
+ export interface SystemBrowserReadiness {
51
+ readonly launch?: SystemBrowserLaunchDiagnostic
52
+ /** False for channels that use the sidebar or bundled runtime directly. */
53
+ readonly checked: boolean
54
+ readonly present: boolean
55
+ readonly kind?: DetectedBrowser['kind']
56
+ readonly path?: string
57
+ /** What was found or which configured product is missing. */
58
+ readonly detail: string
59
+ }
60
+
61
+ /** The Electron runtime's state, as the panel needs it. */
62
+ export interface ElectronReadiness {
63
+ /** `present` — a launch would find a binary; `preparing` — a download is running now; and so on. */
64
+ readonly state: ProvisionSnapshot['state']
65
+ /** One line, already user-facing: the provisioning module's own words. */
66
+ readonly detail: string
67
+ /** When that state was reached, ISO. */
68
+ readonly at: string
69
+ }
70
+
71
+ /** The desktop sidebar bridge, or the honest "there is no desktop here" shape. */
72
+ export interface BridgeReadiness {
73
+ readonly mainExtension?: BridgeStatus['mainExtension']
74
+ readonly code?: string
75
+ /** Whether a DSH Desktop install was found at all. */
76
+ readonly present: boolean
77
+ /** `absent` is reported separately from `missing`: nothing to repair versus something to repair. */
78
+ readonly state: BridgeStatus['state'] | 'absent'
79
+ /** The plugin's own words about the install tree. */
80
+ readonly detail: string
81
+ /**
82
+ * Whether a shell is RUNNING and answering, as opposed to merely installed.
83
+ *
84
+ * Install-tree state survives a reboot and says nothing about a process; the published endpoint is
85
+ * the only thing that does. Reporting "installed" as "ready" is how a panel goes green while every
86
+ * call dials a port nobody owns — the desktop app being closed is the most common broken state
87
+ * there is.
88
+ */
89
+ readonly running: boolean
90
+ /** The plugin's own words about the running shell (or about why there is none). */
91
+ readonly runningDetail: string
92
+ /** The command that installs or repairs it, for a human to run. Never run by the plugin. */
93
+ readonly command?: string
94
+ }
95
+
96
+ /** The whole report. */
97
+ export interface RuntimeStatusReport {
98
+ readonly nativeHostRegistration?: Record<string, { registered: boolean; detail: string }>
99
+ readonly controlledProfile: 'plugin' | 'user' | 'sidebar'
100
+ readonly extension?: ExtensionConnectionStatus & { readonly install?: ReturnType<typeof extensionInstallHelp>; readonly registration?: { registered: boolean; detail: string } }
101
+ readonly fallbackReason?: string
102
+ /** What the settings document says, verbatim: the panel shows the switch it is honouring. */
103
+ readonly channel: BrowserChannel
104
+ /** What that channel resolves to, in panel terms. */
105
+ readonly carrier: CarrierKind
106
+ /** The concrete carrier selected by the same discovery priority as the browser provider. */
107
+ readonly resolvedCarrier: Exclude<CarrierKind, 'auto'>
108
+ /** Whether the carrier's environment requirements are available. */
109
+ readonly readiness: Readiness
110
+ readonly systemBrowser: SystemBrowserReadiness
111
+ /** The system executable selected for the resolved carrier, when applicable. */
112
+ readonly executable?: string
113
+ readonly electron: ElectronReadiness
114
+ readonly bridge: BridgeReadiness
115
+ /** The desktop shell found on this machine; only a patchable one gets bridge install / repair. */
116
+ readonly shell?: DesktopShellReport
117
+ /** Whether "Prepare the bundled browser" is worth offering (it is not while one is running). */
118
+ readonly canProvision: boolean
119
+ /**
120
+ * Whether each host peer (`@deepseek-ai/*`) resolves from this plugin (issue #59). A Desktop app
121
+ * that ships the plugin without its peers makes the plugin's own imports fail at the first use,
122
+ * and the four entries simply stay inactive; this turns that into a named list the diagnostics
123
+ * block can show and a reporter can paste.
124
+ */
125
+ readonly peers?: readonly PeerResolution[]
126
+ /** Why the carrier was adopted, newest last (issue #106). */
127
+ readonly carrierHistory?: readonly string[]
128
+ }
129
+
130
+ /** One host peer's resolution result. */
131
+ export interface PeerResolution {
132
+ readonly name: string
133
+ readonly resolved: boolean
134
+ /** The resolver's own words when it failed. */
135
+ readonly error?: string
136
+ }
137
+
138
+ /** Everything the report reads, so a test can answer without any of the real machinery. */
139
+ export interface RuntimeStatusDeps {
140
+ readonly nativeHostRegistration?: () => NonNullable<RuntimeStatusReport['nativeHostRegistration']>
141
+ readonly fallbackReason?: () => string | undefined
142
+ readonly systemProfile?: () => 'user' | 'plugin'
143
+ readonly extensionConnection?: () => RuntimeStatusReport['extension']
144
+ /** The stored `browser.channel`. */
145
+ readonly channel: () => BrowserChannel
146
+ /** Whether a launch would find an Electron binary — the launch path's own probe. */
147
+ readonly hasBinary: () => boolean
148
+ /** The provisioning state machine's current state. */
149
+ readonly provision: () => ProvisionSnapshot
150
+ /** The desktop install's bridge state, or undefined when there is no desktop install. */
151
+ readonly bridge: () => BridgeStatus | undefined
152
+ readonly bridgeError?: () => string | undefined
153
+ /** The desktop shell classification; omitted by hosts that only report the bridge. */
154
+ readonly shell?: () => DesktopShellReport
155
+ /** The endpoint the shell publishes while it runs; undefined when nothing published one. */
156
+ readonly endpoint: () => BridgeEndpointState | undefined
157
+ /** The launch path's filesystem-only browser discovery; defaults to the production reader. */
158
+ readonly detectBrowser?: (channel: BrowserChannel) => DetectedBrowser | undefined
159
+ /** The provider's current carrier, including a fallback selected after sidebar loss. */
160
+ readonly selectedCarrier?: () => Exclude<CarrierKind, 'auto'> | undefined
161
+ readonly systemConnection?: () => { connected: boolean; detail: string; launch?: SystemBrowserLaunchDiagnostic } | undefined
162
+ /** Resolve one host peer; defaults to this plugin's own `require.resolve` (issue #59). */
163
+ readonly resolvePeer?: (name: string) => string
164
+ /** The last carrier decisions, newest last (issue #106). */
165
+ readonly carrierHistory?: () => readonly string[]
166
+ }
167
+
168
+ /** Which carrier a channel names. */
169
+ function carrierOf(channel: BrowserChannel): CarrierKind {
170
+ if (channel === 'chrome' || channel === 'edge') return 'system'
171
+ if (channel === 'electron') return 'bundled'
172
+ return 'sidebar'
173
+ }
174
+
175
+ /**
176
+ * Assemble the report.
177
+ *
178
+ * The `readiness` field is per carrier on purpose: "the browser is ready" is not a property of this
179
+ * plugin, it is a property of the carrier the user chose. A standalone Electron carrier with a
180
+ * finished download is ready; the sidebar carrier with no bridge is not, however healthy the
181
+ * Electron runtime is.
182
+ * @param deps - the readers; every one of them is a cheap, side-effect-free read.
183
+ * @returns the report the panel renders.
184
+ */
185
+ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport {
186
+ const channel = deps.channel()
187
+ const preferExtension = (channel === 'edge' || channel === 'chrome') && deps.systemProfile?.() === 'user'
188
+ const carrier = preferExtension ? 'extension' : carrierOf(channel)
189
+ const extension = carrier === 'extension' ? deps.extensionConnection?.() ?? {
190
+ state: 'extension-missing' as const, connected: false, browser: channel as 'edge' | 'chrome', detail: 'Optional extension is not connected; managed CDP is available as fallback.',
191
+ } : undefined
192
+
193
+ // The binary check comes first and wins: a runtime that is on disk is ready whatever the
194
+ // provisioning state machine last said, which is also how a runtime installed by hand (or by an
195
+ // earlier process) is reported correctly without a restart. The DETAIL has to follow the same
196
+ // rule, or the panel shows "present" next to "the runtime has not been asked for yet" — measured
197
+ // on a live install, and the kind of contradiction a reader cannot resolve.
198
+ const snapshot = deps.provision()
199
+ const runnable = deps.hasBinary()
200
+ const missingAfterReady = !runnable && (snapshot.state === 'present' || snapshot.state === 'ready')
201
+ const state: ElectronReadiness['state'] = runnable ? 'present' : missingAfterReady ? 'failed' : snapshot.state
202
+ const electron: ElectronReadiness = {
203
+ state,
204
+ detail: runnable ? 'an Electron runtime is already available'
205
+ : missingAfterReady ? 'the previously prepared Electron runtime is missing; prepare it again' : snapshot.detail,
206
+ at: runnable ? new Date().toISOString() : snapshot.at,
207
+ }
208
+
209
+ const bridgeStatus = deps.bridge()
210
+ const endpoint = deps.endpoint()
211
+ const installedBridge: BridgeReadiness = bridgeStatus === undefined
212
+ ? {
213
+ present: false,
214
+ state: 'absent',
215
+ detail: 'no DSH Desktop install was found on this machine',
216
+ running: endpoint?.alive === true,
217
+ runningDetail: endpoint?.detail ?? 'no desktop shell has published a bridge endpoint',
218
+ }
219
+ : {
220
+ present: bridgeStatus.present,
221
+ state: bridgeStatus.state,
222
+ detail: bridgeStatus.detail,
223
+ running: endpoint?.alive === true,
224
+ runningDetail: endpoint?.detail ?? 'no desktop shell has published a bridge endpoint',
225
+ ...bridgeStatus.command === undefined ? {} : { command: bridgeStatus.command },
226
+ ...bridgeStatus.mainExtension === undefined ? {} : { mainExtension: bridgeStatus.mainExtension },
227
+ ...bridgeStatus.code === undefined ? {} : { code: bridgeStatus.code },
228
+ }
229
+
230
+ const bridgeError = deps.bridgeError?.()
231
+ const bridge: BridgeReadiness = bridgeError === undefined ? installedBridge
232
+ : { ...installedBridge, state: 'stale', detail: bridgeError }
233
+
234
+ // The sidebar needs BOTH halves: our patch inside the shell it will be driven through, and that
235
+ // shell actually running. Either one alone is the false green this report exists to prevent.
236
+ // On DSH Tauri the patch is the host patch, which starts the same bridge inside electron-rs.
237
+ const shell = deps.shell?.()
238
+ const sidebarReady = bridge.running && (bridge.state === 'installed'
239
+ || (shell?.kind === 'tauri' && shell.running === true && shell.hostPatch?.status === 'applied'))
240
+
241
+ const selected = preferExtension ? deps.selectedCarrier?.() ?? (extension?.connected ? 'extension' : 'cdp') : undefined
242
+ const checkSystemBrowser = carrier === 'system' || selected === 'cdp'
243
+ const detected = checkSystemBrowser ? (deps.detectBrowser ?? detectBrowser)(channel) : undefined
244
+ const connection = checkSystemBrowser ? deps.systemConnection?.() : undefined
245
+ const systemBrowser: SystemBrowserReadiness = {
246
+ ...connection?.launch === undefined ? {} : { launch: connection.launch },
247
+ checked: checkSystemBrowser,
248
+ present: detected !== undefined,
249
+ ...detected === undefined ? {} : { kind: detected.kind, path: detected.path },
250
+ detail: detected !== undefined ? connection?.detail ?? 'Browser has not launched; run a browser command to establish CDP. No live CDP connection.'
251
+ : !checkSystemBrowser ? `the ${carrier} channel uses its own carrier`
252
+ : `the selected ${channel} installation was not found`,
253
+ }
254
+
255
+ let readiness: Readiness
256
+ let resolvedCarrier: RuntimeStatusReport['resolvedCarrier']
257
+ if (carrier === 'sidebar') {
258
+ resolvedCarrier = 'sidebar'
259
+ readiness = sidebarReady ? 'ready' : 'blocked'
260
+ } else if (carrier === 'bundled') {
261
+ resolvedCarrier = 'bundled'
262
+ readiness = runnable ? 'ready' : 'blocked'
263
+ } else if (selected === 'cdp') {
264
+ resolvedCarrier = 'cdp'
265
+ readiness = detected !== undefined && connection?.connected === true ? 'ready' : 'blocked'
266
+ } else if (carrier === 'extension') {
267
+ resolvedCarrier = 'extension'
268
+ readiness = extension?.state === 'connected' && extension.connected ? 'ready' : 'blocked'
269
+ } else {
270
+ resolvedCarrier = 'system'
271
+ readiness = detected !== undefined && connection?.connected === true ? 'ready' : 'blocked'
272
+ }
273
+
274
+ return {
275
+ ...deps.nativeHostRegistration ? { nativeHostRegistration: deps.nativeHostRegistration() } : {},
276
+ controlledProfile: resolvedCarrier === 'extension' ? 'user' : resolvedCarrier === 'system' || resolvedCarrier === 'cdp' || resolvedCarrier === 'bundled' ? 'plugin' : 'sidebar',
277
+ ...(preferExtension && resolvedCarrier === 'cdp' ? { fallbackReason: deps.fallbackReason?.() ?? (extension?.state === 'disabled' ? 'disabled' : 'not-connected') } : {}),
278
+ ...extension === undefined ? {} : { extension },
279
+ channel,
280
+ carrier,
281
+ resolvedCarrier,
282
+ readiness,
283
+ systemBrowser,
284
+ ...resolvedCarrier === 'system' && detected !== undefined ? { executable: detected.path } : {},
285
+ electron,
286
+ bridge,
287
+ ...shell === undefined ? {} : { shell },
288
+ canProvision: resolvedCarrier === 'bundled' && !runnable && snapshot.state !== 'preparing',
289
+ ...peerReport(deps.resolvePeer),
290
+ ...deps.carrierHistory === undefined ? {} : { carrierHistory: deps.carrierHistory() },
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Resolve every host peer and report the failures (#59). Never throws: an unresolvable peer is a
296
+ * fact to display, not a reason to break the readiness report that needs it.
297
+ * @param resolve - the resolver to use; defaults to this plugin's own.
298
+ * @returns the report field, empty when the manifest declared no peers.
299
+ */
300
+ function peerReport(resolve?: (name: string) => string): { peers: PeerResolution[] } | Record<string, never> {
301
+ if (HOST_PEERS.length === 0) return {}
302
+ const lookup = resolve ?? ((name: string) => pluginRequire.resolve(name))
303
+ return {
304
+ peers: HOST_PEERS.map(name => {
305
+ try { lookup(name); return { name, resolved: true } }
306
+ catch (error) { return { name, resolved: false, error: error instanceof Error ? error.message : String(error) } }
307
+ }),
308
+ }
309
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Browser-origin checks used after DSH authenticates each plugin HTTP request.
3
+ * Desktop protocol forwarding supplies the host session cookie while Chromium may omit Origin
4
+ * and Referer for the custom application scheme. These checks preserve that request shape and
5
+ * reject browser requests that explicitly name another web origin.
6
+ * @module dsh-browser/browser-electron/settings-route
7
+ */
8
+ import type { IncomingMessage } from 'node:http'
9
+
10
+ /** The shell's own URL schemes. Only the shell can mint a document on one of these. */
11
+ const APP_SCHEMES = ['dsh-app:', 'dsh-desktop:']
12
+
13
+ /**
14
+ * The scheme of a header value, when it names a URL.
15
+ * @param value - a raw header value.
16
+ * @returns the scheme, or undefined when the value is absent, opaque or unparseable.
17
+ */
18
+ function schemeOf(value: string): string | undefined {
19
+ if (value === '' || value === 'null') return undefined
20
+ try {
21
+ return new URL(value).protocol
22
+ } catch {
23
+ return undefined
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Whether a request may touch the settings document.
29
+ * @param request - the incoming request.
30
+ * @param writing - true for PUT/POST, which is held to the stricter rule.
31
+ * @returns whether the request is admitted.
32
+ */
33
+ export function sameOrigin(request: IncomingMessage, writing = false): boolean {
34
+ const origin = String(request.headers.origin ?? '').trim()
35
+ const site = String(request.headers['sec-fetch-site'] ?? '').toLowerCase()
36
+
37
+ // A shell URL, in either the Origin or the referrer: the strongest evidence there is.
38
+ if (APP_SCHEMES.includes(schemeOf(origin) ?? '')) return true
39
+ if (APP_SCHEMES.includes(schemeOf(String(request.headers.referer ?? '')) ?? '')) return true
40
+
41
+ // Desktop custom-scheme requests can omit browser origin metadata. The route's host-cookie
42
+ // gate has already authenticated them; the renderer headers retain compatibility with older
43
+ // shells that omit Origin while forwarding settings writes.
44
+ if (origin === '') {
45
+ const agent = String(request.headers['user-agent'] ?? '')
46
+ const language = String(request.headers['accept-language'] ?? '')
47
+ if (/^Mozilla\/5\.0/.test(agent) && language !== '') return true
48
+ // A missing Origin is valid for reads after the host-cookie gate has admitted the caller.
49
+ return !writing
50
+ }
51
+
52
+ // `cross-site` is another origin entirely; `same-site` is another origin of the same site
53
+ // (a.example.com -> b.example.com), which is not this panel either. Both are refused.
54
+ if (site === 'cross-site' || site === 'same-site') return false
55
+ // `Origin: null` is a sandboxed or opaque-origin document. Never this panel.
56
+ if (origin === 'null') return false
57
+ try {
58
+ const parsed = new URL(origin)
59
+ // The host comparison is for http(s), where a page and its route share one host.
60
+ return parsed.host.toLowerCase() === String(request.headers.host ?? '').trim().toLowerCase()
61
+ } catch {
62
+ return false
63
+ }
64
+ }