dsh-builtin-browser 1.0.1 → 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 (222) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/assets/browser-panel-locales.mjs +37 -5
  4. package/assets/browser-policy.d.mts +29 -0
  5. package/assets/browser-policy.mjs +40 -0
  6. package/desktop-bridge/desktop-discovery.d.mts +1 -1
  7. package/desktop-bridge/desktop-discovery.mjs +59 -9
  8. package/desktop-bridge/desktop-identity.json +12 -0
  9. package/desktop-bridge/install.mjs +14 -7
  10. package/desktop-bridge/plugin-browser-bridge.js +19 -7
  11. package/docs/acceptance-2026-11-27.md +67 -0
  12. package/docs/architecture.md +1 -1
  13. package/docs/development.md +33 -4
  14. package/docs/dsh-0.2.3-host-patch-task.md +34 -0
  15. package/docs/hardcoding-audit.md +28 -8
  16. package/docs/known-issues.md +26 -0
  17. package/docs/limitations.md +6 -2
  18. package/docs/tool-reference.md +1 -1
  19. package/docs/v1.1.0-bu-data-batching-task.md +66 -0
  20. package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
  21. package/dsh-host-patch/README.md +4 -0
  22. package/dsh-host-patch/apply.mjs +61 -13
  23. package/dsh-host-patch/rc3-revision9.json.gz +0 -0
  24. package/dsh-host-patch/rc5-revision9.json.gz +0 -0
  25. package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
  26. package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
  27. package/dsh-host-patch/tauri-revision1.json +39 -0
  28. package/dsh-host-patch/tauri.json +43 -0
  29. package/dsh-host-patch/v023-alpha2.json +153 -0
  30. package/lib/browser/anti-bot.js +215 -0
  31. package/lib/browser/deep-dom.js +39 -0
  32. package/lib/browser/runtime.js +15 -0
  33. package/lib/browser/takeover-target.js +13 -6
  34. package/lib/browser/types.js +30 -1
  35. package/lib/browser-electron/authenticated-route.js +16 -2
  36. package/lib/browser-electron/automatic-maintenance.js +16 -10
  37. package/lib/browser-electron/bridge-connection.js +3 -8
  38. package/lib/browser-electron/bridge-install.js +2 -1
  39. package/lib/browser-electron/bridge-status.js +55 -26
  40. package/lib/browser-electron/desktop-bridge-host.js +7 -6
  41. package/lib/browser-electron/desktop-identity.js +28 -5
  42. package/lib/browser-electron/desktop-shell.js +64 -0
  43. package/lib/browser-electron/electron-provision.js +105 -18
  44. package/lib/browser-electron/entry.js +129 -44
  45. package/lib/browser-electron/extension-browser.js +4 -4
  46. package/lib/browser-electron/foreground-watch.js +134 -0
  47. package/lib/browser-electron/guest-cookie-jar.js +13 -13
  48. package/lib/browser-electron/guest-route.js +181 -32
  49. package/lib/browser-electron/guest-runtime.js +61 -10
  50. package/lib/browser-electron/guest-storage.js +2 -2
  51. package/lib/browser-electron/history-store.js +1 -5
  52. package/lib/browser-electron/host-main.js +8 -4
  53. package/lib/browser-electron/host-patch-maintenance.js +14 -8
  54. package/lib/browser-electron/maintenance-route.js +2 -1
  55. package/lib/browser-electron/missing-system-browser.js +5 -9
  56. package/lib/browser-electron/preferred-browser.js +7 -3
  57. package/lib/browser-electron/preview-route.js +9 -13
  58. package/lib/browser-electron/process-ownership.js +1 -1
  59. package/lib/browser-electron/profile-command.js +2 -1
  60. package/lib/browser-electron/profile-extension.js +5 -0
  61. package/lib/browser-electron/profile-lease.js +152 -47
  62. package/lib/browser-electron/provider-core.js +527 -0
  63. package/lib/browser-electron/provider-interaction.js +963 -0
  64. package/lib/browser-electron/provider-media.js +518 -0
  65. package/lib/browser-electron/provider-navigation.js +301 -0
  66. package/lib/browser-electron/provider-observation.js +623 -0
  67. package/lib/browser-electron/provider-tabs.js +372 -0
  68. package/lib/browser-electron/provider.js +150 -3301
  69. package/lib/browser-electron/reference-route.js +9 -18
  70. package/lib/browser-electron/remote-host.js +79 -34
  71. package/lib/browser-electron/runtime-status.js +56 -6
  72. package/lib/browser-electron/settings-store.js +3 -6
  73. package/lib/browser-electron/sidebar-only-host.js +1 -1
  74. package/lib/browser-electron/system-browser.js +539 -172
  75. package/lib/browser-electron/tauri-host.js +208 -0
  76. package/lib/browser-electron/virtual-cursor.js +23 -13
  77. package/lib/browser-reference/service.js +22 -4
  78. package/lib/browser-reference/web-sources.js +1 -1
  79. package/lib/client.js +43409 -0
  80. package/lib/compat/host-features.js +75 -0
  81. package/lib/reference-source.js +1 -1
  82. package/lib/reference-text.js +23 -1
  83. package/lib/takeover-protocol.js +1 -1
  84. package/lib/tool-browser/block-recovery.js +69 -0
  85. package/lib/tool-browser/code-tool.js +170 -19
  86. package/lib/tool-browser/code-worker.js +115 -20
  87. package/lib/tool-browser/errors.js +34 -0
  88. package/lib/tool-browser/index.js +66 -3593
  89. package/lib/tool-browser/page-probe.js +227 -28
  90. package/lib/tool-browser/panel-page.js +2 -1
  91. package/lib/tool-browser/probe-client.js +157 -0
  92. package/lib/tool-browser/screenshot-annotations.js +108 -0
  93. package/lib/tool-browser/state.js +337 -0
  94. package/lib/tool-browser/takeover.js +1 -1
  95. package/lib/tool-browser/tools-debug.js +862 -0
  96. package/lib/tool-browser/tools-interaction.js +993 -0
  97. package/lib/tool-browser/tools-navigation.js +807 -0
  98. package/lib/tool-browser/tools-observation.js +461 -0
  99. package/lib/tool-browser/tools-reference.js +293 -0
  100. package/lib/web-guest.js +1 -0
  101. package/package.json +16 -36
  102. package/scripts/build-client.mjs +305 -0
  103. package/scripts/build.mjs +15 -12
  104. package/scripts/fix-exports.mjs +6 -16
  105. package/scripts/install-electron.mjs +55 -5
  106. package/scripts/pack.mjs +99 -0
  107. package/scripts/publish-manifest.mjs +56 -0
  108. package/scripts/verify-exports.mjs +26 -15
  109. package/skills/dsh-builtin-browser/SKILL.md +27 -2
  110. package/skills/dsh-builtin-browser/references/batch.md +15 -0
  111. package/src/browser/anti-bot.ts +251 -0
  112. package/src/browser/deep-dom.ts +40 -0
  113. package/src/browser/runtime.ts +18 -0
  114. package/src/browser/takeover-target.ts +16 -7
  115. package/src/browser/types.ts +56 -3
  116. package/src/browser-electron/authenticated-route.ts +29 -4
  117. package/src/browser-electron/automatic-maintenance.ts +23 -13
  118. package/src/browser-electron/bridge-connection.ts +11 -10
  119. package/src/browser-electron/bridge-install.ts +2 -1
  120. package/src/browser-electron/bridge-status.ts +61 -22
  121. package/src/browser-electron/desktop-bridge-host.ts +9 -7
  122. package/src/browser-electron/desktop-identity.ts +38 -5
  123. package/src/browser-electron/desktop-shell.ts +100 -0
  124. package/src/browser-electron/electron-provision.ts +104 -18
  125. package/src/browser-electron/entry.ts +1378 -1299
  126. package/src/browser-electron/extension-browser.ts +11 -4
  127. package/src/browser-electron/foreground-watch.ts +142 -0
  128. package/src/browser-electron/guest-cookie-jar.ts +3 -2
  129. package/src/browser-electron/guest-route.ts +180 -32
  130. package/src/browser-electron/guest-runtime.ts +61 -10
  131. package/src/browser-electron/guest-storage.ts +5 -2
  132. package/src/browser-electron/history-store.ts +3 -6
  133. package/src/browser-electron/host-main.ts +8 -4
  134. package/src/browser-electron/host-patch-maintenance.ts +18 -9
  135. package/src/browser-electron/maintenance-route.ts +2 -1
  136. package/src/browser-electron/missing-system-browser.ts +11 -10
  137. package/src/browser-electron/preferred-browser.ts +13 -3
  138. package/src/browser-electron/preview-route.ts +9 -12
  139. package/src/browser-electron/process-ownership.ts +9 -3
  140. package/src/browser-electron/profile-command.ts +2 -1
  141. package/src/browser-electron/profile-extension.ts +5 -0
  142. package/src/browser-electron/profile-lease.ts +131 -35
  143. package/src/browser-electron/provider-core.ts +1107 -0
  144. package/src/browser-electron/provider-interaction.ts +1034 -0
  145. package/src/browser-electron/provider-media.ts +589 -0
  146. package/src/browser-electron/provider-navigation.ts +323 -0
  147. package/src/browser-electron/provider-observation.ts +664 -0
  148. package/src/browser-electron/provider-tabs.ts +372 -0
  149. package/src/browser-electron/provider.ts +158 -4063
  150. package/src/browser-electron/reference-route.ts +598 -608
  151. package/src/browser-electron/remote-host.ts +118 -42
  152. package/src/browser-electron/runtime-status.ts +80 -13
  153. package/src/browser-electron/settings-store.ts +10 -6
  154. package/src/browser-electron/sidebar-only-host.ts +4 -2
  155. package/src/browser-electron/system-browser.ts +537 -184
  156. package/src/browser-electron/tauri-host.ts +194 -0
  157. package/src/browser-electron/virtual-cursor.ts +24 -14
  158. package/src/browser-reference/service.ts +38 -7
  159. package/src/browser-reference/web-sources.ts +4 -1
  160. package/src/client/apply-guard.ts +22 -0
  161. package/src/client/browser/BrowserController.ts +3 -3
  162. package/src/client/browser/IframeImpl.ts +182 -176
  163. package/src/client/browser/frame-history.ts +125 -0
  164. package/src/client/browser/frame-state.ts +27 -0
  165. package/src/client/browser/web-reference-source.ts +5 -1
  166. package/src/client/definition.tsx +36 -30
  167. package/src/client/electron/ElectronWebViewImpl.ts +20 -13
  168. package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
  169. package/src/client/electron/NativeChildPresentation.ts +11 -3
  170. package/src/client/electron/NativeViewPage.ts +19 -5
  171. package/src/client/index.ts +333 -293
  172. package/src/client/locales.ts +9 -6
  173. package/src/client/reference/client/plugin.ts +21 -2
  174. package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
  175. package/src/client/reference/client/production/assembly.ts +4 -28
  176. package/src/client/reference/client/production/availability.ts +0 -2
  177. package/src/client/reference/client/production/composer-attachments.ts +44 -0
  178. package/src/client/reference/client/production/draft-adapter.ts +4 -0
  179. package/src/client/reference/client/production/http-transport.ts +0 -5
  180. package/src/client/reference/client/production/production-submission.ts +50 -290
  181. package/src/client/reference/client/production/protocol.ts +7 -4
  182. package/src/client/reference/client/production/runtime.ts +41 -86
  183. package/src/client/reference/client/production/source-marker.ts +49 -13
  184. package/src/client/reference/client/production/user-text-rule.ts +10 -1
  185. package/src/client/reference/client/reveal.ts +3 -1
  186. package/src/client/reference/client/session-schedule.ts +36 -0
  187. package/src/client/settings/index.ts +8 -0
  188. package/src/client/settings/mount-guard.ts +31 -0
  189. package/src/client/settings/panel.ts +163 -52
  190. package/src/client/startpage/controller.ts +3 -6
  191. package/src/client/view/BrowserBody.tsx +2 -1
  192. package/src/client/view/IframePresentation.ts +37 -16
  193. package/src/client/view/StartPage.tsx +2 -1
  194. package/src/compat/host-features.ts +92 -0
  195. package/src/reference-source.ts +1 -1
  196. package/src/reference-text.ts +23 -1
  197. package/src/takeover-protocol.ts +11 -2
  198. package/src/tool-browser/block-recovery.ts +85 -0
  199. package/src/tool-browser/code-tool.ts +173 -19
  200. package/src/tool-browser/code-worker.ts +101 -15
  201. package/src/tool-browser/errors.ts +40 -0
  202. package/src/tool-browser/index.ts +66 -3534
  203. package/src/tool-browser/page-probe.ts +229 -28
  204. package/src/tool-browser/panel-page.ts +3 -1
  205. package/src/tool-browser/probe-client.ts +183 -0
  206. package/src/tool-browser/screenshot-annotations.ts +131 -0
  207. package/src/tool-browser/state.ts +375 -0
  208. package/src/tool-browser/takeover.ts +3 -2
  209. package/src/tool-browser/tools-debug.ts +806 -0
  210. package/src/tool-browser/tools-interaction.ts +956 -0
  211. package/src/tool-browser/tools-navigation.ts +786 -0
  212. package/src/tool-browser/tools-observation.ts +474 -0
  213. package/src/tool-browser/tools-reference.ts +294 -0
  214. package/src/web-guest.ts +35 -34
  215. package/dist/client.cjs +0 -43167
  216. package/dist/client.d.cts +0 -516
  217. package/dist/client.d.mts +0 -516
  218. package/dist/index.cjs +0 -92
  219. package/dist/index.d.mts +0 -2960
  220. package/dist/index.mjs +0 -24
  221. package/lib/browser-reference/submission-receipts.js +0 -139
  222. package/src/browser-reference/submission-receipts.ts +0 -122
@@ -1,176 +1,182 @@
1
- /** Iframe navigation provider with bounded application-known history. */
2
- import { createSnapshotStore, type SnapshotStore } from '@deepseek-ai/dsh-client-store'
3
- import type { IframePresentation } from '../view/IframePresentation.ts'
4
- import { emptyBrowserFrame, type BrowserCarrierState, type BrowserFrame, type BrowserFrameState, type BrowserLoadError, type BrowserSandboxControl } from './BrowserFrame.ts'
5
- import type { BrowserPageOptions } from './BrowserPage.ts'
6
- import { BrowserNavigation } from './BrowserNavigation.ts'
7
- import type { BrowserTarget } from './url.ts'
8
- import { parseBrowserAddress } from './url.ts'
9
-
10
- /**
11
- * 把观测到的地址变成合法目标(只接受 http(s),其余返回 undefined)。
12
- * @param url - 从 frame 自身地址解出的真实地址。
13
- * @param title - 沿用当前标题的占位值。
14
- */
15
- function toTarget(url: string, title: string): BrowserTarget | undefined {
16
- const parsed = parseBrowserAddress(url)
17
- if (!parsed.ok) return undefined
18
- const target = parsed.target
19
- return target.kind === 'https' || target.kind === 'http'
20
- ? { ...target, title: target.title === '' ? title : target.title }
21
- : undefined
22
- }
23
-
24
- /** Owns iframe navigation; the view reports loads without reading cross-origin content. */
25
- export class IframeImpl implements BrowserFrame {
26
- private readonly carrier = createSnapshotStore<BrowserCarrierState>({ stage: 'idle' })
27
- readonly lifecycle = { getSnapshot: () => this.carrier.getSnapshot(), subscribe: (listener: () => void) => this.carrier.subscribe(listener) }
28
- readonly sandbox: BrowserSandboxControl = { setEnabled: (enabled) => { this.setSandbox(enabled) } }
29
- private readonly navigation: BrowserNavigation
30
- private readonly store: SnapshotStore<BrowserFrameState>
31
- private sandboxed = true
32
- private frameHistoryForward = false
33
- private error: BrowserLoadError | undefined
34
- private disposed = false
35
- private disposal: Promise<void> | undefined
36
- private navigationId: string | undefined
37
-
38
- /** @param options - initial checkpoint and persistence writer. @param presentation - iframe DOM adapter. */
39
- constructor(private readonly options: BrowserPageOptions, private readonly presentation: IframePresentation) {
40
- this.navigation = new BrowserNavigation(options.initial)
41
- this.store = createSnapshotStore({ ...emptyBrowserFrame(), sandboxEnabled: this.sandboxed })
42
- }
43
-
44
- /**
45
- * Complete a native iframe navigation, including documents without a guest runtime.
46
- * @param revision - document generation whose iframe emitted load.
47
- */
48
- handleLoaded(revision: number): void {
49
- if (this.disposed) return
50
- const navigation = this.navigation.snapshot.navigation
51
- if (navigation.status !== 'empty' && navigation.revision !== revision) return
52
- this.navigation.frameLoaded(revision)
53
- this.publish()
54
- }
55
-
56
- handleGuestPending(): void {
57
- this.carrier.set({ stage: 'guest' })
58
- }
59
-
60
- handleGuestFailed(revision: number, description: string): void {
61
- if (this.disposed || this.navigation.snapshot.navigation.status === 'empty'
62
- || this.navigation.snapshot.navigation.revision !== revision) return
63
- this.carrier.set({ stage: 'failed', reason: 'guest-bootstrap-failed', detail: description })
64
- this.error = { code: 'browser-capability-unavailable', description }
65
- this.publish()
66
- }
67
-
68
- handleCapabilityFailure(description: string): void {
69
- if (this.disposed) return
70
- this.error = { code: 'browser-capability-unavailable', description }
71
- this.publish()
72
- }
73
-
74
- handleGuestReady(revision: number, pageId: string): void {
75
- if (this.disposed || this.navigation.snapshot.navigation.status === 'empty'
76
- || this.navigation.snapshot.navigation.revision !== revision) return
77
- this.carrier.set({ stage: 'ready', guestId: pageId })
78
- this.publish()
79
- }
80
-
81
- /** Accept metadata correlated to the current completed native load, without completing it again. */
82
- handleObserved(revision: number, observedUrl: string): void {
83
- if (this.disposed) return
84
- const navigation = this.navigation.snapshot.navigation
85
- if (navigation.status === 'empty' || navigation.status === 'loading' || navigation.revision !== revision) return
86
- const current = BrowserNavigation.current(this.navigation.snapshot)
87
- const target = toTarget(observedUrl, current?.title ?? '')
88
- if (target !== undefined) this.navigation.recordObserved(target)
89
- this.publish()
90
- }
91
-
92
- /**
93
- * Publish a failure only for the current document generation.
94
- * @param revision - document generation whose iframe reported failure.
95
- */
96
- handleLoadFailed(revision: number): void {
97
- if (this.disposed || this.navigation.snapshot.request?.revision !== revision) return
98
- this.error = { code: undefined, description: undefined }
99
- this.publish()
100
- }
101
-
102
- /** @returns immutable navigation state. */
103
- getSnapshot = (): BrowserFrameState => this.store.getSnapshot()
104
- /** @param listener - state invalidation. @returns unsubscribe callback. */
105
- subscribe = (listener: () => void): (() => void) => this.store.subscribe(listener)
106
-
107
- /** @param target - validated address; submitting the current address reloads it. */
108
- loadUrl(target: BrowserTarget, navigationId?: string): void {
109
- if (this.disposed) return
110
- this.navigationId = navigationId
111
- const request = BrowserNavigation.current(this.navigation.snapshot)?.url === target.url
112
- ? this.navigation.reload() : this.navigation.navigate(target)
113
- this.load(request)
114
- }
115
-
116
- /** Move back: app-known history first, then the iframe's own (page-internal) history. */
117
- goBack(): void {
118
- if (this.disposed) return
119
- if (this.navigation.canGoBack) { this.load(this.navigation.back()); return }
120
- this.frameHistoryForward = this.presentation.historyStep(-1) || this.frameHistoryForward
121
- this.publish()
122
- }
123
-
124
- /** Move forward: app-known history first, then the iframe's own (page-internal) history. */
125
- goForward(): void {
126
- if (this.disposed) return
127
- if (this.navigation.canGoForward) { this.load(this.navigation.forward()); return }
128
- if (this.presentation.historyStep(1)) this.frameHistoryForward = false
129
- this.publish()
130
- }
131
- /** Reload the last application-known address. */
132
- reload(): void { if (!this.disposed) this.load(this.navigation.reload()) }
133
-
134
- /** @returns after the presentation has been removed; repeated calls join disposal. */
135
- dispose(): Promise<void> {
136
- if (this.disposal !== undefined) return this.disposal
137
- this.disposed = true
138
- this.presentation.dispose()
139
- this.disposal = Promise.resolve()
140
- return this.disposal
141
- }
142
-
143
- private setSandbox(enabled: boolean): void {
144
- if (this.disposed || enabled === this.sandboxed) return
145
- this.sandboxed = enabled
146
- if (this.store.getSnapshot().target === undefined) {
147
- this.store.set({ ...this.store.getSnapshot(), sandboxEnabled: enabled })
148
- return
149
- }
150
- this.load(this.navigation.reload())
151
- }
152
-
153
- private load(request: ReturnType<BrowserNavigation['navigate']> | undefined): void {
154
- if (request === undefined) return
155
- this.frameHistoryForward = false
156
- this.error = undefined
157
- this.publish()
158
- this.presentation.show({ target: request.target, revision: request.revision, sandboxed: this.sandboxed })
159
- }
160
-
161
- private snapshot(): BrowserFrameState {
162
- const state = this.navigation.snapshot
163
- const target = BrowserNavigation.current(state)
164
- return { navigationId: this.navigationId, target, address: target === undefined ? 'empty' : state.navigation.status === 'unknown' ? 'unknown'
165
- : this.carrier.getSnapshot().stage === 'ready' ? 'observed' : 'requested',
166
- loading: state.navigation.status === 'loading' && this.error === undefined,
167
- canGoBack: this.navigation.canGoBack || this.presentation.historyDepth() > 1,
168
- canGoForward: this.navigation.canGoForward || this.frameHistoryForward,
169
- error: this.error, sandboxEnabled: this.sandboxed }
170
- }
171
-
172
- private publish(): void {
173
- this.store.set(this.snapshot())
174
- this.options.persist(this.navigation.snapshot)
175
- }
176
- }
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,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
+ }
@@ -4,7 +4,11 @@ import type { FrozenSnapshot } from '../reference/client/production/protocol.ts'
4
4
  import { iframeReferenceSource } from './iframe-reference.ts'
5
5
 
6
6
  class WebSourceHttpError extends Error {
7
- constructor(readonly status: number) { super(`web source channel failed (${status})`) }
7
+ readonly status: number
8
+ constructor(status: number) {
9
+ super(`web source channel failed (${status})`)
10
+ this.status = status
11
+ }
8
12
  }
9
13
 
10
14
  /** The authenticated app, not the opaque guest, owns this lease and its replies. */
@@ -1,30 +1,36 @@
1
- /** Static Browser tab type and guide declaration. */
2
- import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client'
3
- import type { TranslateNS } from '@deepseek-ai/dsh-client-locale/client'
4
- import { GuideArtworkBrowser } from '@deepseek-ai/dsh-client-ui-primitives'
5
- import type { SidebarRightTabDefinition } from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
6
- import type {} from './locales.ts'
7
-
8
- /** Browser tab kind. */
9
- export const BROWSER_KIND = 'browser'
10
-
11
- /** Browser implementation identity and keyed Slot dispatch key. */
12
- export const BROWSER_ID = '@deepseek-ai/dsh-client-ui-sidebar-browser'
13
-
14
- /** Build the Browser type with locale-live copy. */
15
- export function browserDefinition(t: TranslateNS<'sidebarBrowser'>): SidebarRightTabDefinition {
16
- return {
17
- id: BROWSER_ID,
18
- kind: BROWSER_KIND,
19
- // 单标签:`multiple: true` 会让宿主在每次 `openTabIn` 时铸一个新的 content id,
20
- // 于是「打开百度 → 搜索数独」变成新开一个标签、上一页被丢弃(用户实测报的就是这个)。
21
- // 浏览器标签按会话只有一个,新的地址在**原地**导航。
22
- multiple: false,
23
- priority: 'builtin',
24
- title: () => t('type.label'),
25
- guide: [{
26
- id: 'new', commandId: 'browser.new' as ShortcutCommandId, order: 30, title: () => t('guide.title'),
27
- description: () => t('guide.description'), icon: GuideArtworkBrowser,
28
- }],
29
- }
30
- }
1
+ /** Static Browser tab type and guide declaration. */
2
+ import type { ShortcutCommandId } from '@deepseek-ai/dsh-client-shortcuts/client'
3
+ import type { TranslateNS } from '@deepseek-ai/dsh-client-locale/client'
4
+ import { GuideArtworkBrowser } from '@deepseek-ai/dsh-client-ui-primitives'
5
+ import type { SidebarRightTabDefinition } from '@deepseek-ai/dsh-client-ui-sidebar-right/client'
6
+ import type { SIDEBAR_BROWSER_LOCALE_NS } from './locales.ts'
7
+
8
+ /** Browser tab kind. */
9
+ export const BROWSER_KIND = 'browser'
10
+
11
+ /**
12
+ * Plugin-owned Browser implementation identity and keyed Slot dispatch key.
13
+ * Distinct from DSH's built-in `@deepseek-ai/dsh-client-ui-sidebar-browser` so both
14
+ * can coexist when a user profile re-enables the built-in row (issue #107).
15
+ */
16
+ export const BROWSER_ID = 'dsh-builtin-browser'
17
+
18
+ /** Build the Browser type with locale-live copy. */
19
+ export function browserDefinition(t: TranslateNS<typeof SIDEBAR_BROWSER_LOCALE_NS>): SidebarRightTabDefinition {
20
+ return {
21
+ id: BROWSER_ID,
22
+ kind: BROWSER_KIND,
23
+ // 每次显式打开都新建一个标签:侧栏"浏览器"按钮/向导入口在已有页面时应当开新标签,而不是
24
+ // 把用户跳回旧页面(用户实测报的就是这个)。页内导航(地址栏、搜索结果、当前标签内跳转)
25
+ // 走 `loadUrl` 原地替换,不会额外开标签。
26
+ multiple: true,
27
+ // Extension band natively takes over DSH's `builtin` `browser` kind without throwing,
28
+ // and cleanly yields back to the built-in implementation if this plugin is removed.
29
+ priority: 'extension',
30
+ title: () => t('type.label'),
31
+ guide: [{
32
+ id: 'new', commandId: 'browser.new' as ShortcutCommandId, order: 30, title: () => t('guide.title'),
33
+ description: () => t('guide.description'), icon: GuideArtworkBrowser,
34
+ }],
35
+ }
36
+ }