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.
- package/CHANGELOG.md +55 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/tool-reference.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -44
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +16 -36
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +15 -12
- package/scripts/fix-exports.mjs +6 -16
- package/scripts/install-electron.mjs +55 -5
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +26 -15
- package/skills/dsh-builtin-browser/SKILL.md +27 -2
- package/skills/dsh-builtin-browser/references/batch.md +15 -0
- package/src/browser/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/runtime.ts +18 -0
- package/src/browser/takeover-target.ts +16 -7
- package/src/browser/types.ts +56 -3
- package/src/browser-electron/authenticated-route.ts +29 -4
- package/src/browser-electron/automatic-maintenance.ts +23 -13
- package/src/browser-electron/bridge-connection.ts +11 -10
- package/src/browser-electron/bridge-install.ts +2 -1
- package/src/browser-electron/bridge-status.ts +61 -22
- package/src/browser-electron/desktop-bridge-host.ts +9 -7
- package/src/browser-electron/desktop-identity.ts +38 -5
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/electron-provision.ts +104 -18
- package/src/browser-electron/entry.ts +1378 -1299
- package/src/browser-electron/extension-browser.ts +11 -4
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +3 -2
- package/src/browser-electron/guest-route.ts +180 -32
- package/src/browser-electron/guest-runtime.ts +61 -10
- package/src/browser-electron/guest-storage.ts +5 -2
- package/src/browser-electron/history-store.ts +3 -6
- package/src/browser-electron/host-main.ts +8 -4
- package/src/browser-electron/host-patch-maintenance.ts +18 -9
- package/src/browser-electron/maintenance-route.ts +2 -1
- package/src/browser-electron/missing-system-browser.ts +11 -10
- package/src/browser-electron/preferred-browser.ts +13 -3
- package/src/browser-electron/preview-route.ts +9 -12
- package/src/browser-electron/process-ownership.ts +9 -3
- package/src/browser-electron/profile-command.ts +2 -1
- package/src/browser-electron/profile-extension.ts +5 -0
- package/src/browser-electron/profile-lease.ts +131 -35
- package/src/browser-electron/provider-core.ts +1107 -0
- package/src/browser-electron/provider-interaction.ts +1034 -0
- package/src/browser-electron/provider-media.ts +589 -0
- package/src/browser-electron/provider-navigation.ts +323 -0
- package/src/browser-electron/provider-observation.ts +664 -0
- package/src/browser-electron/provider-tabs.ts +372 -0
- package/src/browser-electron/provider.ts +158 -4063
- package/src/browser-electron/reference-route.ts +598 -608
- package/src/browser-electron/remote-host.ts +118 -42
- package/src/browser-electron/runtime-status.ts +80 -13
- package/src/browser-electron/settings-store.ts +10 -6
- package/src/browser-electron/sidebar-only-host.ts +4 -2
- package/src/browser-electron/system-browser.ts +537 -184
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/virtual-cursor.ts +24 -14
- package/src/browser-reference/service.ts +38 -7
- package/src/browser-reference/web-sources.ts +4 -1
- package/src/client/apply-guard.ts +22 -0
- package/src/client/browser/BrowserController.ts +3 -3
- package/src/client/browser/IframeImpl.ts +182 -176
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -0
- package/src/client/browser/web-reference-source.ts +5 -1
- package/src/client/definition.tsx +36 -30
- package/src/client/electron/ElectronWebViewImpl.ts +20 -13
- package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
- package/src/client/electron/NativeChildPresentation.ts +11 -3
- package/src/client/electron/NativeViewPage.ts +19 -5
- package/src/client/index.ts +333 -293
- package/src/client/locales.ts +9 -6
- package/src/client/reference/client/plugin.ts +21 -2
- package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
- package/src/client/reference/client/production/assembly.ts +4 -28
- package/src/client/reference/client/production/availability.ts +0 -2
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/draft-adapter.ts +4 -0
- package/src/client/reference/client/production/http-transport.ts +0 -5
- package/src/client/reference/client/production/production-submission.ts +50 -290
- package/src/client/reference/client/production/protocol.ts +7 -4
- package/src/client/reference/client/production/runtime.ts +41 -86
- package/src/client/reference/client/production/source-marker.ts +49 -13
- package/src/client/reference/client/production/user-text-rule.ts +10 -1
- package/src/client/reference/client/reveal.ts +3 -1
- package/src/client/reference/client/session-schedule.ts +36 -0
- package/src/client/settings/index.ts +8 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +163 -52
- package/src/client/startpage/controller.ts +3 -6
- package/src/client/view/BrowserBody.tsx +2 -1
- package/src/client/view/IframePresentation.ts +37 -16
- package/src/client/view/StartPage.tsx +2 -1
- package/src/compat/host-features.ts +92 -0
- package/src/reference-source.ts +1 -1
- package/src/reference-text.ts +23 -1
- package/src/takeover-protocol.ts +11 -2
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +173 -19
- package/src/tool-browser/code-worker.ts +101 -15
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +66 -3534
- package/src/tool-browser/page-probe.ts +229 -28
- package/src/tool-browser/panel-page.ts +3 -1
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +3 -2
- package/src/tool-browser/tools-debug.ts +806 -0
- package/src/tool-browser/tools-interaction.ts +956 -0
- package/src/tool-browser/tools-navigation.ts +786 -0
- package/src/tool-browser/tools-observation.ts +474 -0
- package/src/tool-browser/tools-reference.ts +294 -0
- package/src/web-guest.ts +35 -34
- package/dist/client.cjs +0 -43167
- package/dist/client.d.cts +0 -516
- package/dist/client.d.mts +0 -516
- package/dist/index.cjs +0 -92
- package/dist/index.d.mts +0 -2960
- package/dist/index.mjs +0 -24
- package/lib/browser-reference/submission-receipts.js +0 -139
- 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
|
|
4
|
-
import
|
|
5
|
-
import type
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @param
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
readonly
|
|
29
|
-
|
|
30
|
-
private readonly
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
private
|
|
34
|
-
private
|
|
35
|
-
private
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/** @param
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.disposal
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
+
}
|