dsh-builtin-browser 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -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/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +218 -0
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +260 -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 +15 -53
- package/README.en.md +0 -89
- package/browser-extension/constants.mjs +0 -20
- package/browser-extension/controller.mjs +0 -293
- package/browser-extension/locales.mjs +0 -15
- package/browser-extension/manifest.json +0 -12
- package/browser-extension/options.html +0 -14
- package/browser-extension/options.mjs +0 -9
- package/browser-extension/permission-guard.mjs +0 -13
- package/browser-extension/worker.mjs +0 -74
- package/dist/client.cjs +0 -43167
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/scripts/build.mjs +0 -66
- package/scripts/bundle-host.mjs +0 -28
- package/scripts/fix-exports.mjs +0 -50
- package/scripts/install-electron.mjs +0 -51
- package/scripts/verify-exports.mjs +0 -47
- package/scripts/verify-preview-sdk.mjs +0 -93
- package/skills/dsh-builtin-browser/SKILL.md +0 -73
- package/skills/dsh-builtin-browser/references/batch.md +0 -53
- package/skills/dsh-builtin-browser/references/deliver.md +0 -31
- package/skills/dsh-builtin-browser/references/locate.md +0 -11
- package/skills/dsh-builtin-browser/references/recover.md +0 -11
- package/skills/dsh-builtin-browser/references/verify.md +0 -13
- package/skills/dsh-debug-host/SKILL.md +0 -56
- package/skills/dsh-debug-self/SKILL.md +0 -50
- package/src/bridge-compatibility.ts +0 -39
- package/src/browser/handles.ts +0 -89
- package/src/browser/runtime.ts +0 -560
- package/src/browser/takeover-target.ts +0 -36
- package/src/browser/types.ts +0 -817
- package/src/browser-electron/authenticated-route.ts +0 -84
- package/src/browser-electron/automatic-maintenance.ts +0 -726
- package/src/browser-electron/bridge-auto.ts +0 -159
- package/src/browser-electron/bridge-connection.ts +0 -385
- package/src/browser-electron/bridge-endpoint.ts +0 -129
- package/src/browser-electron/bridge-install.ts +0 -289
- package/src/browser-electron/bridge-maintenance.ts +0 -189
- package/src/browser-electron/bridge-status.ts +0 -347
- package/src/browser-electron/desktop-bridge-host.ts +0 -251
- package/src/browser-electron/desktop-identity.ts +0 -320
- package/src/browser-electron/document-readiness.ts +0 -45
- package/src/browser-electron/electron-provision.ts +0 -261
- package/src/browser-electron/entry.ts +0 -1299
- package/src/browser-electron/ephemeral-profile.ts +0 -189
- package/src/browser-electron/extension-browser.ts +0 -223
- package/src/browser-electron/extension-setup.ts +0 -67
- package/src/browser-electron/file-write.ts +0 -31
- package/src/browser-electron/guest-cookie-jar.ts +0 -176
- package/src/browser-electron/guest-cookie-store.ts +0 -59
- package/src/browser-electron/guest-css-runtime.ts +0 -76
- package/src/browser-electron/guest-css.ts +0 -68
- package/src/browser-electron/guest-route.ts +0 -568
- package/src/browser-electron/guest-runtime.ts +0 -357
- package/src/browser-electron/guest-storage-runtime.ts +0 -54
- package/src/browser-electron/guest-storage.ts +0 -117
- package/src/browser-electron/history-store.ts +0 -227
- package/src/browser-electron/host-main.ts +0 -1381
- package/src/browser-electron/host-patch-maintenance.ts +0 -112
- package/src/browser-electron/http-body.ts +0 -65
- package/src/browser-electron/json-reply.ts +0 -47
- package/src/browser-electron/maintenance-broker.ts +0 -166
- package/src/browser-electron/maintenance-lifecycle.ts +0 -91
- package/src/browser-electron/maintenance-route.ts +0 -67
- package/src/browser-electron/missing-system-browser.ts +0 -113
- package/src/browser-electron/open-slot.ts +0 -49
- package/src/browser-electron/paths.ts +0 -25
- package/src/browser-electron/preferred-browser.ts +0 -120
- package/src/browser-electron/preview-route.ts +0 -218
- package/src/browser-electron/process-ownership.ts +0 -168
- package/src/browser-electron/process.ts +0 -23
- package/src/browser-electron/profile-checkpoint.ts +0 -187
- package/src/browser-electron/profile-command.ts +0 -46
- package/src/browser-electron/profile-extension.ts +0 -124
- package/src/browser-electron/profile-lease.ts +0 -115
- package/src/browser-electron/profile-residue.ts +0 -49
- package/src/browser-electron/provider.ts +0 -4571
- package/src/browser-electron/reference-route.ts +0 -608
- package/src/browser-electron/remote-host.ts +0 -1462
- package/src/browser-electron/rpc-input.ts +0 -13
- package/src/browser-electron/rpc-ops.ts +0 -41
- package/src/browser-electron/runtime-diagnostics.ts +0 -38
- package/src/browser-electron/runtime-route.ts +0 -105
- package/src/browser-electron/runtime-status.ts +0 -242
- package/src/browser-electron/settings-route.ts +0 -64
- package/src/browser-electron/settings-store.ts +0 -589
- package/src/browser-electron/shortcuts-route.ts +0 -112
- package/src/browser-electron/sidebar-only-host.ts +0 -298
- package/src/browser-electron/startpage-shortcuts.ts +0 -213
- package/src/browser-electron/system-browser.ts +0 -1497
- package/src/browser-electron/timing.ts +0 -16
- package/src/browser-electron/virtual-cursor.ts +0 -152
- package/src/browser-electron/windows-system.ts +0 -24
- package/src/browser-reference/delivery.ts +0 -384
- package/src/browser-reference/entry.ts +0 -631
- package/src/browser-reference/export.ts +0 -339
- package/src/browser-reference/import.ts +0 -303
- package/src/browser-reference/page-script.ts +0 -1537
- package/src/browser-reference/service.ts +0 -1315
- package/src/browser-reference/store.ts +0 -172
- package/src/browser-reference/submission-receipts.ts +0 -122
- package/src/browser-reference/text-quote.ts +0 -219
- package/src/browser-reference/types.ts +0 -195
- package/src/browser-reference/visible.ts +0 -367
- package/src/browser-reference/web-sources.ts +0 -103
- package/src/client/browser/BrowserController.ts +0 -693
- package/src/client/browser/BrowserFrame.ts +0 -78
- package/src/client/browser/BrowserNavigation.ts +0 -169
- package/src/client/browser/BrowserPage.ts +0 -23
- package/src/client/browser/BrowserPersistence.ts +0 -44
- package/src/client/browser/IframeImpl.ts +0 -176
- package/src/client/browser/child-tabs.ts +0 -14
- package/src/client/browser/iframe-reference.ts +0 -67
- package/src/client/browser/initialization.ts +0 -262
- package/src/client/browser/omnibox.ts +0 -243
- package/src/client/browser/store.ts +0 -38
- package/src/client/browser/takeover-channel.ts +0 -72
- package/src/client/browser/url.ts +0 -46
- package/src/client/browser/web-reference-source.ts +0 -52
- package/src/client/css-modules.d.ts +0 -4
- package/src/client/definition.tsx +0 -30
- package/src/client/electron/ElectronWebViewImpl.ts +0 -364
- package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
- package/src/client/electron/NativeChildPresentation.ts +0 -45
- package/src/client/electron/NativeViewPage.ts +0 -251
- package/src/client/electron/pages.ts +0 -23
- package/src/client/electron/reference-overlay.ts +0 -53
- package/src/client/electron/workspace.ts +0 -33
- package/src/client/index.ts +0 -293
- package/src/client/locales.ts +0 -857
- package/src/client/pages.ts +0 -28
- package/src/client/reference/client/BrowserRefLink.tsx +0 -142
- package/src/client/reference/client/draft-reference.ts +0 -167
- package/src/client/reference/client/index.ts +0 -7
- package/src/client/reference/client/ordered-submission.ts +0 -108
- package/src/client/reference/client/pending-delivery.ts +0 -216
- package/src/client/reference/client/plugin.ts +0 -189
- package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
- package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
- package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
- package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
- package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
- package/src/client/reference/client/production/ReferenceText.tsx +0 -36
- package/src/client/reference/client/production/assembly.ts +0 -471
- package/src/client/reference/client/production/asset-store.ts +0 -144
- package/src/client/reference/client/production/availability.ts +0 -74
- package/src/client/reference/client/production/bytes.ts +0 -36
- package/src/client/reference/client/production/delivery-client.ts +0 -211
- package/src/client/reference/client/production/draft-adapter.ts +0 -508
- package/src/client/reference/client/production/http-transport.ts +0 -217
- package/src/client/reference/client/production/production-submission.ts +0 -310
- package/src/client/reference/client/production/protocol.ts +0 -231
- package/src/client/reference/client/production/reference-card.ts +0 -240
- package/src/client/reference/client/production/reference-labels.ts +0 -29
- package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
- package/src/client/reference/client/production/reveal.ts +0 -215
- package/src/client/reference/client/production/runtime.ts +0 -1101
- package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
- package/src/client/reference/client/production/source-marker.ts +0 -63
- package/src/client/reference/client/production/source-opener.ts +0 -55
- package/src/client/reference/client/production/styles.ts +0 -104
- package/src/client/reference/client/production/user-text-rule.ts +0 -58
- package/src/client/reference/client/reveal.ts +0 -107
- package/src/client/reference/client/scheme.ts +0 -114
- package/src/client/reference/client/types.ts +0 -168
- package/src/client/reference/css-modules.d.ts +0 -4
- package/src/client/reference/index.ts +0 -11
- package/src/client/reference-capture-owner.ts +0 -162
- package/src/client/reference-intents.ts +0 -36
- package/src/client/settings/index.ts +0 -34
- package/src/client/settings/panel.ts +0 -2657
- package/src/client/shortcut-open.ts +0 -30
- package/src/client/startpage/binding.ts +0 -99
- package/src/client/startpage/controller.ts +0 -303
- package/src/client/startpage/model.ts +0 -279
- package/src/client/view/Browser.module.css +0 -751
- package/src/client/view/BrowserBody.tsx +0 -314
- package/src/client/view/BrowserPresentation.ts +0 -9
- package/src/client/view/BrowserTitle.tsx +0 -17
- package/src/client/view/IframePresentation.ts +0 -344
- package/src/client/view/StartPage.tsx +0 -597
- package/src/client/view/TakeoverBanner.tsx +0 -21
- package/src/index.ts +0 -110
- package/src/reference-owner.ts +0 -5
- package/src/reference-page.ts +0 -9
- package/src/reference-source.ts +0 -3
- package/src/reference-text.ts +0 -197
- package/src/startpage-settings.ts +0 -103
- package/src/startpage.ts +0 -71
- package/src/takeover-protocol.ts +0 -19
- package/src/tool-browser/code-tool.ts +0 -401
- package/src/tool-browser/code-worker.ts +0 -639
- package/src/tool-browser/element-fields.ts +0 -167
- package/src/tool-browser/index.ts +0 -3733
- package/src/tool-browser/page-probe.ts +0 -474
- package/src/tool-browser/panel-page.ts +0 -124
- package/src/tool-browser/screenshot-image.ts +0 -49
- package/src/tool-browser/takeover.ts +0 -198
- package/src/types/electron-shim.d.ts +0 -144
- package/src/types.ts +0 -85
- package/src/web-guest.ts +0 -34
- package/tools/accept-desktop.mjs +0 -148
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What proves a directory is a DSH Desktop install.
|
|
3
|
-
*
|
|
4
|
-
* Reported as issue #40. Every reader of an install directory used to accept a *generic* Electron
|
|
5
|
-
* layout (`resources/app/lib/main.js` or `resources/app.asar`) as proof, and that is not proof of
|
|
6
|
-
* anything: any Electron app has it. The consequence was measured — a throwaway app in a temp
|
|
7
|
-
* directory, whose own package.json said `unrelated-meeting-app`, was accepted by discovery, got a
|
|
8
|
-
* "bridge not installed" verdict with a ready-to-run installer command aimed at it, and (with that
|
|
9
|
-
* command) had its entry file rewritten and the bridge copied in.
|
|
10
|
-
*
|
|
11
|
-
* So identity is one rule, in one file (`desktop-bridge/desktop-identity.json`), read by both the
|
|
12
|
-
* installer and this module. Nothing else may decide what a DSH Desktop install is.
|
|
13
|
-
*
|
|
14
|
-
* Two properties are load-bearing and are why this is not a one-line `name ===` check:
|
|
15
|
-
*
|
|
16
|
-
* - **The archive wins.** Electron loads `resources/app.asar` in preference to `resources/app`, and
|
|
17
|
-
* a desktop update leaves the old extraction lying around. Reading identity from the extraction
|
|
18
|
-
* while the archive holds a different build would verify the wrong bytes, so when the archive is
|
|
19
|
-
* present that is what is read — and the sibling directory is not consulted at all.
|
|
20
|
-
* - **Unreadable means not DSH.** Every failure path (missing file, truncated pickle, unsupported
|
|
21
|
-
* archive version, malformed JSON, unreadable name) refuses. There is no "assume yes" branch: the
|
|
22
|
-
* caller is about to write into, or delete from, this directory.
|
|
23
|
-
* @module dsh-browser/browser-electron/desktop-identity
|
|
24
|
-
*/
|
|
25
|
-
import { closeSync, existsSync, openSync, readFileSync, readSync } from 'node:fs'
|
|
26
|
-
import { createRequire } from 'node:module'
|
|
27
|
-
import { join } from 'node:path'
|
|
28
|
-
|
|
29
|
-
// Electron's patched fs opens an ASAR as a virtual directory. Identity needs the raw archive
|
|
30
|
-
// header and file offsets, including when this reader runs in the Desktop's Node-mode worker.
|
|
31
|
-
const archiveFs: Pick<typeof import('node:fs'), 'openSync' | 'readSync' | 'closeSync' | 'existsSync'> = (() => {
|
|
32
|
-
try { return createRequire(import.meta.url)('original-fs') as typeof import('node:fs') }
|
|
33
|
-
catch { return { openSync, readSync, closeSync, existsSync } }
|
|
34
|
-
})()
|
|
35
|
-
|
|
36
|
-
/** The identity rule, as data. */
|
|
37
|
-
/** Where one kind of install keeps its resources, executable and CLI launcher (all relative). */
|
|
38
|
-
export interface DesktopLayout {
|
|
39
|
-
readonly name: string
|
|
40
|
-
/** The layout applies when this path exists under the install root; the default has none. */
|
|
41
|
-
readonly marker?: string
|
|
42
|
-
readonly resources: string
|
|
43
|
-
readonly executable: string
|
|
44
|
-
readonly cliLauncher: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface IdentityRule {
|
|
48
|
-
readonly packageNames: readonly string[]
|
|
49
|
-
readonly mainEntry: string
|
|
50
|
-
readonly layouts: readonly DesktopLayout[]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The rule shipped in `desktop-bridge/desktop-identity.json`, used when the file cannot be read.
|
|
55
|
-
*
|
|
56
|
-
* A copy exists here only as a fallback for a broken package layout; the test suite asserts that it
|
|
57
|
-
* equals the JSON, so the two can never drift apart silently.
|
|
58
|
-
*/
|
|
59
|
-
export const FALLBACK_RULE: IdentityRule = {
|
|
60
|
-
packageNames: ['@deepseek-ai/dsh-desktop', 'dsh-desktop'],
|
|
61
|
-
mainEntry: 'lib/main.js',
|
|
62
|
-
layouts: [
|
|
63
|
-
{ name: 'macos-bundle', marker: 'Contents/Info.plist', resources: 'Contents/Resources', executable: 'Contents/MacOS/DeepSeek Harness', cliLauncher: 'runtime/cli/bin/dsh' },
|
|
64
|
-
{ name: 'directory', resources: 'resources', executable: 'DeepSeek Harness.exe', cliLauncher: 'runtime/cli/bin/dsh.cmd' },
|
|
65
|
-
],
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** A verified install. */
|
|
69
|
-
export interface DesktopIdentity {
|
|
70
|
-
readonly ok: true
|
|
71
|
-
/** The install root that was verified. */
|
|
72
|
-
readonly root: string
|
|
73
|
-
/** Which shape was verified — the archive when it exists, the extraction only without one. */
|
|
74
|
-
readonly layout: 'packed' | 'unpacked'
|
|
75
|
-
/** `name` from the package the caller will actually run. */
|
|
76
|
-
readonly packageName: string
|
|
77
|
-
/** `version`, when the package declares one. */
|
|
78
|
-
readonly version?: string
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** A refusal, with a reason a human can act on. */
|
|
82
|
-
export interface IdentityRefusal {
|
|
83
|
-
readonly ok: false
|
|
84
|
-
readonly reason: string
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Read the identity rule.
|
|
89
|
-
*
|
|
90
|
-
* Resolved relative to this module, which in both the repository and the published tarball puts
|
|
91
|
-
* `desktop-bridge/` beside `lib/`. A missing file is not fatal — the fallback is the same rule —
|
|
92
|
-
* but a *malformed* one is an error the caller should not ignore, so it is reported through the
|
|
93
|
-
* refusal path rather than silently swapped for the fallback.
|
|
94
|
-
* @returns the rule, or an error string.
|
|
95
|
-
*/
|
|
96
|
-
export function readIdentityRule(): IdentityRule | { readonly error: string } {
|
|
97
|
-
try {
|
|
98
|
-
const path = new URL('../../desktop-bridge/desktop-identity.json', import.meta.url)
|
|
99
|
-
const raw = JSON.parse(readFileSync(path, 'utf8')) as Partial<IdentityRule>
|
|
100
|
-
const names = raw.packageNames
|
|
101
|
-
const main = raw.mainEntry
|
|
102
|
-
if (!Array.isArray(names) || names.length === 0 || names.some(n => typeof n !== 'string')) {
|
|
103
|
-
return { error: 'desktop-identity.json: packageNames must be a non-empty array of strings' }
|
|
104
|
-
}
|
|
105
|
-
if (typeof main !== 'string' || main === '') {
|
|
106
|
-
return { error: 'desktop-identity.json: mainEntry must be a non-empty string' }
|
|
107
|
-
}
|
|
108
|
-
const layouts = raw.layouts
|
|
109
|
-
const field = (value: unknown): boolean => typeof value === 'string' && value !== ''
|
|
110
|
-
if (!Array.isArray(layouts) || layouts.length === 0
|
|
111
|
-
|| layouts.some(l => l === null || typeof l !== 'object' || !field(l.name) || !field(l.resources) || !field(l.executable) || !field(l.cliLauncher)
|
|
112
|
-
|| (l.marker !== undefined && !field(l.marker)))
|
|
113
|
-
|| layouts[layouts.length - 1]?.marker !== undefined) {
|
|
114
|
-
return { error: 'desktop-identity.json: layouts must be a non-empty array whose last entry has no marker' }
|
|
115
|
-
}
|
|
116
|
-
return { packageNames: names, mainEntry: main, layouts }
|
|
117
|
-
} catch (error) {
|
|
118
|
-
if (error instanceof Error && 'code' in error && (error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
119
|
-
return FALLBACK_RULE
|
|
120
|
-
}
|
|
121
|
-
return { error: `desktop-identity.json could not be read: ${String(error)}` }
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function layoutOf(rule: IdentityRule, installRoot: string): DesktopLayout {
|
|
126
|
-
return rule.layouts.find(layout => layout.marker === undefined || existsSync(join(installRoot, ...layout.marker.split('/'))))
|
|
127
|
-
?? rule.layouts[rule.layouts.length - 1] as DesktopLayout
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* The layout of an install root: a macOS `.app` bundle or a plain directory (Windows).
|
|
132
|
-
* Decided by the install's own shape rather than the host OS, so every platform reads it the same.
|
|
133
|
-
* @param installRoot - the install directory.
|
|
134
|
-
* @returns the layout, or an error when the identity rule cannot be read.
|
|
135
|
-
*/
|
|
136
|
-
export function desktopLayout(installRoot: string): DesktopLayout | { readonly error: string } {
|
|
137
|
-
const rule = readIdentityRule()
|
|
138
|
-
return 'error' in rule ? rule : layoutOf(rule, installRoot)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Absolute paths an install keeps, from its layout.
|
|
143
|
-
* @param installRoot - the install directory.
|
|
144
|
-
* @returns resources directory, GUI executable and CLI launcher.
|
|
145
|
-
*/
|
|
146
|
-
export function desktopPaths(installRoot: string): { readonly resources: string; readonly executable: string; readonly cliLauncher: string } {
|
|
147
|
-
const layout = desktopLayout(installRoot)
|
|
148
|
-
if ('error' in layout) throw new Error(layout.error)
|
|
149
|
-
const resources = join(installRoot, ...layout.resources.split('/'))
|
|
150
|
-
return { resources, executable: join(installRoot, ...layout.executable.split('/')), cliLauncher: join(resources, ...layout.cliLauncher.split('/')) }
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* One entry of a Chromium pickle header.
|
|
155
|
-
*
|
|
156
|
-
* `offset` is relative to the content area that follows the header; `unpacked` entries carry no
|
|
157
|
-
* bytes in the archive and live beside it instead.
|
|
158
|
-
*/
|
|
159
|
-
interface AsarEntry {
|
|
160
|
-
readonly size: number
|
|
161
|
-
readonly offset?: string
|
|
162
|
-
readonly unpacked?: boolean
|
|
163
|
-
readonly files?: Record<string, AsarEntry>
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Parse an asar header, the same way the installer does.
|
|
168
|
-
*
|
|
169
|
-
* Layout, for the next reader: an 8-byte outer pickle (`[size][jsonLength]`), then the header
|
|
170
|
-
* pickle whose first 4 bytes are the JSON length, then the JSON tree. File content starts right
|
|
171
|
-
* after the header pickle.
|
|
172
|
-
* @param archive - the archive path.
|
|
173
|
-
* @returns the header tree and the offset where content starts, or an error string.
|
|
174
|
-
*/
|
|
175
|
-
function readAsarHeader(archive: string): { header: { files?: Record<string, AsarEntry> }; contentBase: number } | { error: string } {
|
|
176
|
-
let fd: number | undefined
|
|
177
|
-
try {
|
|
178
|
-
fd = archiveFs.openSync(archive, 'r')
|
|
179
|
-
const outer = Buffer.alloc(8)
|
|
180
|
-
if (archiveFs.readSync(fd, outer, 0, 8, 0) !== 8) return { error: 'the archive header is truncated' }
|
|
181
|
-
const headerSize = outer.readUInt32LE(4)
|
|
182
|
-
if (headerSize < 8 || headerSize > 64 * 1024 * 1024) return { error: `implausible archive header size (${headerSize})` }
|
|
183
|
-
const header = Buffer.alloc(headerSize)
|
|
184
|
-
if (archiveFs.readSync(fd, header, 0, headerSize, 8) !== headerSize) return { error: 'the archive header is truncated' }
|
|
185
|
-
const jsonLength = header.readUInt32LE(4)
|
|
186
|
-
if (jsonLength <= 0 || jsonLength > headerSize - 8) return { error: 'the archive header has an implausible JSON length' }
|
|
187
|
-
return { header: JSON.parse(header.toString('utf8', 8, 8 + jsonLength)), contentBase: 8 + headerSize }
|
|
188
|
-
} catch (error) {
|
|
189
|
-
return { error: `the archive header could not be read: ${String(error)}` }
|
|
190
|
-
} finally {
|
|
191
|
-
if (fd !== undefined) {
|
|
192
|
-
try { archiveFs.closeSync(fd) } catch { /* already closed */ }
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Walk a slash-separated path inside an asar header tree.
|
|
199
|
-
* @param tree - the header's `files` node.
|
|
200
|
-
* @param path - e.g. `lib/main.js`.
|
|
201
|
-
* @returns the entry, or undefined when the path does not exist.
|
|
202
|
-
*/
|
|
203
|
-
function entryAt(tree: Record<string, AsarEntry> | undefined, path: string): AsarEntry | undefined {
|
|
204
|
-
let node: AsarEntry | undefined
|
|
205
|
-
let files: Record<string, AsarEntry> | undefined = tree
|
|
206
|
-
for (const part of path.split('/')) {
|
|
207
|
-
if (files === undefined) return undefined
|
|
208
|
-
node = files[part]
|
|
209
|
-
if (node === undefined) return undefined
|
|
210
|
-
files = node.files
|
|
211
|
-
}
|
|
212
|
-
return node
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Read one file out of an asar archive without extracting the tree.
|
|
217
|
-
* @param archive - the archive path.
|
|
218
|
-
* @param path - a slash-separated path inside the archive.
|
|
219
|
-
* @returns the bytes, or undefined when the entry is absent or unreadable.
|
|
220
|
-
*/
|
|
221
|
-
export function readAsarFile(archive: string, path: string): Buffer | undefined {
|
|
222
|
-
const parsed = readAsarHeader(archive)
|
|
223
|
-
if ('error' in parsed) return undefined
|
|
224
|
-
const entry = entryAt(parsed.header.files, path)
|
|
225
|
-
if (entry === undefined || entry.files !== undefined || entry.unpacked === true) return undefined
|
|
226
|
-
if (typeof entry.offset !== 'string' || typeof entry.size !== 'number' || entry.size < 0) return undefined
|
|
227
|
-
let fd: number | undefined
|
|
228
|
-
try {
|
|
229
|
-
fd = archiveFs.openSync(archive, 'r')
|
|
230
|
-
const buffer = Buffer.alloc(entry.size)
|
|
231
|
-
const read = archiveFs.readSync(fd, buffer, 0, entry.size, parsed.contentBase + Number(entry.offset))
|
|
232
|
-
return read === entry.size ? buffer : undefined
|
|
233
|
-
} catch {
|
|
234
|
-
return undefined
|
|
235
|
-
} finally {
|
|
236
|
-
if (fd !== undefined) {
|
|
237
|
-
try { archiveFs.closeSync(fd) } catch { /* already closed */ }
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Whether an install directory is DSH Desktop.
|
|
244
|
-
*
|
|
245
|
-
* Everything the caller does next (stop the app, delete a tree, extract, rename, write) depends on
|
|
246
|
-
* this being right, so every uncertainty resolves to a refusal that names what was found.
|
|
247
|
-
* @param installRoot - the directory a user or the discovery probe named.
|
|
248
|
-
* @returns the verified identity, or a refusal with a reason.
|
|
249
|
-
*/
|
|
250
|
-
export function readDesktopIdentity(installRoot: string): DesktopIdentity | IdentityRefusal {
|
|
251
|
-
const rule = readIdentityRule()
|
|
252
|
-
if ('error' in rule) return { ok: false, reason: rule.error }
|
|
253
|
-
const resources = join(installRoot, ...layoutOf(rule, installRoot).resources.split('/'))
|
|
254
|
-
const appDir = join(resources, 'app')
|
|
255
|
-
const archive = join(resources, 'app.asar')
|
|
256
|
-
|
|
257
|
-
let archivePresent: boolean
|
|
258
|
-
try {
|
|
259
|
-
archivePresent = archiveFs.existsSync(archive)
|
|
260
|
-
} catch {
|
|
261
|
-
return { ok: false, reason: `cannot inspect ${archive}` }
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const layout: 'packed' | 'unpacked' = archivePresent ? 'packed' : 'unpacked'
|
|
265
|
-
let manifestText: string | undefined
|
|
266
|
-
let mainPresent: boolean
|
|
267
|
-
if (archivePresent) {
|
|
268
|
-
const parsed = readAsarHeader(archive)
|
|
269
|
-
if ('error' in parsed) {
|
|
270
|
-
return { ok: false, reason: `${archive} could not be read: ${parsed.error}` }
|
|
271
|
-
}
|
|
272
|
-
const manifest = entryAt(parsed.header.files, 'package.json')
|
|
273
|
-
if (manifest === undefined || manifest.files !== undefined || manifest.unpacked === true) {
|
|
274
|
-
return { ok: false, reason: `${archive} has no plain package.json; an archive without one is not proof of identity` }
|
|
275
|
-
}
|
|
276
|
-
manifestText = readAsarFile(archive, 'package.json')?.toString('utf8')
|
|
277
|
-
if (manifestText === undefined) {
|
|
278
|
-
return { ok: false, reason: `${archive}: package.json is listed but its bytes cannot be read` }
|
|
279
|
-
}
|
|
280
|
-
mainPresent = entryAt(parsed.header.files, rule.mainEntry) !== undefined
|
|
281
|
-
} else {
|
|
282
|
-
const manifestPath = join(appDir, 'package.json')
|
|
283
|
-
try {
|
|
284
|
-
manifestText = readFileSync(manifestPath, 'utf8')
|
|
285
|
-
} catch (error) {
|
|
286
|
-
console.error(`[dsh-browser] cannot read the package manifest at ${manifestPath}: ${String(error)}`)
|
|
287
|
-
return { ok: false, reason: `${manifestPath} is missing; a directory without a package manifest is not a DSH Desktop install` }
|
|
288
|
-
}
|
|
289
|
-
mainPresent = existsSync(join(appDir, ...rule.mainEntry.split('/')))
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
let manifest: { name?: unknown; version?: unknown }
|
|
293
|
-
try {
|
|
294
|
-
manifest = JSON.parse(manifestText) as { name?: unknown; version?: unknown }
|
|
295
|
-
} catch {
|
|
296
|
-
return { ok: false, reason: 'the package manifest is not valid JSON' }
|
|
297
|
-
}
|
|
298
|
-
const name = typeof manifest.name === 'string' ? manifest.name : ''
|
|
299
|
-
if (!rule.packageNames.includes(name)) {
|
|
300
|
-
return {
|
|
301
|
-
ok: false,
|
|
302
|
-
reason: `the app calls itself ${name === '' ? '(no name)' : JSON.stringify(name)}, which is not one of `
|
|
303
|
-
+ `${rule.packageNames.join(' / ')} — refusing to touch a different application`,
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// The main entry is the file the installer patches and the shell runs; if it is not there, this
|
|
308
|
-
// is not an install this plugin can reason about even though the manifest looks right.
|
|
309
|
-
if (!mainPresent) {
|
|
310
|
-
return { ok: false, reason: `${rule.mainEntry} is not present under ${archivePresent ? archive : appDir}` }
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return {
|
|
314
|
-
ok: true,
|
|
315
|
-
root: installRoot,
|
|
316
|
-
layout,
|
|
317
|
-
packageName: name,
|
|
318
|
-
...typeof manifest.version === 'string' ? { version: manifest.version } : {},
|
|
319
|
-
}
|
|
320
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { BrowserError } from '../browser/types.ts'
|
|
2
|
-
import type { ElectronViewHandle } from './provider.ts'
|
|
3
|
-
|
|
4
|
-
export interface DocumentIdentity {
|
|
5
|
-
readonly id: string
|
|
6
|
-
readonly loaderId: string
|
|
7
|
-
readonly url: string
|
|
8
|
-
readonly unreachableUrl?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function mainDocument(value: unknown, options?: { readonly allowErrorDocument?: boolean }): DocumentIdentity {
|
|
12
|
-
const frame = (value as { frameTree?: { frame?: DocumentIdentity } } | undefined)?.frameTree?.frame
|
|
13
|
-
if (typeof frame?.id !== 'string' || frame.id === ''
|
|
14
|
-
|| typeof frame.loaderId !== 'string' || frame.loaderId === '' || typeof frame.url !== 'string') {
|
|
15
|
-
throw new BrowserError('browser: the guest did not acknowledge its main document identity', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
|
|
16
|
-
}
|
|
17
|
-
if (frame.unreachableUrl && options?.allowErrorDocument !== true) {
|
|
18
|
-
throw new BrowserError(`browser: failed to load ${frame.unreachableUrl}`, 'BROWSER_NAVIGATION_FAILED')
|
|
19
|
-
}
|
|
20
|
-
return frame
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Check parse readiness in an isolated world bound to the acknowledged main frame. */
|
|
24
|
-
export async function documentReady(handle: ElectronViewHandle, expected: DocumentIdentity, checkCurrent = (): void => {}): Promise<boolean> {
|
|
25
|
-
checkCurrent()
|
|
26
|
-
const world = await handle.sendCommand('Page.createIsolatedWorld', { frameId: expected.id, worldName: 'dsh-browser-readiness' }, { present: false, initialize: false }) as { executionContextId?: number }
|
|
27
|
-
checkCurrent()
|
|
28
|
-
if (!Number.isSafeInteger(world?.executionContextId) || world.executionContextId! <= 0) {
|
|
29
|
-
throw new BrowserError('browser: the guest did not acknowledge a document execution context', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
|
|
30
|
-
}
|
|
31
|
-
const result = await handle.sendCommand('Runtime.evaluate', {
|
|
32
|
-
expression: 'document.readyState', contextId: world.executionContextId, returnByValue: true,
|
|
33
|
-
}, { present: false, initialize: false }) as { result?: { value?: unknown }; exceptionDetails?: unknown }
|
|
34
|
-
checkCurrent()
|
|
35
|
-
const after = mainDocument(await handle.sendCommand('Page.getFrameTree', undefined, { present: false, initialize: false }),
|
|
36
|
-
{ allowErrorDocument: !!expected.unreachableUrl })
|
|
37
|
-
checkCurrent()
|
|
38
|
-
if (after.id !== expected.id || after.loaderId !== expected.loaderId) {
|
|
39
|
-
throw new BrowserError('browser: the acknowledged document was superseded', 'BROWSER_NAVIGATION_SUPERSEDED')
|
|
40
|
-
}
|
|
41
|
-
if (result.exceptionDetails !== undefined || !['loading', 'interactive', 'complete'].includes(String(result.result?.value))) {
|
|
42
|
-
throw new BrowserError('browser: the document did not acknowledge its parse state', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
|
|
43
|
-
}
|
|
44
|
-
return result.result?.value !== 'loading'
|
|
45
|
-
}
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/** Prepare an explicitly supplied external Electron runtime, never the plugin generation. */
|
|
2
|
-
import { spawn } from 'node:child_process'
|
|
3
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
-
import { isAbsolute, join } from 'node:path'
|
|
5
|
-
|
|
6
|
-
import { internals } from './remote-host.ts'
|
|
7
|
-
|
|
8
|
-
/** How long a background provision may run before it is abandoned. */
|
|
9
|
-
export const PROVISION_TIMEOUT_MS = 180_000
|
|
10
|
-
|
|
11
|
-
/** What happened, in terms a log line can carry. */
|
|
12
|
-
export interface ProvisionResult {
|
|
13
|
-
/** `present` — nothing to do; `ready` — provisioned now; `skipped` — opted out; `failed`. */
|
|
14
|
-
readonly status: 'present' | 'ready' | 'skipped' | 'failed'
|
|
15
|
-
/** One line for the log; never contains a stack trace a user has to decode. */
|
|
16
|
-
readonly detail: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The state a settings panel shows, which is one state wider than {@link ProvisionResult}.
|
|
21
|
-
*
|
|
22
|
-
* `idle` and `preparing` are the two a log line never needs and a user always does: "nothing has
|
|
23
|
-
* been asked for yet" and "a ~100 MB download is running right now" are the states in which a first
|
|
24
|
-
* browser call is slow, and until this existed neither was visible anywhere in the product — the
|
|
25
|
-
* only trace was a log line the panel cannot read.
|
|
26
|
-
*/
|
|
27
|
-
export interface ProvisionSnapshot {
|
|
28
|
-
/** `idle` and `preparing` are provisional; the rest are terminal for this attempt. */
|
|
29
|
-
readonly state: 'idle' | 'preparing' | 'present' | 'ready' | 'skipped' | 'failed'
|
|
30
|
-
/** One line, already user-facing: never a stack trace. */
|
|
31
|
-
readonly detail: string
|
|
32
|
-
/** When the state last changed, ISO. */
|
|
33
|
-
readonly at: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const IDLE: ProvisionSnapshot = {
|
|
37
|
-
state: 'idle',
|
|
38
|
-
detail: 'the runtime has not been asked for yet',
|
|
39
|
-
at: new Date(0).toISOString(),
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let latest: ProvisionSnapshot = IDLE
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The current provisioning state, for a readiness report.
|
|
46
|
-
*
|
|
47
|
-
* Deliberately a snapshot rather than a promise: a panel polling this must be able to answer in one
|
|
48
|
-
* synchronous read, without awaiting (and thereby echoing) the download it is reporting on.
|
|
49
|
-
* @returns the last state written, or the idle state before anything ran.
|
|
50
|
-
*/
|
|
51
|
-
export function provisionSnapshot(): ProvisionSnapshot {
|
|
52
|
-
return latest
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Replace the reported state. Internal: every terminal result is recorded here. */
|
|
56
|
-
function record(result: ProvisionResult): ProvisionResult {
|
|
57
|
-
latest = { state: result.status, detail: result.detail, at: new Date().toISOString() }
|
|
58
|
-
return result
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Everything this module touches from the outside, so a test can drive it without Electron. */
|
|
62
|
-
export interface ProvisionDeps {
|
|
63
|
-
/** Whether a spawnable binary already exists. */
|
|
64
|
-
readonly hasBinary: () => boolean
|
|
65
|
-
/** The installed electron package's own installer script, or undefined when it is not there. */
|
|
66
|
-
readonly installerScript: () => string | undefined
|
|
67
|
-
/** Runs the installer; resolves to an exit code, or rejects/returns null on failure. */
|
|
68
|
-
readonly run: (script: string, signal?: AbortSignal) => Promise<{ code: number | null; detail?: string }>
|
|
69
|
-
/** Where the outcome goes. */
|
|
70
|
-
readonly log: (message: string) => void
|
|
71
|
-
/** Opt-out honoured exactly like the install script honours it. */
|
|
72
|
-
readonly skip: () => boolean
|
|
73
|
-
/** Budget for one provision. */
|
|
74
|
-
readonly timeoutMs: number
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Whether a spawnable Electron binary is already available.
|
|
79
|
-
*
|
|
80
|
-
* Resolved through the same probe the host uses, so this can never disagree with what a launch
|
|
81
|
-
* would find: a second, cheaper-looking check would be the classic way to report "ready" and then
|
|
82
|
-
* fail at spawn time.
|
|
83
|
-
* @returns true when a launch would find a binary.
|
|
84
|
-
*/
|
|
85
|
-
export function hasElectronRuntime(): boolean {
|
|
86
|
-
try {
|
|
87
|
-
internals.resolveElectronPath()
|
|
88
|
-
return true
|
|
89
|
-
} catch {
|
|
90
|
-
return false
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @returns the explicitly selected external package installer, or undefined.
|
|
96
|
-
*/
|
|
97
|
-
function electronInstallerScript(): string | undefined {
|
|
98
|
-
try {
|
|
99
|
-
const directory = process.env.DSH_BROWSER_ELECTRON_PACKAGE
|
|
100
|
-
if (!directory || !isAbsolute(directory)) return undefined
|
|
101
|
-
const metadata = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')) as { name?: unknown }
|
|
102
|
-
if (metadata.name !== 'electron') return undefined
|
|
103
|
-
const script = join(directory, 'install.js')
|
|
104
|
-
return existsSync(script) ? script : undefined
|
|
105
|
-
} catch {
|
|
106
|
-
return undefined
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** The Electron version the installed package asks for, for a log line that names the download. */
|
|
111
|
-
function electronVersion(): string {
|
|
112
|
-
try {
|
|
113
|
-
const directory = process.env.DSH_BROWSER_ELECTRON_PACKAGE
|
|
114
|
-
if (!directory || !isAbsolute(directory)) return 'unknown'
|
|
115
|
-
const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')) as { version?: unknown }
|
|
116
|
-
return typeof manifest.version === 'string' ? manifest.version : 'unknown'
|
|
117
|
-
} catch {
|
|
118
|
-
return 'unknown'
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
let runningInstaller: Promise<{ code: number | null; detail?: string }> | undefined
|
|
123
|
-
|
|
124
|
-
/** The real dependencies: this process's spawn, fs and logger. */
|
|
125
|
-
export function defaultDeps(log: (message: string) => void = () => {}): ProvisionDeps {
|
|
126
|
-
return {
|
|
127
|
-
hasBinary: hasElectronRuntime,
|
|
128
|
-
installerScript: electronInstallerScript,
|
|
129
|
-
run: (script, signal) => {
|
|
130
|
-
if (runningInstaller !== undefined) return runningInstaller
|
|
131
|
-
const run = new Promise<{ code: number | null; detail?: string }>(resolve => {
|
|
132
|
-
const child = spawn(process.execPath, [script], {
|
|
133
|
-
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
134
|
-
stdio: ['ignore', 'ignore', 'ignore'],
|
|
135
|
-
windowsHide: true,
|
|
136
|
-
})
|
|
137
|
-
let failure: string | undefined
|
|
138
|
-
const abort = (): void => { child.kill('SIGKILL') }
|
|
139
|
-
signal?.addEventListener('abort', abort, { once: true })
|
|
140
|
-
if (signal?.aborted) abort()
|
|
141
|
-
child.once('error', error => { failure = String(error) })
|
|
142
|
-
child.once('close', code => {
|
|
143
|
-
signal?.removeEventListener('abort', abort)
|
|
144
|
-
resolve({ code, detail: failure })
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
runningInstaller = run
|
|
148
|
-
const clear = (): void => { if (runningInstaller === run) runningInstaller = undefined }
|
|
149
|
-
void run.then(clear, clear)
|
|
150
|
-
return run
|
|
151
|
-
},
|
|
152
|
-
log,
|
|
153
|
-
skip: () => typeof process.env.ELECTRON_SKIP_BINARY_DOWNLOAD === 'string'
|
|
154
|
-
&& process.env.ELECTRON_SKIP_BINARY_DOWNLOAD !== '',
|
|
155
|
-
timeoutMs: PROVISION_TIMEOUT_MS,
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Provision the runtime once per process, when it is missing.
|
|
161
|
-
*
|
|
162
|
-
* Concurrent callers share the first attempt: two tool calls arriving together must not start two
|
|
163
|
-
* downloads into the same directory.
|
|
164
|
-
* @param deps - the effects, defaulted to this process's.
|
|
165
|
-
* @returns what happened. Never throws.
|
|
166
|
-
*/
|
|
167
|
-
export async function ensureElectronRuntime(deps: ProvisionDeps = defaultDeps()): Promise<ProvisionResult> {
|
|
168
|
-
if (deps.hasBinary()) return record({ status: 'present', detail: 'an Electron runtime is already available' })
|
|
169
|
-
if (deps.skip()) return record({ status: 'skipped', detail: 'ELECTRON_SKIP_BINARY_DOWNLOAD is set' })
|
|
170
|
-
const script = deps.installerScript()
|
|
171
|
-
if (script === undefined) {
|
|
172
|
-
return record({ status: 'failed', detail: 'the installed electron package has no install.js; reinstall the plugin in this profile' })
|
|
173
|
-
}
|
|
174
|
-
const version = electronVersion()
|
|
175
|
-
latest = {
|
|
176
|
-
state: 'preparing',
|
|
177
|
-
detail: `downloading Electron ${version} (one time, about a minute)`,
|
|
178
|
-
at: new Date().toISOString(),
|
|
179
|
-
}
|
|
180
|
-
deps.log(`preparing Electron ${version} in the background (a missing runtime needs a download)`)
|
|
181
|
-
// The bound has to be a REFERENCED timer, and it has to be cleared when the race finishes.
|
|
182
|
-
//
|
|
183
|
-
// A first version unref'd it — "do not keep the process alive for a download" — which is exactly
|
|
184
|
-
// backwards: with nothing else on the loop the timer never fires, the promise never settles, and a
|
|
185
|
-
// caller waiting on it hangs with no error at all. CI caught it before a user could: the test for
|
|
186
|
-
// this path failed with "Promise resolution is still pending but the event loop has already
|
|
187
|
-
// resolved". Keep it referenced, and clear it so a success does not leave a 180 s handle behind.
|
|
188
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
189
|
-
const controller = new AbortController()
|
|
190
|
-
const timeout = new Promise<{ code: number | null; detail: string }>(resolve => {
|
|
191
|
-
timer = setTimeout(
|
|
192
|
-
() => {
|
|
193
|
-
controller.abort()
|
|
194
|
-
resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` })
|
|
195
|
-
},
|
|
196
|
-
deps.timeoutMs,
|
|
197
|
-
)
|
|
198
|
-
})
|
|
199
|
-
let outcome: { code: number | null; detail?: string }
|
|
200
|
-
try {
|
|
201
|
-
outcome = await Promise.race([deps.run(script, controller.signal), timeout])
|
|
202
|
-
} catch (error) {
|
|
203
|
-
return record({ status: 'failed', detail: `the download failed: ${String(error)}` })
|
|
204
|
-
} finally {
|
|
205
|
-
if (timer !== undefined) clearTimeout(timer)
|
|
206
|
-
}
|
|
207
|
-
if (outcome.code !== 0) {
|
|
208
|
-
return record({
|
|
209
|
-
status: 'failed',
|
|
210
|
-
detail: `Electron provisioning did not finish (${outcome.detail ?? `exit ${String(outcome.code)}`}); `
|
|
211
|
-
+ 'the browser still works through a sidebar, Chrome or Edge; retry from Settings → Browser → '
|
|
212
|
-
+ 'Readiness ("Prepare the bundled browser"), or run `npx --no dsh-browser-install-electron`',
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
return record({ status: 'ready', detail: 'the Electron runtime is ready' })
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** One attempt per process, shared by every caller. */
|
|
219
|
-
let attempt: Promise<ProvisionResult> | undefined
|
|
220
|
-
/** Whether {@link attempt} has settled, which is what makes a retry possible. */
|
|
221
|
-
let settled = false
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Start (or join) the single background attempt.
|
|
225
|
-
*
|
|
226
|
-
* Returns immediately with the shared promise, so a caller that does not care can ignore it and one
|
|
227
|
-
* that does can await it — the returned promise never rejects.
|
|
228
|
-
*
|
|
229
|
-
* `force` is the second half of the settings panel's retry button. Without it the memoised attempt
|
|
230
|
-
* made a failed download permanent for the life of the process: the panel could offer a button, the
|
|
231
|
-
* button could call this, and the answer would be the failure it was trying to replace. An attempt
|
|
232
|
-
* still IN FLIGHT is always joined, never restarted — two downloads into one directory is the one
|
|
233
|
-
* outcome worth refusing.
|
|
234
|
-
* @param log - where the outcome goes.
|
|
235
|
-
* @param deps - the effects; defaulted to this process's, overridable so a test can drive it.
|
|
236
|
-
* @param options - `force` discards a settled attempt so a new one may start.
|
|
237
|
-
* @returns the shared attempt.
|
|
238
|
-
*/
|
|
239
|
-
export function provisionElectronInBackground(
|
|
240
|
-
log: (message: string) => void,
|
|
241
|
-
deps: ProvisionDeps = defaultDeps(log),
|
|
242
|
-
options: { readonly force?: boolean } = {},
|
|
243
|
-
): Promise<ProvisionResult> {
|
|
244
|
-
if (options.force === true && settled) {
|
|
245
|
-
attempt = undefined
|
|
246
|
-
settled = false
|
|
247
|
-
}
|
|
248
|
-
attempt ??= ensureElectronRuntime(deps).then(result => {
|
|
249
|
-
settled = true
|
|
250
|
-
log(`electron runtime: ${result.status} — ${result.detail}`)
|
|
251
|
-
return result
|
|
252
|
-
})
|
|
253
|
-
return attempt
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Forget the attempt. Tests only: a real process provisions at most once. */
|
|
257
|
-
export function resetProvisionStateForTest(): void {
|
|
258
|
-
attempt = undefined
|
|
259
|
-
settled = false
|
|
260
|
-
latest = IDLE
|
|
261
|
-
}
|