dsh-builtin-browser 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/README.en.md +89 -0
  2. package/browser-extension/constants.mjs +20 -0
  3. package/browser-extension/controller.mjs +293 -0
  4. package/browser-extension/locales.mjs +15 -0
  5. package/browser-extension/manifest.json +12 -0
  6. package/browser-extension/options.html +14 -0
  7. package/browser-extension/options.mjs +9 -0
  8. package/browser-extension/permission-guard.mjs +13 -0
  9. package/browser-extension/worker.mjs +74 -0
  10. package/package.json +20 -2
  11. package/scripts/build-client.mjs +305 -0
  12. package/scripts/build.mjs +69 -0
  13. package/scripts/bundle-host.mjs +28 -0
  14. package/scripts/fix-exports.mjs +40 -0
  15. package/scripts/install-electron.mjs +101 -0
  16. package/scripts/pack.mjs +99 -0
  17. package/scripts/publish-manifest.mjs +56 -0
  18. package/scripts/verify-exports.mjs +58 -0
  19. package/scripts/verify-preview-sdk.mjs +93 -0
  20. package/skills/dsh-builtin-browser/SKILL.md +98 -0
  21. package/skills/dsh-builtin-browser/references/batch.md +68 -0
  22. package/skills/dsh-builtin-browser/references/deliver.md +31 -0
  23. package/skills/dsh-builtin-browser/references/locate.md +11 -0
  24. package/skills/dsh-builtin-browser/references/recover.md +11 -0
  25. package/skills/dsh-builtin-browser/references/verify.md +13 -0
  26. package/skills/dsh-debug-host/SKILL.md +56 -0
  27. package/skills/dsh-debug-self/SKILL.md +50 -0
  28. package/src/bridge-compatibility.ts +39 -0
  29. package/src/browser/anti-bot.ts +251 -0
  30. package/src/browser/deep-dom.ts +40 -0
  31. package/src/browser/handles.ts +89 -0
  32. package/src/browser/runtime.ts +578 -0
  33. package/src/browser/takeover-target.ts +45 -0
  34. package/src/browser/types.ts +870 -0
  35. package/src/browser-electron/authenticated-route.ts +109 -0
  36. package/src/browser-electron/automatic-maintenance.ts +736 -0
  37. package/src/browser-electron/bridge-auto.ts +159 -0
  38. package/src/browser-electron/bridge-connection.ts +386 -0
  39. package/src/browser-electron/bridge-endpoint.ts +129 -0
  40. package/src/browser-electron/bridge-install.ts +290 -0
  41. package/src/browser-electron/bridge-maintenance.ts +189 -0
  42. package/src/browser-electron/bridge-status.ts +386 -0
  43. package/src/browser-electron/desktop-bridge-host.ts +253 -0
  44. package/src/browser-electron/desktop-identity.ts +353 -0
  45. package/src/browser-electron/desktop-shell.ts +100 -0
  46. package/src/browser-electron/document-readiness.ts +45 -0
  47. package/src/browser-electron/electron-provision.ts +347 -0
  48. package/src/browser-electron/entry.ts +1378 -0
  49. package/src/browser-electron/ephemeral-profile.ts +189 -0
  50. package/src/browser-electron/extension-browser.ts +230 -0
  51. package/src/browser-electron/extension-setup.ts +67 -0
  52. package/src/browser-electron/file-write.ts +31 -0
  53. package/src/browser-electron/foreground-watch.ts +142 -0
  54. package/src/browser-electron/guest-cookie-jar.ts +177 -0
  55. package/src/browser-electron/guest-cookie-store.ts +59 -0
  56. package/src/browser-electron/guest-css-runtime.ts +76 -0
  57. package/src/browser-electron/guest-css.ts +68 -0
  58. package/src/browser-electron/guest-route.ts +716 -0
  59. package/src/browser-electron/guest-runtime.ts +408 -0
  60. package/src/browser-electron/guest-storage-runtime.ts +54 -0
  61. package/src/browser-electron/guest-storage.ts +120 -0
  62. package/src/browser-electron/history-store.ts +224 -0
  63. package/src/browser-electron/host-main.ts +1385 -0
  64. package/src/browser-electron/host-patch-maintenance.ts +121 -0
  65. package/src/browser-electron/http-body.ts +65 -0
  66. package/src/browser-electron/json-reply.ts +47 -0
  67. package/src/browser-electron/maintenance-broker.ts +166 -0
  68. package/src/browser-electron/maintenance-lifecycle.ts +91 -0
  69. package/src/browser-electron/maintenance-route.ts +68 -0
  70. package/src/browser-electron/missing-system-browser.ts +114 -0
  71. package/src/browser-electron/open-slot.ts +49 -0
  72. package/src/browser-electron/paths.ts +25 -0
  73. package/src/browser-electron/preferred-browser.ts +130 -0
  74. package/src/browser-electron/preview-route.ts +215 -0
  75. package/src/browser-electron/process-ownership.ts +174 -0
  76. package/src/browser-electron/process.ts +23 -0
  77. package/src/browser-electron/profile-checkpoint.ts +187 -0
  78. package/src/browser-electron/profile-command.ts +47 -0
  79. package/src/browser-electron/profile-extension.ts +129 -0
  80. package/src/browser-electron/profile-lease.ts +211 -0
  81. package/src/browser-electron/profile-residue.ts +49 -0
  82. package/src/browser-electron/provider-core.ts +1107 -0
  83. package/src/browser-electron/provider-interaction.ts +1034 -0
  84. package/src/browser-electron/provider-media.ts +589 -0
  85. package/src/browser-electron/provider-navigation.ts +323 -0
  86. package/src/browser-electron/provider-observation.ts +664 -0
  87. package/src/browser-electron/provider-tabs.ts +372 -0
  88. package/src/browser-electron/provider.ts +666 -0
  89. package/src/browser-electron/reference-route.ts +598 -0
  90. package/src/browser-electron/remote-host.ts +1538 -0
  91. package/src/browser-electron/rpc-input.ts +13 -0
  92. package/src/browser-electron/rpc-ops.ts +41 -0
  93. package/src/browser-electron/runtime-diagnostics.ts +38 -0
  94. package/src/browser-electron/runtime-route.ts +105 -0
  95. package/src/browser-electron/runtime-status.ts +309 -0
  96. package/src/browser-electron/settings-route.ts +64 -0
  97. package/src/browser-electron/settings-store.ts +593 -0
  98. package/src/browser-electron/shortcuts-route.ts +112 -0
  99. package/src/browser-electron/sidebar-only-host.ts +300 -0
  100. package/src/browser-electron/startpage-shortcuts.ts +213 -0
  101. package/src/browser-electron/system-browser.ts +1850 -0
  102. package/src/browser-electron/tauri-host.ts +194 -0
  103. package/src/browser-electron/timing.ts +16 -0
  104. package/src/browser-electron/virtual-cursor.ts +162 -0
  105. package/src/browser-electron/windows-system.ts +24 -0
  106. package/src/browser-reference/delivery.ts +384 -0
  107. package/src/browser-reference/entry.ts +631 -0
  108. package/src/browser-reference/export.ts +339 -0
  109. package/src/browser-reference/import.ts +303 -0
  110. package/src/browser-reference/page-script.ts +1537 -0
  111. package/src/browser-reference/service.ts +1346 -0
  112. package/src/browser-reference/store.ts +172 -0
  113. package/src/browser-reference/text-quote.ts +219 -0
  114. package/src/browser-reference/types.ts +195 -0
  115. package/src/browser-reference/visible.ts +367 -0
  116. package/src/browser-reference/web-sources.ts +106 -0
  117. package/src/client/apply-guard.ts +22 -0
  118. package/src/client/browser/BrowserController.ts +693 -0
  119. package/src/client/browser/BrowserFrame.ts +78 -0
  120. package/src/client/browser/BrowserNavigation.ts +169 -0
  121. package/src/client/browser/BrowserPage.ts +23 -0
  122. package/src/client/browser/BrowserPersistence.ts +44 -0
  123. package/src/client/browser/IframeImpl.ts +182 -0
  124. package/src/client/browser/child-tabs.ts +14 -0
  125. package/src/client/browser/frame-history.ts +125 -0
  126. package/src/client/browser/frame-state.ts +27 -0
  127. package/src/client/browser/iframe-reference.ts +67 -0
  128. package/src/client/browser/initialization.ts +262 -0
  129. package/src/client/browser/omnibox.ts +243 -0
  130. package/src/client/browser/store.ts +38 -0
  131. package/src/client/browser/takeover-channel.ts +72 -0
  132. package/src/client/browser/url.ts +46 -0
  133. package/src/client/browser/web-reference-source.ts +56 -0
  134. package/src/client/css-modules.d.ts +4 -0
  135. package/src/client/definition.tsx +36 -0
  136. package/src/client/electron/ElectronWebViewImpl.ts +371 -0
  137. package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
  138. package/src/client/electron/NativeChildPresentation.ts +53 -0
  139. package/src/client/electron/NativeViewPage.ts +265 -0
  140. package/src/client/electron/pages.ts +23 -0
  141. package/src/client/electron/reference-overlay.ts +53 -0
  142. package/src/client/electron/workspace.ts +33 -0
  143. package/src/client/index.ts +333 -0
  144. package/src/client/locales.ts +860 -0
  145. package/src/client/pages.ts +28 -0
  146. package/src/client/reference/client/BrowserRefLink.tsx +142 -0
  147. package/src/client/reference/client/draft-reference.ts +167 -0
  148. package/src/client/reference/client/index.ts +7 -0
  149. package/src/client/reference/client/ordered-submission.ts +108 -0
  150. package/src/client/reference/client/pending-delivery.ts +216 -0
  151. package/src/client/reference/client/plugin.ts +208 -0
  152. package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
  153. package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
  154. package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
  155. package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
  156. package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
  157. package/src/client/reference/client/production/ReferenceText.tsx +36 -0
  158. package/src/client/reference/client/production/assembly.ts +447 -0
  159. package/src/client/reference/client/production/asset-store.ts +144 -0
  160. package/src/client/reference/client/production/availability.ts +72 -0
  161. package/src/client/reference/client/production/bytes.ts +36 -0
  162. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  163. package/src/client/reference/client/production/delivery-client.ts +211 -0
  164. package/src/client/reference/client/production/draft-adapter.ts +512 -0
  165. package/src/client/reference/client/production/http-transport.ts +212 -0
  166. package/src/client/reference/client/production/production-submission.ts +70 -0
  167. package/src/client/reference/client/production/protocol.ts +234 -0
  168. package/src/client/reference/client/production/reference-card.ts +240 -0
  169. package/src/client/reference/client/production/reference-labels.ts +29 -0
  170. package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
  171. package/src/client/reference/client/production/reveal.ts +215 -0
  172. package/src/client/reference/client/production/runtime.ts +1056 -0
  173. package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
  174. package/src/client/reference/client/production/source-marker.ts +99 -0
  175. package/src/client/reference/client/production/source-opener.ts +55 -0
  176. package/src/client/reference/client/production/styles.ts +104 -0
  177. package/src/client/reference/client/production/user-text-rule.ts +67 -0
  178. package/src/client/reference/client/reveal.ts +109 -0
  179. package/src/client/reference/client/scheme.ts +114 -0
  180. package/src/client/reference/client/session-schedule.ts +36 -0
  181. package/src/client/reference/client/types.ts +168 -0
  182. package/src/client/reference/css-modules.d.ts +4 -0
  183. package/src/client/reference/index.ts +11 -0
  184. package/src/client/reference-capture-owner.ts +162 -0
  185. package/src/client/reference-intents.ts +36 -0
  186. package/src/client/settings/index.ts +42 -0
  187. package/src/client/settings/mount-guard.ts +31 -0
  188. package/src/client/settings/panel.ts +2768 -0
  189. package/src/client/shortcut-open.ts +30 -0
  190. package/src/client/startpage/binding.ts +99 -0
  191. package/src/client/startpage/controller.ts +300 -0
  192. package/src/client/startpage/model.ts +279 -0
  193. package/src/client/view/Browser.module.css +751 -0
  194. package/src/client/view/BrowserBody.tsx +315 -0
  195. package/src/client/view/BrowserPresentation.ts +9 -0
  196. package/src/client/view/BrowserTitle.tsx +17 -0
  197. package/src/client/view/IframePresentation.ts +365 -0
  198. package/src/client/view/StartPage.tsx +598 -0
  199. package/src/client/view/TakeoverBanner.tsx +21 -0
  200. package/src/compat/host-features.ts +92 -0
  201. package/src/index.ts +110 -0
  202. package/src/reference-owner.ts +5 -0
  203. package/src/reference-page.ts +9 -0
  204. package/src/reference-source.ts +3 -0
  205. package/src/reference-text.ts +219 -0
  206. package/src/startpage-settings.ts +103 -0
  207. package/src/startpage.ts +71 -0
  208. package/src/takeover-protocol.ts +28 -0
  209. package/src/tool-browser/block-recovery.ts +85 -0
  210. package/src/tool-browser/code-tool.ts +555 -0
  211. package/src/tool-browser/code-worker.ts +725 -0
  212. package/src/tool-browser/element-fields.ts +167 -0
  213. package/src/tool-browser/errors.ts +40 -0
  214. package/src/tool-browser/index.ts +265 -0
  215. package/src/tool-browser/page-probe.ts +675 -0
  216. package/src/tool-browser/panel-page.ts +126 -0
  217. package/src/tool-browser/probe-client.ts +183 -0
  218. package/src/tool-browser/screenshot-annotations.ts +131 -0
  219. package/src/tool-browser/screenshot-image.ts +49 -0
  220. package/src/tool-browser/state.ts +375 -0
  221. package/src/tool-browser/takeover.ts +199 -0
  222. package/src/tool-browser/tools-debug.ts +806 -0
  223. package/src/tool-browser/tools-interaction.ts +956 -0
  224. package/src/tool-browser/tools-navigation.ts +786 -0
  225. package/src/tool-browser/tools-observation.ts +474 -0
  226. package/src/tool-browser/tools-reference.ts +294 -0
  227. package/src/types/electron-shim.d.ts +144 -0
  228. package/src/types.ts +85 -0
  229. package/src/web-guest.ts +35 -0
  230. package/tools/accept-desktop.mjs +148 -0
  231. package/dist/client.d.cts +0 -516
  232. package/dist/client.d.mts +0 -516
  233. package/dist/index.cjs +0 -92
  234. package/dist/index.d.mts +0 -2960
  235. package/dist/index.mjs +0 -24
  236. package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
  237. package/dsh-builtin-browser-1.0.3.tgz +0 -0
  238. package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  239. package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  240. package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  241. package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  242. package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  243. package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  244. package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  245. package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  246. package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  247. package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  248. package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  249. package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  250. package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  251. package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  252. package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  253. package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  254. package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  255. package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  256. package/dsh-host-patch/sources/manifest.json +0 -218
  257. package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  258. package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  259. package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  260. package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  261. package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  262. package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  263. package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  264. package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  265. package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  266. package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  267. package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  268. package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  269. package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  270. package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  271. package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  272. package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  273. package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  274. package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  275. package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
  276. package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
  277. package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
  278. package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
  279. package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
  280. package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
  281. package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
  282. package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
  283. package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
  284. package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
  285. package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
  286. package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
  287. package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
  288. package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
  289. package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
  290. package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
  291. package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
  292. package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
  293. package/dsh-host-patch/sources/series.json +0 -260
@@ -0,0 +1,78 @@
1
+ /** Carrier-neutral page navigation and observable state. */
2
+ import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots'
3
+ import type { BrowserTarget } from './url.ts'
4
+
5
+ /** A loading failure, optionally carrying the underlying browser's diagnostic. */
6
+ export interface BrowserLoadError {
7
+ readonly code: number | string | undefined
8
+ readonly description: string | undefined
9
+ }
10
+
11
+ /** State consumed by common browser chrome, without DOM or carrier identifiers. */
12
+ export interface BrowserFrameState {
13
+ /** Controller request whose navigation this frame is observing. */
14
+ readonly navigationId?: string
15
+ readonly target: BrowserTarget | undefined
16
+ readonly address: 'empty' | 'requested' | 'observed' | 'unknown'
17
+ readonly loading: boolean
18
+ /** The current document's DOM is ready even if its subresources are still loading. */
19
+ readonly documentReady?: boolean
20
+ readonly canGoBack: boolean
21
+ readonly canGoForward: boolean
22
+ readonly error: BrowserLoadError | undefined
23
+ /** Undefined when this provider does not expose a sandbox control. */
24
+ readonly sandboxEnabled: boolean | undefined
25
+ }
26
+
27
+ /** Optional iframe policy control, not an Electron process-sandbox switch. */
28
+ export interface BrowserSandboxControl {
29
+ /** @param enabled - whether the provider's embedding sandbox is enforced. */
30
+ setEnabled(enabled: boolean): void
31
+ }
32
+
33
+ /** Carrier-level initialization stage, below the navigation record. */
34
+ export type BrowserCarrierStage = 'idle' | 'guest' | 'ready' | 'failed'
35
+
36
+ /** What the carrier can prove about the page it owns. */
37
+ export interface BrowserCarrierState {
38
+ readonly stage: BrowserCarrierStage
39
+ /** Native guest id once the shell reports one. */
40
+ readonly guestId?: string
41
+ readonly generation?: string
42
+ readonly frameId?: string
43
+ readonly loaderId?: string
44
+ /** Why the carrier could not reach `ready`; machine code, localized by the UI. */
45
+ readonly reason?: 'workspace-unavailable' | 'acquire-failed' | 'guest-bootstrap-failed'
46
+ /** Original carrier failure text, bounded and kept with its owning attempt. */
47
+ readonly detail?: string
48
+ }
49
+
50
+ /** Navigation owns page lifetime; mounting and hiding belong to BrowserPresentation. */
51
+ export interface BrowserFrame extends HostObservable<BrowserFrameState> {
52
+ readonly sandbox?: BrowserSandboxControl
53
+ /**
54
+ * Optional carrier proof (`guest created`, `document ready`, bootstrap failure).
55
+ * A frame without it still navigates; its initialization receipt simply stops
56
+ * at `navigating`, which is exactly what an older carrier can promise.
57
+ */
58
+ readonly lifecycle?: HostObservable<BrowserCarrierState>
59
+ /** @param target - validated HTTP(S) address; loading failures are published in state. */
60
+ loadUrl(target: BrowserTarget, navigationId?: string): void
61
+ /** Move backward when the provider reports an available entry. */
62
+ goBack(): void
63
+ /** Move forward when the provider reports an available entry. */
64
+ goForward(): void
65
+ /** Reload the current address without creating a new history entry. */
66
+ reload(): void
67
+ /** @returns after the page, listeners and pending initialization have been released; repeated calls join disposal. */
68
+ dispose(): Promise<void>
69
+ }
70
+
71
+ /**
72
+ * Create idle navigation state without a page target.
73
+ * @returns state before any page has been requested.
74
+ */
75
+ export function emptyBrowserFrame(): BrowserFrameState {
76
+ return { target: undefined, address: 'empty', loading: false, canGoBack: false, canGoForward: false,
77
+ error: undefined, sandboxEnabled: undefined }
78
+ }
@@ -0,0 +1,169 @@
1
+ /** Bounded, application-known history used only by the iframe provider. */
2
+ import type { BrowserTarget } from './url.ts'
3
+ import type { BrowserHistoryEntry, BrowserTabState } from './BrowserPersistence.ts'
4
+
5
+ /** Maximum retained application-known navigation entries per tab. */
6
+ export const MAX_BROWSER_HISTORY = 100
7
+
8
+ /**
9
+ * Owns the application-known URL history and the iframe observation state machine.
10
+ * The first load for a request keeps its URL authoritative; another load marks it unknown.
11
+ */
12
+ export class BrowserNavigation {
13
+ private value: BrowserTabState
14
+
15
+ /**
16
+ * @param initial - persisted state restored for this tab, or a fresh empty state.
17
+ */
18
+ constructor(initial: BrowserTabState = BrowserNavigation.empty()) {
19
+ this.value = initial
20
+ }
21
+
22
+ /**
23
+ * Create state before a tab has a controlled navigation target.
24
+ * @returns empty serializable state.
25
+ */
26
+ static empty(): BrowserTabState {
27
+ return { entries: [], index: -1, request: undefined, navigation: { status: 'empty' }, failure: undefined }
28
+ }
29
+
30
+ /**
31
+ * Read the selected application-history entry.
32
+ * @param state - serializable tab state.
33
+ * @returns the current target, if any.
34
+ */
35
+ static current(state: BrowserTabState | undefined): BrowserHistoryEntry | undefined {
36
+ return state === undefined || state.index < 0 ? undefined : state.entries[state.index]
37
+ }
38
+
39
+ /**
40
+ * Test whether the Web carrier can use the preceding application-history entry.
41
+ * @param state - serializable tab state.
42
+ * @returns whether Back is available.
43
+ */
44
+ static canGoBack(state: BrowserTabState): boolean {
45
+ return state.navigation.status !== 'unknown' && state.index > 0
46
+ }
47
+
48
+ /**
49
+ * Test whether the Web carrier can use the following application-history entry.
50
+ * @param state - serializable tab state.
51
+ * @returns whether Forward is available.
52
+ */
53
+ static canGoForward(state: BrowserTabState): boolean {
54
+ return state.navigation.status !== 'unknown'
55
+ && state.index >= 0
56
+ && state.index < state.entries.length - 1
57
+ }
58
+
59
+ /** Current immutable serializable state. */
60
+ get snapshot(): BrowserTabState {
61
+ return this.value
62
+ }
63
+
64
+ /** Whether the Web iframe can safely use the application-owned Back entry. */
65
+ get canGoBack(): boolean {
66
+ return BrowserNavigation.canGoBack(this.value)
67
+ }
68
+
69
+ /** Whether the Web iframe can safely use the application-owned Forward entry. */
70
+ get canGoForward(): boolean {
71
+ return BrowserNavigation.canGoForward(this.value)
72
+ }
73
+
74
+ /**
75
+ * Add a controlled target and discard its stale forward branch.
76
+ * @param target - validated canonical target.
77
+ * @returns the new load request.
78
+ */
79
+ navigate(target: BrowserTarget): NonNullable<BrowserTabState['request']> {
80
+ const entries = [...this.value.entries.slice(0, this.value.index + 1), target]
81
+ if (entries.length > MAX_BROWSER_HISTORY) entries.splice(0, entries.length - MAX_BROWSER_HISTORY)
82
+ return this.request(target, { ...this.value, entries, index: entries.length - 1 })
83
+ }
84
+
85
+ /**
86
+ * Select the preceding application-known target.
87
+ * @returns a new load request, or undefined when unavailable.
88
+ */
89
+ back(): BrowserTabState['request'] {
90
+ if (!this.canGoBack) return undefined
91
+ const index = this.value.index - 1
92
+ const target = this.value.entries[index] as BrowserHistoryEntry
93
+ return this.request(target, { ...this.value, index })
94
+ }
95
+
96
+ /**
97
+ * Select the following application-known target.
98
+ * @returns a new load request, or undefined when unavailable.
99
+ */
100
+ forward(): BrowserTabState['request'] {
101
+ if (!this.canGoForward) return undefined
102
+ const index = this.value.index + 1
103
+ const target = this.value.entries[index] as BrowserHistoryEntry
104
+ return this.request(target, { ...this.value, index })
105
+ }
106
+
107
+ /**
108
+ * Start another load of the last application-known target.
109
+ * @returns a new load request, or undefined before the first target.
110
+ */
111
+ reload(): BrowserTabState['request'] {
112
+ const target = BrowserNavigation.current(this.value)
113
+ return target === undefined ? undefined : this.request(target, this.value)
114
+ }
115
+
116
+ /**
117
+ * Record a frame load for its captured revision.
118
+ * @param revision - revision bound to the rendered frame.
119
+ */
120
+ frameLoaded(revision: number): void {
121
+ const navigation = this.value.navigation
122
+ if (navigation.status === 'empty' || navigation.revision !== revision) return
123
+ if (navigation.status === 'loading') {
124
+ this.value = { ...this.value, navigation: { status: 'known', revision } }
125
+ } else if (navigation.status === 'known') {
126
+ this.value = { ...this.value, navigation: { status: 'unknown', revision } }
127
+ }
128
+ }
129
+
130
+ /**
131
+ * 记录页面**自己**走到的地址(同源代理下可读),不发新请求。
132
+ *
133
+ * 页内点链接后 iframe 已经显示新文档,只是应用不知道地址;这里把已知地址换成观测值,
134
+ * 地址栏才跟得上,也不会再提示「URL 已变化」。
135
+ * @param target - 从 frame 自身地址解出的目标。
136
+ */
137
+ recordObserved(target: BrowserTarget): void {
138
+ const current = BrowserNavigation.current(this.value)
139
+ if (current !== undefined && current.url === target.url) {
140
+ const navigation = this.value.navigation
141
+ if (navigation.status === 'unknown') this.value = { ...this.value, navigation: { status: 'known', revision: navigation.revision } }
142
+ return
143
+ }
144
+ const entries = [...this.value.entries.slice(0, this.value.index + 1), target]
145
+ if (entries.length > MAX_BROWSER_HISTORY) entries.splice(0, entries.length - MAX_BROWSER_HISTORY)
146
+ this.value = {
147
+ ...this.value,
148
+ entries,
149
+ index: entries.length - 1,
150
+ request: undefined,
151
+ navigation: { status: 'known', revision: this.value.navigation.status === 'empty' ? 0 : this.value.navigation.revision },
152
+ failure: undefined,
153
+ }
154
+ }
155
+
156
+ private request(
157
+ target: BrowserTarget,
158
+ basis: BrowserTabState,
159
+ ): NonNullable<BrowserTabState['request']> {
160
+ const request = { revision: (this.value.request?.revision ?? 0) + 1, target }
161
+ this.value = {
162
+ ...basis,
163
+ request,
164
+ navigation: { status: 'loading', revision: request.revision },
165
+ failure: undefined,
166
+ }
167
+ return request
168
+ }
169
+ }
@@ -0,0 +1,23 @@
1
+ /** Composition of one navigation provider and its presentation. */
2
+ import type { BrowserPresentation } from '../view/BrowserPresentation.ts'
3
+ import type { BrowserFrame } from './BrowserFrame.ts'
4
+ import type { BrowserTabState } from './BrowserPersistence.ts'
5
+ import type { TabId } from '@deepseek-ai/dsh-client-ui-dockkit'
6
+
7
+ /** Provider construction inputs; persistence does not enter the live navigation interface. */
8
+ export interface BrowserPageOptions {
9
+ readonly tabId?: TabId
10
+ readonly initial: BrowserTabState | undefined
11
+ readonly persist: (state: BrowserTabState) => void
12
+ readonly openRequested: (url: string) => void
13
+ }
14
+
15
+ /** The owning controller disposes frame; UI mounts only presentation. */
16
+ export interface BrowserPage {
17
+ readonly adoption?: { readonly url: string; acknowledge(requestId: string): void }
18
+ readonly frame: BrowserFrame
19
+ readonly presentation: BrowserPresentation
20
+ }
21
+
22
+ /** Construct an idle provider without attaching DOM; saved navigation waits for an explicit frame command. */
23
+ export type BrowserPageFactory = (options: BrowserPageOptions) => BrowserPage
@@ -0,0 +1,44 @@
1
+ /** Existing browser-local navigation records, independent from live frame state. */
2
+ import type { BrowserAddressFailure, BrowserTarget } from './url.ts'
3
+
4
+ /** One retained address. */
5
+ export type BrowserHistoryEntry = BrowserTarget
6
+
7
+ /** Observability recorded for a controlled navigation. */
8
+ export type BrowserNavigationStatus =
9
+ | { readonly status: 'empty' }
10
+ | { readonly status: 'loading'; readonly revision: number }
11
+ | { readonly status: 'known'; readonly revision: number }
12
+ | { readonly status: 'unknown'; readonly revision: number }
13
+
14
+ /** Address refusal carried by existing browser-local records. */
15
+ export type BrowserFailure = { readonly kind: 'address'; readonly reason: BrowserAddressFailure }
16
+
17
+ /** Serializable record; providers retain the history they can restore. */
18
+ export interface BrowserTabState {
19
+ readonly entries: readonly BrowserHistoryEntry[]
20
+ readonly index: number
21
+ readonly request: { readonly revision: number; readonly target: BrowserTarget } | undefined
22
+ readonly navigation: BrowserNavigationStatus
23
+ readonly failure: BrowserFailure | undefined
24
+ }
25
+
26
+ /**
27
+ * Read the selected address from a saved navigation record.
28
+ * @param state - saved navigation.
29
+ * @returns its last selected address, if any.
30
+ */
31
+ export function currentBrowserTarget(state: BrowserTabState | undefined): BrowserTarget | undefined {
32
+ return state === undefined || state.index < 0 ? undefined : state.entries[state.index]
33
+ }
34
+
35
+ /**
36
+ * Checkpoint an observed address without serializing native history.
37
+ * @param target - current address.
38
+ * @param revision - navigation generation.
39
+ * @returns an address-only checkpoint.
40
+ */
41
+ export function browserAddressCheckpoint(target: BrowserTarget, revision: number): BrowserTabState {
42
+ return { entries: [target], index: 0, request: { target, revision },
43
+ navigation: { status: 'known', revision }, failure: undefined }
44
+ }
@@ -0,0 +1,182 @@
1
+ /** Iframe navigation provider with bounded application-known history. */
2
+ import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
3
+ import { sameFrameState } from './frame-state.ts'
4
+ import type { IframePresentation } from '../view/IframePresentation.ts'
5
+ import { emptyBrowserFrame, type BrowserCarrierState, type BrowserFrame, type BrowserFrameState, type BrowserLoadError, type BrowserSandboxControl } from './BrowserFrame.ts'
6
+ import type { BrowserPageOptions } from './BrowserPage.ts'
7
+ import { BrowserNavigation } from './BrowserNavigation.ts'
8
+ import type { BrowserTarget } from './url.ts'
9
+ import { parseBrowserAddress } from './url.ts'
10
+
11
+ /**
12
+ * 把观测到的地址变成合法目标(只接受 http(s),其余返回 undefined)。
13
+ * @param url - 从 frame 自身地址解出的真实地址。
14
+ * @param title - 沿用当前标题的占位值。
15
+ */
16
+ function toTarget(url: string, title: string): BrowserTarget | undefined {
17
+ const parsed = parseBrowserAddress(url)
18
+ if (!parsed.ok) return undefined
19
+ const target = parsed.target
20
+ return target.kind === 'https' || target.kind === 'http'
21
+ ? { ...target, title: target.title === '' ? title : target.title }
22
+ : undefined
23
+ }
24
+
25
+ /** Owns iframe navigation; the view reports loads without reading cross-origin content. */
26
+ export class IframeImpl implements BrowserFrame {
27
+ private readonly carrier = createSnapshotStore<BrowserCarrierState>({ stage: 'idle' })
28
+ readonly lifecycle = { getSnapshot: () => this.carrier.getSnapshot(), subscribe: (listener: () => void) => this.carrier.subscribe(listener) }
29
+ readonly sandbox: BrowserSandboxControl = { setEnabled: (enabled) => { this.setSandbox(enabled) } }
30
+ private readonly navigation: BrowserNavigation
31
+ private readonly store: SnapshotStore<BrowserFrameState>
32
+ private sandboxed = true
33
+ private frameHistoryForward = false
34
+ private error: BrowserLoadError | undefined
35
+ private disposed = false
36
+ private disposal: Promise<void> | undefined
37
+ private navigationId: string | undefined
38
+ private readonly options: BrowserPageOptions
39
+ private readonly presentation: IframePresentation
40
+ constructor(options: BrowserPageOptions, presentation: IframePresentation) {
41
+ this.options = options
42
+ this.presentation = presentation
43
+ this.navigation = new BrowserNavigation(options.initial)
44
+ this.store = createSnapshotStore({ ...emptyBrowserFrame(), sandboxEnabled: this.sandboxed })
45
+ }
46
+
47
+ /**
48
+ * Complete a native iframe navigation, including documents without a guest runtime.
49
+ * @param revision - document generation whose iframe emitted load.
50
+ */
51
+ handleLoaded(revision: number): void {
52
+ if (this.disposed) return
53
+ const navigation = this.navigation.snapshot.navigation
54
+ if (navigation.status !== 'empty' && navigation.revision !== revision) return
55
+ this.navigation.frameLoaded(revision)
56
+ this.publish()
57
+ }
58
+
59
+ handleGuestPending(): void {
60
+ this.carrier.set({ stage: 'guest' })
61
+ }
62
+
63
+ handleGuestFailed(revision: number, description: string): void {
64
+ if (this.disposed || this.navigation.snapshot.navigation.status === 'empty'
65
+ || this.navigation.snapshot.navigation.revision !== revision) return
66
+ this.carrier.set({ stage: 'failed', reason: 'guest-bootstrap-failed', detail: description })
67
+ this.error = { code: 'browser-capability-unavailable', description }
68
+ this.publish()
69
+ }
70
+
71
+ handleCapabilityFailure(description: string): void {
72
+ if (this.disposed) return
73
+ this.error = { code: 'browser-capability-unavailable', description }
74
+ this.publish()
75
+ }
76
+
77
+ handleGuestReady(revision: number, pageId: string): void {
78
+ if (this.disposed || this.navigation.snapshot.navigation.status === 'empty'
79
+ || this.navigation.snapshot.navigation.revision !== revision) return
80
+ this.carrier.set({ stage: 'ready', guestId: pageId })
81
+ this.publish()
82
+ }
83
+
84
+ /** Accept metadata correlated to the current completed native load, without completing it again. */
85
+ handleObserved(revision: number, observedUrl: string): void {
86
+ if (this.disposed) return
87
+ const navigation = this.navigation.snapshot.navigation
88
+ if (navigation.status === 'empty' || navigation.status === 'loading' || navigation.revision !== revision) return
89
+ const current = BrowserNavigation.current(this.navigation.snapshot)
90
+ const target = toTarget(observedUrl, current?.title ?? '')
91
+ if (target !== undefined) this.navigation.recordObserved(target)
92
+ this.publish()
93
+ }
94
+
95
+ /**
96
+ * Publish a failure only for the current document generation.
97
+ * @param revision - document generation whose iframe reported failure.
98
+ */
99
+ handleLoadFailed(revision: number): void {
100
+ if (this.disposed || this.navigation.snapshot.request?.revision !== revision) return
101
+ this.error = { code: undefined, description: undefined }
102
+ this.publish()
103
+ }
104
+
105
+ /** @returns immutable navigation state. */
106
+ getSnapshot = (): BrowserFrameState => this.store.getSnapshot()
107
+ /** @param listener - state invalidation. @returns unsubscribe callback. */
108
+ subscribe = (listener: () => void): (() => void) => this.store.subscribe(listener)
109
+
110
+ /** @param target - validated address; submitting the current address reloads it. */
111
+ loadUrl(target: BrowserTarget, navigationId?: string): void {
112
+ if (this.disposed) return
113
+ this.navigationId = navigationId
114
+ const request = BrowserNavigation.current(this.navigation.snapshot)?.url === target.url
115
+ ? this.navigation.reload() : this.navigation.navigate(target)
116
+ this.load(request)
117
+ }
118
+
119
+ /** Move back: app-known history first, then the iframe's own (page-internal) history. */
120
+ goBack(): void {
121
+ if (this.disposed) return
122
+ if (this.navigation.canGoBack) { this.load(this.navigation.back()); return }
123
+ this.frameHistoryForward = this.presentation.historyStep(-1) || this.frameHistoryForward
124
+ this.publish()
125
+ }
126
+
127
+ /** Move forward: app-known history first, then the iframe's own (page-internal) history. */
128
+ goForward(): void {
129
+ if (this.disposed) return
130
+ if (this.navigation.canGoForward) { this.load(this.navigation.forward()); return }
131
+ if (this.presentation.historyStep(1)) this.frameHistoryForward = this.presentation.canGoForward?.() ?? false
132
+ this.publish()
133
+ }
134
+ /** Reload the last application-known address. */
135
+ reload(): void { if (!this.disposed) this.load(this.navigation.reload()) }
136
+
137
+ /** @returns after the presentation has been removed; repeated calls join disposal. */
138
+ dispose(): Promise<void> {
139
+ if (this.disposal !== undefined) return this.disposal
140
+ this.disposed = true
141
+ this.presentation.dispose()
142
+ this.disposal = Promise.resolve()
143
+ return this.disposal
144
+ }
145
+
146
+ private setSandbox(enabled: boolean): void {
147
+ if (this.disposed || enabled === this.sandboxed) return
148
+ this.sandboxed = enabled
149
+ if (this.store.getSnapshot().target === undefined) {
150
+ this.store.set({ ...this.store.getSnapshot(), sandboxEnabled: enabled })
151
+ return
152
+ }
153
+ this.load(this.navigation.reload())
154
+ }
155
+
156
+ private load(request: ReturnType<BrowserNavigation['navigate']> | undefined): void {
157
+ if (request === undefined) return
158
+ this.frameHistoryForward = false
159
+ this.error = undefined
160
+ this.publish()
161
+ this.presentation.show({ target: request.target, revision: request.revision, sandboxed: this.sandboxed })
162
+ }
163
+
164
+ private snapshot(): BrowserFrameState {
165
+ const state = this.navigation.snapshot
166
+ const target = BrowserNavigation.current(state)
167
+ return { navigationId: this.navigationId, target, address: target === undefined ? 'empty' : state.navigation.status === 'unknown' ? 'unknown'
168
+ : this.carrier.getSnapshot().stage === 'ready' ? 'observed' : 'requested',
169
+ loading: state.navigation.status === 'loading' && this.error === undefined,
170
+ canGoBack: this.navigation.canGoBack || this.presentation.historyDepth() > 1,
171
+ canGoForward: this.navigation.canGoForward || (this.presentation.canGoForward?.() ?? this.frameHistoryForward),
172
+ error: this.error, sandboxEnabled: this.sandboxed }
173
+ }
174
+
175
+ private publish(): void {
176
+ const next = this.snapshot()
177
+ // Publishing an identical state wakes every subscriber for nothing; in a dock that re-renders on
178
+ // each publish that is the React #185 loop (issue #127). Compare first, then set.
179
+ if (!sameFrameState(this.store.getSnapshot(), next)) this.store.set(next)
180
+ this.options.persist(this.navigation.snapshot)
181
+ }
182
+ }
@@ -0,0 +1,14 @@
1
+ import type { BrowserChildTabRequest, BrowserChildTabResult } from '../../types.ts'
2
+ import { parseBrowserAddress } from './url.ts'
3
+
4
+ export function dispatchChildTab(request: BrowserChildTabRequest, applicationOrigin: string,
5
+ open: (url: string) => void, alive = true): BrowserChildTabResult {
6
+ if (!alive) return { status: 'unsupported', code: 'guest-disposed' }
7
+ if (request.mode !== 'url-only') return { status: 'unsupported', code: 'BROWSER_NATIVE_CHILD_UNAVAILABLE' }
8
+ if (typeof request.url !== 'string' || !/^https?:\/\//iu.test(request.url)) return { status: 'unsupported', code: 'invalid-child-url' }
9
+ const parsed = parseBrowserAddress(request.url, applicationOrigin)
10
+ if (!parsed.ok || !['http', 'https'].includes(parsed.target.kind)) return { status: 'unsupported', code: 'invalid-child-url' }
11
+ try { open(parsed.target.url) }
12
+ catch { return { status: 'unsupported', code: 'sidebar-tab-dispatch-failed' } }
13
+ return { status: 'url-only-dispatched' }
14
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Tracks one opaque guest iframe's own position inside the browser's joint session history.
3
+ *
4
+ * Joint `history.length` includes entries owned by the host DSH page and retains the guest's
5
+ * forward branch after a Back step. Comparing `depth` only against `lastDepth` fails when a
6
+ * user goes Back and then navigates to a new page (or calls `history.pushState`): Chromium
7
+ * truncates the forward branch before pushing the new entry, so `history.length` stays equal
8
+ * to (or becomes smaller than) `lastDepth`, leaving Back disabled.
9
+ *
10
+ * Comparing against `baseDepth + index` on genuine forward navigations (and honoring explicit
11
+ * `push` / `pop` / `replace` / `navigationType` hints from the guest runtime) keeps both Back
12
+ * and Forward accurate across branches without ever stepping into the host page's history.
13
+ */
14
+ export interface GuestHistoryObservation {
15
+ readonly depth: number
16
+ readonly reason?: string | undefined
17
+ readonly navigationType?: string | undefined
18
+ }
19
+
20
+ export class GuestFrameHistory {
21
+ private baseDepth: number | undefined
22
+ private lastDepth = 1
23
+ private index = 0
24
+ private maxIndex = 0
25
+ private hasCommittedDocument = false
26
+ private documentNavigated = false
27
+ private pendingSteps = 0
28
+
29
+ reset(baseDepth: number): void {
30
+ this.baseDepth = Number.isSafeInteger(baseDepth) && baseDepth > 0 ? baseDepth : 1
31
+ this.lastDepth = this.baseDepth
32
+ this.index = 0
33
+ this.maxIndex = 0
34
+ this.hasCommittedDocument = false
35
+ this.documentNavigated = false
36
+ this.pendingSteps = 0
37
+ }
38
+
39
+ /** Record that the guest switched to a new document identity after the initial load. */
40
+ noteDocumentChange(): void {
41
+ if (this.hasCommittedDocument) this.documentNavigated = true
42
+ }
43
+
44
+ record(observation: GuestHistoryObservation): void {
45
+ const depth = Number.isSafeInteger(observation.depth) && observation.depth > 0 ? observation.depth : 1
46
+ if (this.baseDepth === undefined || depth < this.baseDepth) this.baseDepth = depth
47
+ const base = this.baseDepth
48
+ const reason = observation.reason
49
+ const navType = observation.navigationType
50
+ const navigated = this.documentNavigated
51
+ this.documentNavigated = false
52
+ this.hasCommittedDocument = true
53
+
54
+ if (reason === 'push') {
55
+ this.pendingSteps = 0
56
+ this.index = Math.max(this.index + 1, depth - base)
57
+ this.maxIndex = this.index
58
+ this.lastDepth = depth
59
+ return
60
+ }
61
+ if (reason === 'pop' || reason === 'pageshow') {
62
+ if (this.pendingSteps > 0) this.pendingSteps -= 1
63
+ this.lastDepth = depth
64
+ return
65
+ }
66
+ if (reason === 'replace') {
67
+ this.lastDepth = depth
68
+ return
69
+ }
70
+
71
+ if (navigated) {
72
+ if (navType === 'back_forward') {
73
+ if (this.pendingSteps > 0) this.pendingSteps -= 1
74
+ this.lastDepth = depth
75
+ return
76
+ }
77
+ if (navType === 'reload') {
78
+ this.lastDepth = depth
79
+ return
80
+ }
81
+ if (navType === undefined && this.pendingSteps > 0) {
82
+ this.pendingSteps -= 1
83
+ this.lastDepth = depth
84
+ return
85
+ }
86
+ // Fresh cross-document navigation: Chromium truncated any forward branch above `index`
87
+ // before pushing the new entry. Only advance when joint history exceeds `base + index`,
88
+ // so `location.replace()` at the tip does not fabricate a Back entry.
89
+ this.pendingSteps = 0
90
+ if (depth > base + this.index) {
91
+ this.index = depth - base
92
+ this.maxIndex = this.index
93
+ }
94
+ this.lastDepth = depth
95
+ return
96
+ }
97
+
98
+ if (depth > this.lastDepth) {
99
+ this.index = depth - base
100
+ this.maxIndex = Math.max(this.maxIndex, this.index)
101
+ }
102
+ this.lastDepth = depth
103
+ }
104
+
105
+ canStep(delta: number): boolean {
106
+ return delta < 0 ? this.index > 0 : this.index < this.maxIndex
107
+ }
108
+
109
+ step(delta: number): boolean {
110
+ if (!this.canStep(delta)) return false
111
+ this.index = Math.max(0, this.index + (delta < 0 ? -1 : 1))
112
+ this.pendingSteps += 1
113
+ return true
114
+ }
115
+
116
+ /** Entries this guest iframe itself added, counting the current one; host session history is excluded. */
117
+ depth(): number {
118
+ return this.index + 1
119
+ }
120
+
121
+ /** Whether the guest iframe has a forward entry of its own. */
122
+ canGoForward(): boolean {
123
+ return this.index < this.maxIndex
124
+ }
125
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * "Is this the same frame state?" — the guard that keeps a publish loop from becoming React #185.
3
+ *
4
+ * WHY THIS EXISTS
5
+ * Every tick of a browser tab calls `publish()`, which hands a freshly built snapshot object to the
6
+ * session store. The store notifies its subscribers on every `set`, the dock re-renders, and a tab
7
+ * whose state did not actually change publishes again — an unbounded publish → render → publish
8
+ * cycle that React reports as "Maximum update depth exceeded" (issue #127).
9
+ *
10
+ * The snapshot is a plain object of scalars plus one `target` descriptor, so "changed" means "a key
11
+ * differs", with the descriptor compared by value.
12
+ */
13
+
14
+ /** Compare two snapshots by value, so an equal state is not published again. */
15
+ export function sameFrameState(left: object, right: object): boolean {
16
+ const keys = new Set([...Object.keys(left), ...Object.keys(right)])
17
+ for (const key of keys) {
18
+ const a = (left as Record<string, unknown>)[key]
19
+ const b = (right as Record<string, unknown>)[key]
20
+ if (a === b) continue
21
+ if (typeof a === 'object' && typeof b === 'object' && a !== null && b !== null) {
22
+ if (JSON.stringify(a) === JSON.stringify(b)) continue
23
+ }
24
+ return false
25
+ }
26
+ return true
27
+ }