dsh-builtin-browser 1.0.0 → 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 +61 -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/pr64-maintenance.md +1 -1
- package/docs/tool-reference.md +1 -1
- package/docs/user-guide.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 -46
- 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 -54
- 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-electron/package-removal.js +0 -5
- 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 -1301
- 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/package-removal.ts +0 -4
- 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,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The last page a tool opened, shared by the provider and the HTTP surface.
|
|
3
|
-
*
|
|
4
|
-
* The provider instance that runs a tool and the one that answers routes are not guaranteed to be the
|
|
5
|
-
* same object (a surface can be built per context), so an instance field read back `null`. A module-level
|
|
6
|
-
* slot is what both sides can see — and it is what lets the Web sidebar place a tool-opened page with one
|
|
7
|
-
* call instead of a manual address-bar dance.
|
|
8
|
-
* @module dsh-builtin-browser/browser-electron/open-slot
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The slot lives on \`globalThis\`: the plugin's lib can be imported by more than one module instance in the
|
|
13
|
-
* same process (tools and the HTTP surface), and module-level state is per instance — which read back as
|
|
14
|
-
* \`null\` even after an open.
|
|
15
|
-
*/
|
|
16
|
-
const SLOT = '__dshBuiltinBrowserLastOpen'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Record an open request.
|
|
20
|
-
* @param url - the page a tool asked to open.
|
|
21
|
-
* @param at - arrival time in epoch milliseconds.
|
|
22
|
-
*/
|
|
23
|
-
export function setLastOpen(url: string, at: number, owner?: string): void {
|
|
24
|
-
(globalThis as unknown as Record<string, unknown>)[SLOT] = { url, at, ...owner === undefined ? {} : { owner } }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Read the most recent open request.
|
|
29
|
-
* @returns the request, or undefined when nothing was opened since start.
|
|
30
|
-
*/
|
|
31
|
-
export function getLastOpen(): { readonly url: string; readonly at: number; readonly owner?: string } | undefined {
|
|
32
|
-
return (globalThis as unknown as Record<string, { url: string; at: number; owner?: string } | undefined>)[SLOT]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 清空 open 记录(客户端摆放完侧栏标签后回执)。
|
|
37
|
-
*
|
|
38
|
-
* 「最后一次 open」如果一直留着,刷新页面或换一个标签页打开 DSH 时就会被重放,把用户已经关掉的
|
|
39
|
-
* 侧栏与网页重新拉起来。拿到回执即清空,这条记录就变成一次性事件。
|
|
40
|
-
* @param at - 只有记录的到达时间与之一致时才清空;省略则无条件清空。
|
|
41
|
-
* @returns 是否真的清掉了。
|
|
42
|
-
*/
|
|
43
|
-
export function clearLastOpen(at?: number): boolean {
|
|
44
|
-
const current = getLastOpen()
|
|
45
|
-
if (current === undefined) return false
|
|
46
|
-
if (at !== undefined && current.at !== at) return false
|
|
47
|
-
delete (globalThis as unknown as Record<string, unknown>)[SLOT]
|
|
48
|
-
return true
|
|
49
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** Keep package-manager children in plain-filesystem mode, including after this bundle is unloaded. */
|
|
2
|
-
export function enableElectronPackageRemoval(environment: NodeJS.ProcessEnv = process.env, electron = process.versions.electron): void {
|
|
3
|
-
if (electron !== undefined && environment.ELECTRON_RUN_AS_NODE === '1') environment.ELECTRON_NO_ASAR = '1'
|
|
4
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Where DSH keeps the plugin's per-user state.
|
|
3
|
-
*
|
|
4
|
-
* Every reader — settings, history, the profile root, the maintenance plan and the desktop
|
|
5
|
-
* bridge endpoint — must resolve DSH_HOME the same way. The expression used to be inlined in
|
|
6
|
-
* each module, which let one of them drift to a different directory and produced two
|
|
7
|
-
* half-profiles that never met (see the note in entry.ts).
|
|
8
|
-
* @module dsh-browser/browser-electron/paths
|
|
9
|
-
*/
|
|
10
|
-
import { homedir } from 'node:os'
|
|
11
|
-
import { join } from 'node:path'
|
|
12
|
-
|
|
13
|
-
/** Absolute path of the DSH home directory; DSH_HOME overrides the per-user default. */
|
|
14
|
-
export function dshHome(): string {
|
|
15
|
-
return process.env.DSH_HOME || join(homedir(), '.dsh')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function browserHostLogPath(): string {
|
|
19
|
-
return join(dshHome(), 'logs', 'dsh-builtin-browser-host.log')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Absolute path of the endpoint file the running desktop shell publishes. */
|
|
23
|
-
export function bridgeEndpointPath(): string {
|
|
24
|
-
return join(dshHome(), 'dsh-builtin-browser-bridge.json')
|
|
25
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { EXTENSION_READY_TIMEOUT_MS } from '../../assets/browser-policy.mjs'
|
|
2
|
-
import { ExtensionBrowserViewHost } from './extension-browser.ts'
|
|
3
|
-
import type { NativeBrowserClient } from '../../native-host/client.mjs'
|
|
4
|
-
import type { ElectronBrowserViewHost, ElectronViewHandle } from './provider.ts'
|
|
5
|
-
import { readTabHandle, sessionWireId, type BrowserTabWireId } from '../browser/handles.ts'
|
|
6
|
-
import type { BrowserSessionId } from '../browser/types.ts'
|
|
7
|
-
|
|
8
|
-
export async function extensionReady(connect: () => Promise<void>, milliseconds = EXTENSION_READY_TIMEOUT_MS): Promise<boolean> {
|
|
9
|
-
const deadline = Date.now() + milliseconds
|
|
10
|
-
let timer: ReturnType<typeof setTimeout> | undefined
|
|
11
|
-
const attempt = async () => {
|
|
12
|
-
do {
|
|
13
|
-
try { await connect(); return true } catch {}
|
|
14
|
-
await new Promise(resolve => setTimeout(resolve, Math.min(100, Math.max(0, deadline - Date.now()))))
|
|
15
|
-
} while (Date.now() < deadline)
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
try { return await Promise.race([attempt(), new Promise<false>(resolve => { timer = setTimeout(() => resolve(false), milliseconds) })]) }
|
|
19
|
-
finally { clearTimeout(timer) }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class PreferredBrowserViewHost implements ElectronBrowserViewHost {
|
|
23
|
-
private readonly routes = new Map<BrowserSessionId, Promise<ElectronBrowserViewHost>>()
|
|
24
|
-
private readonly decisions = new Map<BrowserSessionId, ElectronBrowserViewHost>()
|
|
25
|
-
private readonly mapped = new Map<string, { handle: ElectronViewHandle; real?: Promise<{ host: ElectronBrowserViewHost; handle: ElectronViewHandle }>; dead: boolean }>()
|
|
26
|
-
private released = false
|
|
27
|
-
private selected?: 'extension' | 'cdp'
|
|
28
|
-
fallbackReason?: string
|
|
29
|
-
private readonly extension: ExtensionBrowserViewHost
|
|
30
|
-
|
|
31
|
-
constructor(readonly browser: 'edge' | 'chrome', readonly fallback: ElectronBrowserViewHost & { connectionStatus?: () => { connected: boolean; detail: string } }, client?: NativeBrowserClient, private readonly bound = EXTENSION_READY_TIMEOUT_MS) {
|
|
32
|
-
this.extension = new ExtensionBrowserViewHost(browser, client)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
activeCarrier(): 'extension' | 'cdp' { return this.selected ?? (this.extension.connectionStatus().connected ? 'extension' : 'cdp') }
|
|
36
|
-
get disposed(): boolean { return this.released }
|
|
37
|
-
connectionStatus() { return this.extension.connectionStatus() }
|
|
38
|
-
async refreshStatus() { await this.extension.refreshStatus() }
|
|
39
|
-
async prepare(scope?: BrowserSessionId) { if (scope) await (await this.route(scope)).prepare?.(scope) }
|
|
40
|
-
referenceOverlayOwnerFor(scope: BrowserSessionId): 'client' | undefined {
|
|
41
|
-
const host = this.decisions.get(scope)
|
|
42
|
-
return host ? host.referenceOverlayOwner : 'client'
|
|
43
|
-
}
|
|
44
|
-
connectedView(id: string) {
|
|
45
|
-
const view = this.mapped.get(id)
|
|
46
|
-
return !!view && !view.dead && (this.decisions.get(sessionWireId(readTabHandle(id))) === this.fallback
|
|
47
|
-
? this.fallback.connectionStatus?.().connected === true : this.extension.connectedView(id))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private route(scope: BrowserSessionId): Promise<ElectronBrowserViewHost> {
|
|
51
|
-
if (this.released) return Promise.reject(new Error('browser carrier was released'))
|
|
52
|
-
let route = this.routes.get(scope)
|
|
53
|
-
if (!route) {
|
|
54
|
-
route = (async () => {
|
|
55
|
-
const ready = await extensionReady(() => this.extension.prepare(), this.bound)
|
|
56
|
-
if (this.released) throw new Error('browser carrier was released')
|
|
57
|
-
this.selected = ready ? 'extension' : 'cdp'
|
|
58
|
-
const state = this.extension.connectionStatus().state
|
|
59
|
-
this.fallbackReason = ready ? undefined : state === 'disabled' ? 'disabled' : state === 'extension-missing' ? 'extension-not-installed' : 'not-connected'
|
|
60
|
-
const host = ready ? this.extension : this.fallback
|
|
61
|
-
this.decisions.set(scope, host)
|
|
62
|
-
return host
|
|
63
|
-
})()
|
|
64
|
-
this.routes.set(scope, route)
|
|
65
|
-
}
|
|
66
|
-
return route
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
createView(id: BrowserTabWireId): ElectronViewHandle {
|
|
70
|
-
if (this.mapped.has(id)) throw new Error('browser view already exists')
|
|
71
|
-
const view: { handle: ElectronViewHandle; real?: Promise<{ host: ElectronBrowserViewHost; handle: ElectronViewHandle }>; dead: boolean } = {
|
|
72
|
-
dead: false, handle: { id, supportsCdpJpeg: true, sendCommand: async (method, params) => {
|
|
73
|
-
if (view.dead || this.released) throw new Error('browser view was released')
|
|
74
|
-
view.real ??= this.route(sessionWireId(readTabHandle(id))).then(host => {
|
|
75
|
-
if (view.dead || this.released) throw new Error('browser view was released')
|
|
76
|
-
return { host, handle: host.createView(id) }
|
|
77
|
-
})
|
|
78
|
-
const real = await view.real
|
|
79
|
-
return real.handle.sendCommand(method, params)
|
|
80
|
-
} },
|
|
81
|
-
}
|
|
82
|
-
this.mapped.set(id, view)
|
|
83
|
-
return view.handle
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
destroyView(handle: ElectronViewHandle) {
|
|
87
|
-
const view = this.mapped.get(handle.id)
|
|
88
|
-
if (!view) return
|
|
89
|
-
view.dead = true; this.mapped.delete(handle.id)
|
|
90
|
-
void view.real?.then(real => real.host.destroyView(real.handle)).catch(() => {})
|
|
91
|
-
}
|
|
92
|
-
async listPages(scope: BrowserSessionId, options: { requireRunning?: boolean } = {}) {
|
|
93
|
-
if (options.requireRunning && !this.routes.has(scope)) return []
|
|
94
|
-
return (await this.route(scope)).listPages?.(scope, options) ?? []
|
|
95
|
-
}
|
|
96
|
-
async adoptPage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))) {
|
|
97
|
-
const host = await this.route(scope)
|
|
98
|
-
if (!host.adoptPage) throw new Error('carrier does not support page adoption')
|
|
99
|
-
const handle = await host.adoptPage(id, scope)
|
|
100
|
-
this.mapped.set(id, { handle, real: Promise.resolve({ host, handle }), dead: false })
|
|
101
|
-
return handle
|
|
102
|
-
}
|
|
103
|
-
async closePage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))) {
|
|
104
|
-
const host = await this.route(scope)
|
|
105
|
-
if (!host.closePage) throw new Error('carrier does not support explicit close')
|
|
106
|
-
await host.closePage(id, scope)
|
|
107
|
-
const view = this.mapped.get(id)
|
|
108
|
-
if (view) this.destroyView(view.handle)
|
|
109
|
-
}
|
|
110
|
-
async retireSession(scope: BrowserSessionId) {
|
|
111
|
-
try { await (await this.routes.get(scope))?.retireSession?.(scope) }
|
|
112
|
-
finally { this.routes.delete(scope); this.decisions.delete(scope) }
|
|
113
|
-
}
|
|
114
|
-
dispose() {
|
|
115
|
-
if (this.released) return
|
|
116
|
-
this.released = true
|
|
117
|
-
for (const view of [...this.mapped.values()]) this.destroyView(view.handle)
|
|
118
|
-
this.extension.dispose(); this.fallback.dispose?.()
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { PREVIEW_ROUTE, PREVIEW_SESSIONS_ROUTE, BRIDGE_STATUS_ROUTE } from '../../assets/browser-policy.mjs'
|
|
2
|
-
import { URL_PARSE_BASE } from '../../assets/browser-policy.mjs'
|
|
3
|
-
/**
|
|
4
|
-
* The live-view frame endpoint (issue #34): one JPEG per request, for a remote operator watching the
|
|
5
|
-
* page the agent is driving.
|
|
6
|
-
*
|
|
7
|
-
* Deliberately one frame per request rather than a stream. The viewer asks for the next frame after
|
|
8
|
-
* it has decoded and painted the previous one, so a slow link slows the view down instead of
|
|
9
|
-
* queueing images; the design chose this over MJPEG and WebSocket for the first version precisely
|
|
10
|
-
* because it needs no new plumbing and degrades predictably.
|
|
11
|
-
*
|
|
12
|
-
* The path is fixed and the session travels as a query parameter because the host web server only
|
|
13
|
-
* registers exact paths. That is also why the session id is not a `viewId`: a client may name a
|
|
14
|
-
* session the plugin handed out, never a carrier handle, a port, or an arbitrary target.
|
|
15
|
-
* @module dsh-browser/browser-electron/preview-route
|
|
16
|
-
*/
|
|
17
|
-
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
18
|
-
import type { BrowserError } from '../browser/types.ts'
|
|
19
|
-
import { replyJson } from './json-reply.ts'
|
|
20
|
-
import { sameOrigin } from './settings-route.ts'
|
|
21
|
-
import { findDesktopInstall, readBridgeStatus } from './bridge-status.ts'
|
|
22
|
-
import type { MainExtensionStatus } from './profile-extension.ts'
|
|
23
|
-
|
|
24
|
-
/** Where the frame endpoint lives. The viewer must use exactly this path, same origin. */
|
|
25
|
-
export { PREVIEW_ROUTE }
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Where the viewer asks which sessions it may watch.
|
|
29
|
-
*
|
|
30
|
-
* The provider names its sessions (`browser:<uuid>`) and only it knows them; the browser page has no
|
|
31
|
-
* way to guess one. Without this the viewer could not build a frame URL at all, and inventing an id
|
|
32
|
-
* is exactly what the design forbids. So the list is served, and it contains nothing but ids of
|
|
33
|
-
* sessions that currently have a page — no URLs, no titles, no target handles.
|
|
34
|
-
*/
|
|
35
|
-
export { PREVIEW_SESSIONS_ROUTE }
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Where the settings panel asks whether the desktop bridge is installed.
|
|
39
|
-
*
|
|
40
|
-
* Reported as issue #36: a missing bridge was only a log warning, so a user on `channel: sidebar`
|
|
41
|
-
* saw "another window opened again" with nothing connecting that to "the bridge is not installed".
|
|
42
|
-
* The reading is taken from the install tree on disk, so it is true even when the plugin has just
|
|
43
|
-
* started and remembers nothing.
|
|
44
|
-
*/
|
|
45
|
-
export { BRIDGE_STATUS_ROUTE }
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/** What the route needs from the settings document. */
|
|
49
|
-
interface PreviewSettings {
|
|
50
|
-
get(): { readonly remoteView: { readonly enabled: boolean } }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** What the route needs from the browser service. */
|
|
54
|
-
interface PreviewBrowser {
|
|
55
|
-
exists(session: string): boolean
|
|
56
|
-
capturePassive(session: string, signal?: AbortSignal): Promise<{ readonly dataUrl: string }>
|
|
57
|
-
/** Sessions that currently hold a page. Optional: a service without it reports none. */
|
|
58
|
-
watchableSessions?(): readonly string[]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* List the sessions a viewer may watch.
|
|
63
|
-
*
|
|
64
|
-
* Ids only. The whole point of this endpoint is to give the page something it cannot guess; adding a
|
|
65
|
-
* URL or title here would leak the very content the frame endpoint is careful not to describe in its
|
|
66
|
-
* refusals.
|
|
67
|
-
* @param request - the incoming request.
|
|
68
|
-
* @param response - the response to write.
|
|
69
|
-
* @param settings - the settings document, for the share switch.
|
|
70
|
-
* @param browser - the browser service.
|
|
71
|
-
*/
|
|
72
|
-
export async function handlePreviewSessions(
|
|
73
|
-
request: IncomingMessage,
|
|
74
|
-
response: ServerResponse,
|
|
75
|
-
settings: PreviewSettings,
|
|
76
|
-
browser: PreviewBrowser,
|
|
77
|
-
): Promise<void> {
|
|
78
|
-
if (request.method !== 'GET') {
|
|
79
|
-
replyJson(response, 405, { error: 'method-not-allowed' })
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
if (!sameOrigin(request)) {
|
|
83
|
-
replyJson(response, 403, { error: 'not-same-origin' })
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
if (settings.get().remoteView.enabled !== true) {
|
|
87
|
-
// An empty list rather than a refusal: the panel asks this before it knows whether sharing is
|
|
88
|
-
// on, and "nothing to watch" is the honest answer to give a client that is not allowed to watch.
|
|
89
|
-
replyJson(response, 200, { enabled: false, sessions: [] })
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
const sessions = browser.watchableSessions?.() ?? []
|
|
93
|
-
replyJson(response, 200, { enabled: true, sessions: [...sessions] })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Serve one frame, or say precisely why not.
|
|
99
|
-
*
|
|
100
|
-
* Every refusal is a status the viewer can act on: 403 when watching is switched off (the host has
|
|
101
|
-
* not agreed), 404 when that session has no page (nothing to watch, and nothing is opened on its
|
|
102
|
-
* behalf), 503 when the page cannot produce an image right now (hidden window, capture timeout) —
|
|
103
|
-
* which the viewer shows as paused rather than as an error.
|
|
104
|
-
* @param request - the incoming request.
|
|
105
|
-
* @param response - the response to write.
|
|
106
|
-
* @param settings - the settings document, for the host's share switch.
|
|
107
|
-
* @param browser - the browser service, for passive capture.
|
|
108
|
-
*/
|
|
109
|
-
export async function handlePreviewFrame(
|
|
110
|
-
request: IncomingMessage,
|
|
111
|
-
response: ServerResponse,
|
|
112
|
-
settings: PreviewSettings,
|
|
113
|
-
browser: PreviewBrowser,
|
|
114
|
-
): Promise<void> {
|
|
115
|
-
if (request.method !== 'GET') {
|
|
116
|
-
replyJson(response, 405, { error: 'method-not-allowed' })
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
// The host's own pages only. A live browser frame can contain a CAPTCHA or logged-in content, so
|
|
120
|
-
// the endpoint is not something a cross-origin page may pull even with the switch on.
|
|
121
|
-
if (!sameOrigin(request)) {
|
|
122
|
-
replyJson(response, 403, { error: 'not-same-origin' })
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
// The host's consent, checked per request rather than cached: switching sharing off must take
|
|
126
|
-
// effect on the next frame, not on the next restart.
|
|
127
|
-
if (settings.get().remoteView.enabled !== true) {
|
|
128
|
-
replyJson(response, 403, { error: 'remote-view-disabled' })
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
const url = new URL(request.url ?? '/', URL_PARSE_BASE)
|
|
132
|
-
const session = url.searchParams.get('session') ?? ''
|
|
133
|
-
if (session === '') {
|
|
134
|
-
replyJson(response, 400, { error: 'session-required' })
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
// A session the plugin did not hand out is not a session. This is the only identifier a caller
|
|
138
|
-
// may supply; no carrier handle, view id, port or CDP target is accepted anywhere.
|
|
139
|
-
if (!browser.exists(session)) {
|
|
140
|
-
replyJson(response, 404, { error: 'no-such-session' })
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
const frame = await browser.capturePassive(session)
|
|
145
|
-
const comma = frame.dataUrl.indexOf(',')
|
|
146
|
-
if (comma === -1) {
|
|
147
|
-
replyJson(response, 503, { error: 'preview-unavailable', retryable: true })
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
const header = frame.dataUrl.slice(0, comma)
|
|
151
|
-
const base64 = frame.dataUrl.slice(comma + 1)
|
|
152
|
-
const mime = /^data:([^;]+)/.exec(header)?.[1] ?? 'image/jpeg'
|
|
153
|
-
const bytes = Buffer.from(base64, 'base64')
|
|
154
|
-
if (bytes.length === 0) {
|
|
155
|
-
replyJson(response, 503, { error: 'preview-unavailable', retryable: true })
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
response.writeHead(200, {
|
|
159
|
-
'content-type': mime,
|
|
160
|
-
'content-length': bytes.length,
|
|
161
|
-
// A frame is a moment, never a cached answer: replaying the last one would show the viewer a
|
|
162
|
-
// picture that claims to be live.
|
|
163
|
-
'cache-control': 'no-store, private',
|
|
164
|
-
'x-content-type-options': 'nosniff',
|
|
165
|
-
'cross-origin-resource-policy': 'same-origin',
|
|
166
|
-
'x-captured-at': String(Date.now()),
|
|
167
|
-
})
|
|
168
|
-
response.end(bytes)
|
|
169
|
-
} catch (error) {
|
|
170
|
-
// BROWSER_PREVIEW_UNAVAILABLE is the expected "cannot draw this right now" (hidden or minimized
|
|
171
|
-
// window, capture timeout). Anything else is still a refusal to serve an image, and the viewer
|
|
172
|
-
// treats both the same way: show paused, do not retry in a tight loop.
|
|
173
|
-
const code = (error as BrowserError)?.code
|
|
174
|
-
replyJson(response, 503, {
|
|
175
|
-
error: code === 'BROWSER_PREVIEW_UNAVAILABLE' ? 'preview-unavailable' : 'capture-failed',
|
|
176
|
-
retryable: true,
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Report whether the desktop bridge is installed, for the settings panel.
|
|
183
|
-
*
|
|
184
|
-
* Read-only and same-origin like the rest: it names a directory and a state, nothing that could be
|
|
185
|
-
* used to reach anything else. The command it returns is for a human to run — executing it here
|
|
186
|
-
* would let a page decide to close the desktop shell.
|
|
187
|
-
* @param request - the incoming request.
|
|
188
|
-
* @param response - the response to write.
|
|
189
|
-
* @param localAppData - the base directory to probe; injected so a test can point at a fixture.
|
|
190
|
-
*/
|
|
191
|
-
export async function handleBridgeStatus(
|
|
192
|
-
request: IncomingMessage,
|
|
193
|
-
response: ServerResponse,
|
|
194
|
-
localAppData?: string,
|
|
195
|
-
mainExtension?: MainExtensionStatus,
|
|
196
|
-
registry?: () => readonly string[],
|
|
197
|
-
conventions?: () => readonly string[],
|
|
198
|
-
): Promise<void> {
|
|
199
|
-
if (request.method !== 'GET') {
|
|
200
|
-
replyJson(response, 405, { error: 'method-not-allowed' })
|
|
201
|
-
return
|
|
202
|
-
}
|
|
203
|
-
if (!sameOrigin(request)) {
|
|
204
|
-
replyJson(response, 403, { error: 'not-same-origin' })
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
const installRoot = findDesktopInstall(localAppData, registry, conventions)
|
|
208
|
-
const status = installRoot === undefined
|
|
209
|
-
? {
|
|
210
|
-
state: 'missing' as const,
|
|
211
|
-
present: false,
|
|
212
|
-
archivePresent: false,
|
|
213
|
-
detail: 'no DSH Desktop install found in the usual roots, at DSH_DESKTOP_PATH or DSH_DESKTOP_APP, '
|
|
214
|
-
+ 'in the uninstall registry, or at this platform\'s conventional locations',
|
|
215
|
-
}
|
|
216
|
-
: readBridgeStatus(installRoot, mainExtension)
|
|
217
|
-
replyJson(response, 200, { ok: true, bridge: status })
|
|
218
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { PERSONAL_PROFILE_DIRS } from '../../assets/browser-products.mjs'
|
|
2
|
-
import { windowsPowerShellPath } from './windows-system.ts'
|
|
3
|
-
import { execFile } from 'node:child_process'
|
|
4
|
-
import { readFile, readlink } from 'node:fs/promises'
|
|
5
|
-
import { realpathSync } from 'node:fs'
|
|
6
|
-
import { homedir } from 'node:os'
|
|
7
|
-
import { isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
8
|
-
import { promisify } from 'node:util'
|
|
9
|
-
import type { ChildProcess } from 'node:child_process'
|
|
10
|
-
|
|
11
|
-
export interface ProcessIdentity {
|
|
12
|
-
readonly pid: number
|
|
13
|
-
readonly created: string
|
|
14
|
-
readonly executable: string
|
|
15
|
-
readonly argv: readonly string[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type ProcessInspector = (pid: number) => Promise<ProcessIdentity | undefined>
|
|
19
|
-
export interface ProcessOwnershipOptions {
|
|
20
|
-
readonly managed: boolean
|
|
21
|
-
readonly inspect?: ProcessInspector
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const execute = promisify(execFile)
|
|
25
|
-
const windowsInspection = String.raw`
|
|
26
|
-
$ErrorActionPreference='Stop'
|
|
27
|
-
try {
|
|
28
|
-
[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
|
|
29
|
-
$p=Get-CimInstance Win32_Process -Filter ('ProcessId='+$env:DSH_INSPECT_PID)
|
|
30
|
-
if($null -eq $p -or !$p.ExecutablePath -or !$p.CommandLine -or !$p.CreationDate) { throw 'Process identity is unavailable' }
|
|
31
|
-
@{pid=[int]$p.ProcessId;created=$p.CreationDate.ToUniversalTime().Ticks.ToString();
|
|
32
|
-
executable=$p.ExecutablePath;commandLine=$p.CommandLine} | ConvertTo-Json -Compress
|
|
33
|
-
} catch { [Console]::Error.WriteLine($_.Exception.Message); exit 2 }
|
|
34
|
-
`
|
|
35
|
-
|
|
36
|
-
export function parseWindowsCommandLine(command: string): string[] {
|
|
37
|
-
const argv: string[] = []
|
|
38
|
-
let value = '', quoted = false, started = false
|
|
39
|
-
for (let i = 0; i < command.length; i++) {
|
|
40
|
-
const char = command[i]!
|
|
41
|
-
if ((char === ' ' || char === '\t') && !quoted) {
|
|
42
|
-
if (started) argv.push(value)
|
|
43
|
-
value = ''; started = false
|
|
44
|
-
continue
|
|
45
|
-
}
|
|
46
|
-
started = true
|
|
47
|
-
if (char === '\\') {
|
|
48
|
-
let count = 1
|
|
49
|
-
while (command[i + 1] === '\\') { count++; i++ }
|
|
50
|
-
if (command[i + 1] !== '"') { value += '\\'.repeat(count); continue }
|
|
51
|
-
value += '\\'.repeat(Math.floor(count / 2))
|
|
52
|
-
if (count % 2) { value += '"'; i++; continue }
|
|
53
|
-
i++
|
|
54
|
-
} else if (char !== '"') { value += char; continue }
|
|
55
|
-
if (quoted && command[i + 1] === '"') { value += '"'; i++ }
|
|
56
|
-
else quoted = !quoted
|
|
57
|
-
}
|
|
58
|
-
if (started) argv.push(value)
|
|
59
|
-
return argv
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export async function inspectProcess(pid: number, diagnose?: (reason: string) => void): Promise<ProcessIdentity | undefined> {
|
|
63
|
-
if (!Number.isSafeInteger(pid) || pid <= 0) return undefined
|
|
64
|
-
try {
|
|
65
|
-
if (process.platform === 'win32') {
|
|
66
|
-
const { stdout } = await execute(windowsPowerShellPath(),
|
|
67
|
-
['-NoProfile', '-NonInteractive', '-EncodedCommand', Buffer.from(windowsInspection, 'utf16le').toString('base64')],
|
|
68
|
-
{ windowsHide: true, timeout: 15000, maxBuffer: 128 * 1024, env: { ...process.env, DSH_INSPECT_PID: String(pid) } })
|
|
69
|
-
const result = JSON.parse(stdout.replace(/^\uFEFF/u, ''))
|
|
70
|
-
if (result.pid !== pid || typeof result.created !== 'string' || !result.created
|
|
71
|
-
|| typeof result.executable !== 'string' || !result.executable
|
|
72
|
-
|| typeof result.commandLine !== 'string' || !result.commandLine) throw new Error('Windows returned an incomplete or mismatched process identity')
|
|
73
|
-
return { pid, created: result.created, executable: result.executable, argv: parseWindowsCommandLine(result.commandLine) }
|
|
74
|
-
}
|
|
75
|
-
if (process.platform === 'linux') {
|
|
76
|
-
const root = `/proc/${pid}`
|
|
77
|
-
const before = await readFile(`${root}/stat`, 'utf8')
|
|
78
|
-
const executable = await readlink(`${root}/exe`)
|
|
79
|
-
const command = await readFile(`${root}/cmdline`, 'utf8')
|
|
80
|
-
const after = await readFile(`${root}/stat`, 'utf8')
|
|
81
|
-
const start = (stat: string): string | undefined => stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19]
|
|
82
|
-
const created = start(before)
|
|
83
|
-
if (!created || created !== start(after) || !command.endsWith('\0')) return undefined
|
|
84
|
-
return { pid, created, executable, argv: command.slice(0, -1).split('\0') }
|
|
85
|
-
}
|
|
86
|
-
} catch (error) { diagnose?.(String(error).slice(-2000)) }
|
|
87
|
-
return undefined
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function canonical(path: string): string {
|
|
91
|
-
const actual = realpathSync(path)
|
|
92
|
-
return process.platform === 'win32' ? actual.toLowerCase() : actual
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function personalProfile(path: string): boolean {
|
|
96
|
-
const roots = process.platform === 'win32'
|
|
97
|
-
? PERSONAL_PROFILE_DIRS.win32
|
|
98
|
-
.map(name => join(process.env.LOCALAPPDATA || homedir(), name))
|
|
99
|
-
: process.platform === 'darwin'
|
|
100
|
-
? PERSONAL_PROFILE_DIRS.darwin.map(name => join(homedir(), 'Library', 'Application Support', name))
|
|
101
|
-
: PERSONAL_PROFILE_DIRS.linux.map(name => join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), name))
|
|
102
|
-
return roots.some(root => {
|
|
103
|
-
let actual: string
|
|
104
|
-
try { actual = canonical(root) } catch { actual = resolve(root); if (process.platform === 'win32') actual = actual.toLowerCase() }
|
|
105
|
-
const child = relative(actual, path)
|
|
106
|
-
return child === '' || (child !== '..' && !child.startsWith(`..${sep}`) && !isAbsolute(child))
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function dataDirectory(argv: readonly string[]): string | undefined {
|
|
111
|
-
const values: string[] = []
|
|
112
|
-
for (let i = 1; i < argv.length; i++) {
|
|
113
|
-
const arg = argv[i]!
|
|
114
|
-
if (arg === '--user-data-dir') values.push(argv[++i] ?? '')
|
|
115
|
-
else if (arg.startsWith('--user-data-dir=')) values.push(arg.slice('--user-data-dir='.length))
|
|
116
|
-
}
|
|
117
|
-
return values.length === 1 && values[0] !== '' ? values[0] : undefined
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export class BrowserProcessOwnership {
|
|
121
|
-
private readonly records = new WeakMap<ChildProcess, { identity: ProcessIdentity; executable: string; directory: string }>()
|
|
122
|
-
|
|
123
|
-
constructor(private readonly executable: string, private readonly directory: string,
|
|
124
|
-
private readonly options: ProcessOwnershipOptions) {}
|
|
125
|
-
|
|
126
|
-
private live(child: ChildProcess): boolean {
|
|
127
|
-
return Number.isSafeInteger(child.pid) && child.exitCode === null && child.signalCode === null
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async capture(child: ChildProcess): Promise<void> {
|
|
131
|
-
if (!this.options.managed || !this.live(child)) return
|
|
132
|
-
try {
|
|
133
|
-
const record = await (this.options.inspect ?? inspectProcess)(child.pid!)
|
|
134
|
-
if (!record || !this.live(child) || record.pid !== child.pid || !record.created) return
|
|
135
|
-
const directory = canonical(this.directory), argument = dataDirectory(record.argv)
|
|
136
|
-
if (!argument || personalProfile(directory) || canonical(argument) !== directory
|
|
137
|
-
|| canonical(record.executable) !== canonical(this.executable)) return
|
|
138
|
-
this.records.set(child, { identity: record, executable: canonical(record.executable), directory })
|
|
139
|
-
} catch { /* Fail closed. */ }
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async verify(child: ChildProcess): Promise<boolean> {
|
|
143
|
-
const captured = this.records.get(child)
|
|
144
|
-
if (!captured || !this.live(child)) return false
|
|
145
|
-
const record = captured.identity
|
|
146
|
-
try {
|
|
147
|
-
const current = await (this.options.inspect ?? inspectProcess)(record.pid)
|
|
148
|
-
return this.live(child) && current !== undefined && current.pid === record.pid
|
|
149
|
-
&& current.created === record.created && current.executable === record.executable
|
|
150
|
-
&& JSON.stringify(current.argv) === JSON.stringify(record.argv)
|
|
151
|
-
&& canonical(current.executable) === captured.executable && canonical(this.executable) === captured.executable
|
|
152
|
-
&& canonical(dataDirectory(current.argv) ?? '') === captured.directory && this.ownsDirectory(child)
|
|
153
|
-
} catch { return false }
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
ownsDirectory(child: ChildProcess, path = this.directory): boolean {
|
|
157
|
-
const captured = this.records.get(child)
|
|
158
|
-
try {
|
|
159
|
-
return captured !== undefined && canonical(path) === captured.directory
|
|
160
|
-
&& canonical(this.directory) === captured.directory && !personalProfile(captured.directory)
|
|
161
|
-
} catch { return false }
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async terminate(child: ChildProcess): Promise<boolean> {
|
|
165
|
-
if (!await this.verify(child) || !this.live(child)) return false
|
|
166
|
-
try { return child.kill() } catch { return false }
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One shared definition of process liveness.
|
|
3
|
-
*
|
|
4
|
-
* Signal 0 performs the permission and existence checks and delivers nothing, so it is safe to
|
|
5
|
-
* call on a pid we only read from a file. `EPERM` means the process exists and belongs to
|
|
6
|
-
* someone else, which is still "alive" for the endpoint reader and the profile sweeper alike.
|
|
7
|
-
* @module dsh-browser/browser-electron/process
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Whether a process with this pid exists, without signalling it.
|
|
12
|
-
* @param pid - the process id to test; a non-integer or non-positive value is never alive.
|
|
13
|
-
* @returns whether that process exists.
|
|
14
|
-
*/
|
|
15
|
-
export function pidAlive(pid: number): boolean {
|
|
16
|
-
if (!Number.isSafeInteger(pid) || pid <= 0) return false
|
|
17
|
-
try {
|
|
18
|
-
process.kill(pid, 0)
|
|
19
|
-
return true
|
|
20
|
-
} catch (error) {
|
|
21
|
-
return (error as NodeJS.ErrnoException)?.code === 'EPERM'
|
|
22
|
-
}
|
|
23
|
-
}
|