dsh-builtin-browser 0.5.8 → 1.0.1
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 +410 -1
- package/README.en.md +16 -64
- package/README.md +33 -64
- package/assets/browser-carriers.svg +20 -0
- package/assets/browser-extension-identity.d.mts +2 -0
- package/assets/browser-extension-identity.mjs +2 -0
- package/assets/browser-messages.d.mts +5 -0
- package/assets/browser-messages.mjs +64 -0
- package/assets/browser-panel-locales.d.mts +2 -0
- package/assets/browser-panel-locales.mjs +380 -0
- package/assets/browser-policy.d.mts +37 -0
- package/assets/browser-policy.mjs +37 -0
- package/assets/browser-products.d.mts +6 -0
- package/assets/browser-products.mjs +76 -0
- package/assets/screenshots/1-main.png +0 -0
- package/assets/screenshots/2-form-fill.png +0 -0
- package/assets/screenshots/3-challenge.png +0 -0
- package/browser-extension/constants.mjs +20 -0
- package/browser-extension/controller.mjs +293 -0
- package/browser-extension/locales.mjs +15 -0
- package/browser-extension/manifest.json +12 -0
- package/browser-extension/options.html +14 -0
- package/browser-extension/options.mjs +9 -0
- package/browser-extension/permission-guard.mjs +13 -0
- package/browser-extension/worker.mjs +74 -0
- package/cordis.patch.yml +23 -48
- package/desktop-bridge/desktop-discovery.d.mts +2 -0
- package/desktop-bridge/desktop-discovery.mjs +36 -0
- package/desktop-bridge/desktop-identity.json +17 -1
- package/desktop-bridge/desktop-processes.d.mts +1 -0
- package/desktop-bridge/desktop-processes.mjs +15 -0
- package/desktop-bridge/guest-proxy.mjs +109 -0
- package/desktop-bridge/install.mjs +197 -74
- package/desktop-bridge/main.mjs +11 -0
- package/desktop-bridge/maintenance-files.d.mts +8 -0
- package/desktop-bridge/maintenance-files.mjs +28 -0
- package/desktop-bridge/maintenance-progress.ps1 +2 -2
- package/desktop-bridge/native-guests.mjs +41 -0
- package/desktop-bridge/plugin-browser-bridge.js +618 -370
- package/desktop-bridge/profile-loader.mjs +26 -0
- package/dist/client.cjs +43167 -0
- package/dist/client.d.cts +516 -0
- package/dist/client.d.mts +516 -0
- package/dist/index.cjs +92 -0
- package/dist/index.d.mts +2960 -0
- package/dist/index.mjs +24 -0
- package/docs/HANDOVER-2026-11-15.md +178 -0
- package/docs/README.md +10 -19
- package/docs/architecture.md +17 -145
- package/docs/child-tabs.md +13 -0
- package/docs/desktop-acceptance.md +9 -0
- package/docs/development.md +88 -18
- package/docs/extension-browser.md +44 -0
- package/docs/hardcoding-audit.md +64 -0
- package/docs/limitations.md +23 -73
- package/docs/pr64-extension-status.md +46 -0
- package/docs/pr64-maintenance.md +25 -0
- package/docs/pr64-native-children.md +52 -0
- package/docs/pr64-native-views.md +60 -0
- package/docs/tool-reference.md +87 -11
- package/docs/user-guide.md +47 -255
- package/docs/why-browser.md +6 -39
- package/dsh-host-patch/README.md +60 -0
- package/dsh-host-patch/apply.mjs +194 -0
- package/dsh-host-patch/legacy-bridge.mjs +53 -0
- package/dsh-host-patch/rc3-revision1.json +90 -0
- package/dsh-host-patch/rc3-revision2.json +112 -0
- package/dsh-host-patch/rc3-revision3.json.gz +0 -0
- package/dsh-host-patch/rc3-revision4.json.gz +0 -0
- package/dsh-host-patch/rc3-revision5.json.gz +0 -0
- package/dsh-host-patch/rc3-revision6.json.gz +0 -0
- package/dsh-host-patch/rc3-revision7.json.gz +0 -0
- package/dsh-host-patch/rc3-revision8.json.gz +0 -0
- package/dsh-host-patch/rc3.json +148 -0
- package/dsh-host-patch/rc5-revision1.json +90 -0
- package/dsh-host-patch/rc5-revision2.json +112 -0
- package/dsh-host-patch/rc5-revision3.json.gz +0 -0
- package/dsh-host-patch/rc5-revision4.json.gz +0 -0
- package/dsh-host-patch/rc5-revision5.json.gz +0 -0
- package/dsh-host-patch/rc5-revision6.json.gz +0 -0
- package/dsh-host-patch/rc5-revision7.json.gz +0 -0
- package/dsh-host-patch/rc5-revision8.json.gz +0 -0
- package/dsh-host-patch/rc5.json +148 -0
- package/lib/bridge-compatibility.js +38 -0
- package/lib/browser/handles.js +78 -0
- package/lib/browser/runtime.js +155 -43
- package/lib/browser/takeover-target.js +24 -0
- package/lib/browser-electron/authenticated-route.js +23 -0
- package/lib/browser-electron/automatic-maintenance.js +394 -51
- package/lib/browser-electron/bridge-auto.js +2 -1
- package/lib/browser-electron/bridge-connection.js +8 -1
- package/lib/browser-electron/bridge-install.js +27 -2
- package/lib/browser-electron/bridge-maintenance.js +35 -10
- package/lib/browser-electron/bridge-status.js +98 -27
- package/lib/browser-electron/desktop-bridge-host.js +193 -560
- package/lib/browser-electron/desktop-identity.js +40 -2
- package/lib/browser-electron/document-readiness.js +34 -0
- package/lib/browser-electron/electron-provision.js +14 -44
- package/lib/browser-electron/entry.js +659 -252
- package/lib/browser-electron/extension-browser.js +234 -0
- package/lib/browser-electron/extension-setup.js +69 -0
- package/lib/browser-electron/guest-cookie-jar.LICENSE.txt +32 -0
- package/lib/browser-electron/guest-cookie-jar.js +10559 -0
- package/lib/browser-electron/guest-cookie-store.js +74 -0
- package/lib/browser-electron/guest-css-runtime.js +75 -0
- package/lib/browser-electron/guest-css.js +106 -0
- package/lib/browser-electron/guest-route.js +603 -0
- package/lib/browser-electron/guest-runtime.js +356 -0
- package/lib/browser-electron/guest-storage-runtime.js +52 -0
- package/lib/browser-electron/guest-storage.js +163 -0
- package/lib/browser-electron/history-store.js +2 -1
- package/lib/browser-electron/host-main.js +162 -7
- package/lib/browser-electron/host-patch-maintenance.js +141 -0
- package/lib/browser-electron/http-body.js +22 -0
- package/lib/browser-electron/maintenance-broker.js +35 -5
- package/lib/browser-electron/maintenance-lifecycle.js +7 -5
- package/lib/browser-electron/maintenance-route.js +9 -6
- package/lib/browser-electron/open-slot.js +47 -0
- package/lib/browser-electron/paths.js +4 -1
- package/lib/browser-electron/preferred-browser.js +144 -0
- package/lib/browser-electron/preview-route.js +11 -8
- package/lib/browser-electron/process-ownership.js +198 -0
- package/lib/browser-electron/profile-checkpoint.js +222 -0
- package/lib/browser-electron/profile-command.js +60 -0
- package/lib/browser-electron/profile-extension.js +126 -0
- package/lib/browser-electron/profile-lease.js +157 -0
- package/lib/browser-electron/profile-residue.js +61 -0
- package/lib/browser-electron/provider.js +719 -262
- package/lib/browser-electron/reference-route.js +635 -0
- package/lib/browser-electron/remote-host.js +12 -13
- package/lib/browser-electron/runtime-route.js +6 -5
- package/lib/browser-electron/runtime-status.js +30 -29
- package/lib/browser-electron/settings-store.js +10 -5
- package/lib/browser-electron/shortcuts-route.js +108 -0
- package/lib/browser-electron/sidebar-only-host.js +119 -18
- package/lib/browser-electron/startpage-shortcuts.js +172 -0
- package/lib/browser-electron/system-browser.js +352 -371
- package/lib/browser-electron/windows-system.js +2 -1
- package/lib/browser-reference/delivery.js +326 -0
- package/lib/browser-reference/entry.js +597 -0
- package/lib/browser-reference/export.js +298 -0
- package/lib/browser-reference/import.js +295 -0
- package/lib/browser-reference/page-script.js +1406 -0
- package/lib/browser-reference/service.js +1062 -0
- package/lib/browser-reference/store.js +177 -0
- package/lib/browser-reference/submission-receipts.js +139 -0
- package/lib/browser-reference/text-quote.js +167 -0
- package/lib/browser-reference/types.js +11 -0
- package/lib/browser-reference/visible.js +311 -0
- package/lib/browser-reference/web-sources.js +97 -0
- package/lib/index.js +10 -3
- package/lib/reference-owner.js +5 -0
- package/lib/reference-page.js +12 -0
- package/lib/reference-source.js +2 -0
- package/lib/reference-text.js +188 -0
- package/lib/startpage-settings.js +63 -0
- package/lib/startpage.js +44 -0
- package/lib/takeover-protocol.js +2 -0
- package/lib/tool-browser/code-tool.js +416 -0
- package/lib/tool-browser/code-worker.js +872 -0
- package/lib/tool-browser/index.js +940 -76
- package/lib/tool-browser/page-probe.js +3 -3
- package/lib/tool-browser/panel-page.js +95 -0
- package/lib/tool-browser/screenshot-image.js +51 -0
- package/lib/tool-browser/takeover.js +205 -0
- package/lib/types.js +1 -0
- package/lib/web-guest.js +26 -0
- package/native-host/client.d.mts +17 -0
- package/native-host/client.mjs +100 -0
- package/native-host/host.mjs +150 -0
- package/native-host/identity.d.mts +2 -0
- package/native-host/identity.mjs +1 -0
- package/native-host/install.mjs +168 -0
- package/native-host/protocol.mjs +75 -0
- package/package.json +80 -92
- package/scripts/build.mjs +66 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +50 -0
- package/scripts/install-electron.mjs +11 -26
- package/scripts/verify-exports.mjs +47 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +56 -47
- package/skills/dsh-builtin-browser/references/batch.md +31 -1
- package/skills/dsh-debug-host/SKILL.md +56 -0
- package/skills/dsh-debug-self/SKILL.md +50 -0
- package/src/bridge-compatibility.ts +39 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +146 -50
- package/src/browser/takeover-target.ts +36 -0
- package/src/browser/types.ts +19 -7
- package/src/browser-electron/authenticated-route.ts +29 -1
- package/src/browser-electron/automatic-maintenance.ts +368 -56
- package/src/browser-electron/bridge-auto.ts +5 -4
- package/src/browser-electron/bridge-connection.ts +20 -2
- package/src/browser-electron/bridge-endpoint.ts +3 -3
- package/src/browser-electron/bridge-install.ts +40 -4
- package/src/browser-electron/bridge-maintenance.ts +42 -14
- package/src/browser-electron/bridge-status.ts +94 -23
- package/src/browser-electron/desktop-bridge-host.ts +185 -585
- package/src/browser-electron/desktop-identity.ts +53 -2
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +12 -45
- package/src/browser-electron/entry.ts +1299 -882
- package/src/browser-electron/ephemeral-profile.ts +1 -1
- package/src/browser-electron/extension-browser.ts +223 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/guest-cookie-jar.ts +176 -0
- package/src/browser-electron/guest-cookie-store.ts +59 -0
- package/src/browser-electron/guest-css-runtime.ts +76 -0
- package/src/browser-electron/guest-css.ts +68 -0
- package/src/browser-electron/guest-route.ts +568 -0
- package/src/browser-electron/guest-runtime.ts +357 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +117 -0
- package/src/browser-electron/history-store.ts +5 -4
- package/src/browser-electron/host-main.ts +156 -11
- package/src/browser-electron/host-patch-maintenance.ts +112 -0
- package/src/browser-electron/http-body.ts +23 -0
- package/src/browser-electron/maintenance-broker.ts +29 -5
- package/src/browser-electron/maintenance-lifecycle.ts +14 -9
- package/src/browser-electron/maintenance-route.ts +17 -14
- package/src/browser-electron/missing-system-browser.ts +2 -2
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +5 -1
- package/src/browser-electron/preferred-browser.ts +120 -0
- package/src/browser-electron/preview-route.ts +18 -11
- package/src/browser-electron/process-ownership.ts +168 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +46 -0
- package/src/browser-electron/profile-extension.ts +124 -0
- package/src/browser-electron/profile-lease.ts +115 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider.ts +771 -289
- package/src/browser-electron/reference-route.ts +608 -0
- package/src/browser-electron/remote-host.ts +15 -15
- package/src/browser-electron/runtime-route.ts +11 -10
- package/src/browser-electron/runtime-status.ts +51 -32
- package/src/browser-electron/settings-store.ts +27 -7
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +118 -19
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +309 -338
- package/src/browser-electron/windows-system.ts +2 -1
- package/src/browser-reference/delivery.ts +384 -0
- package/src/browser-reference/entry.ts +631 -0
- package/src/browser-reference/export.ts +339 -0
- package/src/browser-reference/import.ts +303 -0
- package/src/browser-reference/page-script.ts +1537 -0
- package/src/browser-reference/service.ts +1315 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/submission-receipts.ts +122 -0
- package/src/browser-reference/text-quote.ts +219 -0
- package/src/browser-reference/types.ts +195 -0
- package/src/browser-reference/visible.ts +367 -0
- package/src/browser-reference/web-sources.ts +103 -0
- package/src/client/browser/BrowserController.ts +693 -0
- package/src/client/browser/BrowserFrame.ts +78 -0
- package/src/client/browser/BrowserNavigation.ts +169 -0
- package/src/client/browser/BrowserPage.ts +23 -0
- package/src/client/browser/BrowserPersistence.ts +44 -0
- package/src/client/browser/IframeImpl.ts +176 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/iframe-reference.ts +67 -0
- package/src/client/browser/initialization.ts +262 -0
- package/src/client/browser/omnibox.ts +243 -0
- package/src/client/browser/store.ts +38 -0
- package/src/client/browser/takeover-channel.ts +72 -0
- package/src/client/browser/url.ts +46 -0
- package/src/client/browser/web-reference-source.ts +52 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +30 -0
- package/src/client/electron/ElectronWebViewImpl.ts +364 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +138 -0
- package/src/client/electron/NativeChildPresentation.ts +45 -0
- package/src/client/electron/NativeViewPage.ts +251 -0
- package/src/client/electron/pages.ts +23 -0
- package/src/client/electron/reference-overlay.ts +53 -0
- package/src/client/electron/workspace.ts +33 -0
- package/src/client/index.ts +293 -0
- package/src/client/locales.ts +857 -0
- package/src/client/pages.ts +28 -0
- package/src/client/reference/client/BrowserRefLink.tsx +142 -0
- package/src/client/reference/client/draft-reference.ts +167 -0
- package/src/client/reference/client/index.ts +7 -0
- package/src/client/reference/client/ordered-submission.ts +108 -0
- package/src/client/reference/client/pending-delivery.ts +216 -0
- package/src/client/reference/client/plugin.ts +189 -0
- package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
- package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
- package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
- package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
- package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
- package/src/client/reference/client/production/ReferenceText.tsx +36 -0
- package/src/client/reference/client/production/assembly.ts +471 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +74 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +508 -0
- package/src/client/reference/client/production/http-transport.ts +217 -0
- package/src/client/reference/client/production/production-submission.ts +310 -0
- package/src/client/reference/client/production/protocol.ts +231 -0
- package/src/client/reference/client/production/reference-card.ts +240 -0
- package/src/client/reference/client/production/reference-labels.ts +29 -0
- package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
- package/src/client/reference/client/production/reveal.ts +215 -0
- package/src/client/reference/client/production/runtime.ts +1101 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +63 -0
- package/src/client/reference/client/production/source-opener.ts +55 -0
- package/src/client/reference/client/production/styles.ts +104 -0
- package/src/client/reference/client/production/user-text-rule.ts +58 -0
- package/src/client/reference/client/reveal.ts +107 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/types.ts +168 -0
- package/src/client/reference/css-modules.d.ts +4 -0
- package/src/client/reference/index.ts +11 -0
- package/src/client/reference-capture-owner.ts +162 -0
- package/src/client/reference-intents.ts +36 -0
- package/src/client/settings/index.ts +34 -0
- package/{client.js → src/client/settings/panel.ts} +2657 -2231
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +303 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +314 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +344 -0
- package/src/client/view/StartPage.tsx +597 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/index.ts +110 -73
- package/src/reference-owner.ts +5 -0
- package/src/reference-page.ts +9 -0
- package/src/reference-source.ts +3 -0
- package/src/reference-text.ts +197 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +19 -0
- package/src/tool-browser/code-tool.ts +401 -0
- package/src/tool-browser/code-worker.ts +639 -0
- package/src/tool-browser/index.ts +908 -77
- package/src/tool-browser/page-probe.ts +4 -4
- package/src/tool-browser/panel-page.ts +124 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/takeover.ts +198 -0
- package/src/types/electron-shim.d.ts +20 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +34 -0
- package/tools/accept-desktop.mjs +148 -0
- package/lib/browser/runtime.d.ts +0 -175
- package/lib/browser/types.d.ts +0 -797
- package/lib/browser-electron/authenticated-route.d.ts +0 -27
- package/lib/browser-electron/automatic-maintenance.d.ts +0 -41
- package/lib/browser-electron/bridge-auto.d.ts +0 -93
- package/lib/browser-electron/bridge-connection.d.ts +0 -93
- package/lib/browser-electron/bridge-endpoint.d.ts +0 -30
- package/lib/browser-electron/bridge-install.d.ts +0 -85
- package/lib/browser-electron/bridge-maintenance.d.ts +0 -24
- package/lib/browser-electron/bridge-status.d.ts +0 -50
- package/lib/browser-electron/desktop-bridge-host.d.ts +0 -248
- package/lib/browser-electron/desktop-identity.d.ts +0 -58
- package/lib/browser-electron/electron-provision.d.ts +0 -92
- package/lib/browser-electron/entry.d.ts +0 -64
- package/lib/browser-electron/ephemeral-profile.d.ts +0 -37
- package/lib/browser-electron/file-write.d.ts +0 -2
- package/lib/browser-electron/history-store.d.ts +0 -98
- package/lib/browser-electron/host-main.d.ts +0 -26
- package/lib/browser-electron/http-body.d.ts +0 -24
- package/lib/browser-electron/json-reply.d.ts +0 -33
- package/lib/browser-electron/maintenance-broker.d.ts +0 -35
- package/lib/browser-electron/maintenance-lifecycle.d.ts +0 -32
- package/lib/browser-electron/maintenance-route.d.ts +0 -18
- package/lib/browser-electron/missing-system-browser.d.ts +0 -54
- package/lib/browser-electron/paths.d.ts +0 -4
- package/lib/browser-electron/preview-route.d.ts +0 -89
- package/lib/browser-electron/process.d.ts +0 -14
- package/lib/browser-electron/provider.d.ts +0 -959
- package/lib/browser-electron/remote-host.d.ts +0 -256
- package/lib/browser-electron/rpc-input.d.ts +0 -4
- package/lib/browser-electron/rpc-ops.d.ts +0 -18
- package/lib/browser-electron/runtime-diagnostics.d.ts +0 -12
- package/lib/browser-electron/runtime-route.d.ts +0 -55
- package/lib/browser-electron/runtime-status.d.ts +0 -116
- package/lib/browser-electron/settings-route.d.ts +0 -15
- package/lib/browser-electron/settings-store.d.ts +0 -224
- package/lib/browser-electron/sidebar-only-host.d.ts +0 -36
- package/lib/browser-electron/system-browser.d.ts +0 -367
- package/lib/browser-electron/timing.d.ts +0 -8
- package/lib/browser-electron/virtual-cursor.d.ts +0 -67
- package/lib/browser-electron/windows-system.d.ts +0 -3
- package/lib/index.d.ts +0 -30
- package/lib/tool-browser/element-fields.d.ts +0 -145
- package/lib/tool-browser/index.d.ts +0 -53
- package/lib/tool-browser/page-probe.d.ts +0 -86
- package/scripts/consumer-install-check.mjs +0 -72
- package/scripts/run-tests.mjs +0 -32
- package/scripts/verify-host-compat.mjs +0 -195
- package/scripts/verify-preview-route.mjs +0 -168
- package/scripts/verify-runtime-status.mjs +0 -179
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs'
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Legacy standalone Electron browser host (not a supported package export): an
|
|
3
4
|
* {@link ElectronBrowserViewHost} implementation that spawns the plugin's own
|
|
4
5
|
* Electron child process (host-main.js) and drives it over line-delimited
|
|
5
|
-
* JSON-RPC on a loopback TCP socket.
|
|
6
|
-
* surfaces without a desktop shell's electronViewHost (plain dsh web):
|
|
7
|
-
* installing the plugin is enough — the browser window appears on first use.
|
|
6
|
+
* JSON-RPC on a loopback TCP socket.
|
|
8
7
|
*
|
|
9
8
|
* Protocol (one JSON object per line, both directions):
|
|
10
9
|
* -> { id, op: 'createView' } | { id, op: 'destroyView', viewId } |
|
|
@@ -29,15 +28,17 @@
|
|
|
29
28
|
|
|
30
29
|
import { execFileSync, spawn } from 'node:child_process'
|
|
31
30
|
import { appendFileSync, mkdirSync, statSync, writeFileSync } from 'node:fs'
|
|
32
|
-
import { randomBytes } from 'node:crypto'
|
|
31
|
+
import { randomBytes, randomUUID } from 'node:crypto'
|
|
33
32
|
import { createRequire } from 'node:module'
|
|
34
33
|
import { existsSync, readFileSync, readdirSync, readlinkSync } from 'node:fs'
|
|
35
34
|
import { basename, dirname, isAbsolute, join } from 'node:path'
|
|
36
35
|
import { createServer, type Server, type Socket } from 'node:net'
|
|
37
|
-
import { withTimeoutShared } from './timing.
|
|
36
|
+
import { withTimeoutShared } from './timing.ts'
|
|
37
|
+
import { browserHostLogPath } from './paths.ts'
|
|
38
38
|
import { fileURLToPath } from 'node:url'
|
|
39
|
-
import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle, PresentOptions, ScreenshotOptions } from './provider.
|
|
40
|
-
import type { ExportedCookie } from '../browser/types.
|
|
39
|
+
import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle, PresentOptions, ScreenshotOptions } from './provider.ts'
|
|
40
|
+
import type { ExportedCookie } from '../browser/types.ts'
|
|
41
|
+
import { readTabHandle, tabWireId, type BrowserTabWireId } from '../browser/handles.ts'
|
|
41
42
|
|
|
42
43
|
/** How long to wait for the child to signal readiness before failing. */
|
|
43
44
|
const READY_TIMEOUT_MS = 20_000
|
|
@@ -1089,7 +1090,7 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
1089
1090
|
})
|
|
1090
1091
|
await new Promise<void>((resolve, reject) => {
|
|
1091
1092
|
server.once('error', reject)
|
|
1092
|
-
server.listen(0,
|
|
1093
|
+
server.listen(0, LOOPBACK_IPV4, () => resolve())
|
|
1093
1094
|
})
|
|
1094
1095
|
// A later server error (rare on a loopback ephemeral port) must not crash
|
|
1095
1096
|
// the process; the client's fail path handles the actual recovery.
|
|
@@ -1162,10 +1163,11 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
1162
1163
|
// of going stale (only the page state is lost).
|
|
1163
1164
|
}
|
|
1164
1165
|
|
|
1165
|
-
createView(): ElectronViewHandle {
|
|
1166
|
+
createView(identity?: BrowserTabWireId): ElectronViewHandle {
|
|
1166
1167
|
// The seam is synchronous; the provider uses the handle immediately, so
|
|
1167
1168
|
// commands are deferred until the child is up and the view materialized.
|
|
1168
|
-
const id =
|
|
1169
|
+
const id = identity ?? tabWireId({ owner: 'standalone', session: randomUUID(), tab: randomUUID() })
|
|
1170
|
+
readTabHandle(id)
|
|
1169
1171
|
const view = new DeferredRemoteView(id, () => this.ensureView(id))
|
|
1170
1172
|
this.views.set(id, view)
|
|
1171
1173
|
return view
|
|
@@ -1415,11 +1417,9 @@ function hostStamp(): string {
|
|
|
1415
1417
|
}
|
|
1416
1418
|
|
|
1417
1419
|
function appendHostLog(text: string): void {
|
|
1418
|
-
const home = process.env.DSH_HOME
|
|
1419
|
-
if (home === undefined || home === '') return
|
|
1420
1420
|
try {
|
|
1421
|
-
const
|
|
1422
|
-
const
|
|
1421
|
+
const file = browserHostLogPath()
|
|
1422
|
+
const dir = dirname(file)
|
|
1423
1423
|
try {
|
|
1424
1424
|
if (statSync(file).size > HOST_LOG_MAX_BYTES) {
|
|
1425
1425
|
// Discard the old bytes but leave a dated marker: truncating to empty
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RUNTIME_STATUS_ROUTE, RUNTIME_PROVISION_ROUTE } from '../../assets/browser-policy.mjs'
|
|
1
2
|
/**
|
|
2
3
|
* The readiness endpoints the settings panel reads.
|
|
3
4
|
*
|
|
@@ -10,13 +11,13 @@
|
|
|
10
11
|
* @module dsh-browser/browser-electron/runtime-route
|
|
11
12
|
*/
|
|
12
13
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
13
|
-
import type { ProvisionSnapshot } from './electron-provision.
|
|
14
|
-
import { replyJson } from './json-reply.
|
|
15
|
-
import { sameOrigin } from './settings-route.
|
|
16
|
-
import type { RuntimeStatusReport } from './runtime-status.
|
|
14
|
+
import type { ProvisionSnapshot } from './electron-provision.ts'
|
|
15
|
+
import { replyJson } from './json-reply.ts'
|
|
16
|
+
import { sameOrigin } from './settings-route.ts'
|
|
17
|
+
import type { RuntimeStatusReport } from './runtime-status.ts'
|
|
17
18
|
|
|
18
19
|
/** Where the panel reads readiness. */
|
|
19
|
-
export
|
|
20
|
+
export { RUNTIME_STATUS_ROUTE }
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Where the panel asks for the bundled runtime.
|
|
@@ -26,12 +27,12 @@ export const RUNTIME_STATUS_ROUTE = '/dsh-builtin-browser/runtime-status'
|
|
|
26
27
|
* would time out in the browser long before a slow network finished, and would hold a connection
|
|
27
28
|
* open for something the panel can poll instead.
|
|
28
29
|
*/
|
|
29
|
-
export
|
|
30
|
+
export { RUNTIME_PROVISION_ROUTE }
|
|
30
31
|
|
|
31
32
|
/** What both handlers need. */
|
|
32
33
|
export interface RuntimeRouteDeps {
|
|
33
34
|
/** The current report; a cheap read, never a spawn. */
|
|
34
|
-
readonly report: () => RuntimeStatusReport
|
|
35
|
+
readonly report: () => RuntimeStatusReport | Promise<RuntimeStatusReport>
|
|
35
36
|
/**
|
|
36
37
|
* Start (or join) a provision and return the state it is in now.
|
|
37
38
|
*
|
|
@@ -60,7 +61,7 @@ export async function handleRuntimeStatus(
|
|
|
60
61
|
replyJson(response, 403, { error: 'not-same-origin' })
|
|
61
62
|
return
|
|
62
63
|
}
|
|
63
|
-
replyJson(response, 200, { ok: true, runtime: deps.report() })
|
|
64
|
+
replyJson(response, 200, { ok: true, runtime: await deps.report() })
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/**
|
|
@@ -95,10 +96,10 @@ export async function handleRuntimeProvision(
|
|
|
95
96
|
// an answer it can render, rather than a dropped connection it cannot tell from a hang.
|
|
96
97
|
replyJson(response, 200, {
|
|
97
98
|
ok: true,
|
|
98
|
-
runtime: deps.report(),
|
|
99
|
+
runtime: await deps.report(),
|
|
99
100
|
provisionError: String(error),
|
|
100
101
|
})
|
|
101
102
|
return
|
|
102
103
|
}
|
|
103
|
-
replyJson(response, 200, { ok: true, runtime: deps.report(), provision: snapshot })
|
|
104
|
+
replyJson(response, 200, { ok: true, runtime: await deps.report(), provision: snapshot })
|
|
104
105
|
}
|
|
@@ -20,19 +20,22 @@
|
|
|
20
20
|
* a particular page can be driven. Nothing spawns anything.
|
|
21
21
|
* @module dsh-browser/browser-electron/runtime-status
|
|
22
22
|
*/
|
|
23
|
-
import type { BridgeStatus } from './bridge-status.
|
|
24
|
-
import type { BridgeEndpointState } from './bridge-endpoint.
|
|
25
|
-
import type { ProvisionSnapshot } from './electron-provision.
|
|
26
|
-
import
|
|
23
|
+
import type { BridgeStatus } from './bridge-status.ts'
|
|
24
|
+
import type { BridgeEndpointState } from './bridge-endpoint.ts'
|
|
25
|
+
import type { ProvisionSnapshot } from './electron-provision.ts'
|
|
26
|
+
import type { ExtensionConnectionStatus } from '../../native-host/client.mjs'
|
|
27
|
+
import type { extensionInstallHelp } from './extension-browser.ts'
|
|
28
|
+
import { detectBrowser, type BrowserChannel, type DetectedBrowser, type SystemBrowserLaunchDiagnostic } from './system-browser.ts'
|
|
27
29
|
|
|
28
30
|
/** The part of the carrier the channel names, in the terms the panel has to explain. */
|
|
29
|
-
export type CarrierKind = 'sidebar' | 'bundled' | 'system' | 'auto'
|
|
31
|
+
export type CarrierKind = 'sidebar' | 'bundled' | 'system' | 'extension' | 'cdp' | 'auto'
|
|
30
32
|
|
|
31
33
|
/** Whether the chosen carrier's required files or running bridge are available. */
|
|
32
34
|
export type Readiness = 'ready' | 'blocked'
|
|
33
35
|
|
|
34
36
|
/** The system-browser discovery result, obtained without launching an executable. */
|
|
35
37
|
export interface SystemBrowserReadiness {
|
|
38
|
+
readonly launch?: SystemBrowserLaunchDiagnostic
|
|
36
39
|
/** False for channels that use the sidebar or bundled runtime directly. */
|
|
37
40
|
readonly checked: boolean
|
|
38
41
|
readonly present: boolean
|
|
@@ -54,6 +57,8 @@ export interface ElectronReadiness {
|
|
|
54
57
|
|
|
55
58
|
/** The desktop sidebar bridge, or the honest "there is no desktop here" shape. */
|
|
56
59
|
export interface BridgeReadiness {
|
|
60
|
+
readonly mainExtension?: BridgeStatus['mainExtension']
|
|
61
|
+
readonly code?: string
|
|
57
62
|
/** Whether a DSH Desktop install was found at all. */
|
|
58
63
|
readonly present: boolean
|
|
59
64
|
/** `absent` is reported separately from `missing`: nothing to repair versus something to repair. */
|
|
@@ -77,6 +82,10 @@ export interface BridgeReadiness {
|
|
|
77
82
|
|
|
78
83
|
/** The whole report. */
|
|
79
84
|
export interface RuntimeStatusReport {
|
|
85
|
+
readonly nativeHostRegistration?: Record<string, { registered: boolean; detail: string }>
|
|
86
|
+
readonly controlledProfile: 'plugin' | 'user' | 'sidebar'
|
|
87
|
+
readonly extension?: ExtensionConnectionStatus & { readonly install?: ReturnType<typeof extensionInstallHelp>; readonly registration?: { registered: boolean; detail: string } }
|
|
88
|
+
readonly fallbackReason?: string
|
|
80
89
|
/** What the settings document says, verbatim: the panel shows the switch it is honouring. */
|
|
81
90
|
readonly channel: BrowserChannel
|
|
82
91
|
/** What that channel resolves to, in panel terms. */
|
|
@@ -96,6 +105,10 @@ export interface RuntimeStatusReport {
|
|
|
96
105
|
|
|
97
106
|
/** Everything the report reads, so a test can answer without any of the real machinery. */
|
|
98
107
|
export interface RuntimeStatusDeps {
|
|
108
|
+
readonly nativeHostRegistration?: () => NonNullable<RuntimeStatusReport['nativeHostRegistration']>
|
|
109
|
+
readonly fallbackReason?: () => string | undefined
|
|
110
|
+
readonly systemProfile?: () => 'user' | 'plugin'
|
|
111
|
+
readonly extensionConnection?: () => RuntimeStatusReport['extension']
|
|
99
112
|
/** The stored `browser.channel`. */
|
|
100
113
|
readonly channel: () => BrowserChannel
|
|
101
114
|
/** Whether a launch would find an Electron binary — the launch path's own probe. */
|
|
@@ -104,25 +117,19 @@ export interface RuntimeStatusDeps {
|
|
|
104
117
|
readonly provision: () => ProvisionSnapshot
|
|
105
118
|
/** The desktop install's bridge state, or undefined when there is no desktop install. */
|
|
106
119
|
readonly bridge: () => BridgeStatus | undefined
|
|
120
|
+
readonly bridgeError?: () => string | undefined
|
|
107
121
|
/** The endpoint the shell publishes while it runs; undefined when nothing published one. */
|
|
108
122
|
readonly endpoint: () => BridgeEndpointState | undefined
|
|
109
123
|
/** The launch path's filesystem-only browser discovery; defaults to the production reader. */
|
|
110
124
|
readonly detectBrowser?: (channel: BrowserChannel) => DetectedBrowser | undefined
|
|
111
125
|
/** The provider's current carrier, including a fallback selected after sidebar loss. */
|
|
112
126
|
readonly selectedCarrier?: () => Exclude<CarrierKind, 'auto'> | undefined
|
|
127
|
+
readonly systemConnection?: () => { connected: boolean; detail: string; launch?: SystemBrowserLaunchDiagnostic } | undefined
|
|
113
128
|
}
|
|
114
129
|
|
|
115
130
|
/** Which carrier a channel names. */
|
|
116
131
|
function carrierOf(channel: BrowserChannel): CarrierKind {
|
|
117
|
-
|
|
118
|
-
if (channel === 'bundled') return 'bundled'
|
|
119
|
-
if (channel === 'auto') return 'auto'
|
|
120
|
-
return 'system'
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/** Whether a binary being present settles the Electron question. */
|
|
124
|
-
function electronReady(state: ElectronReadiness['state']): boolean {
|
|
125
|
-
return state === 'present' || state === 'ready'
|
|
132
|
+
return channel === 'chrome' || channel === 'edge' ? 'system' : 'sidebar'
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
/**
|
|
@@ -136,7 +143,11 @@ function electronReady(state: ElectronReadiness['state']): boolean {
|
|
|
136
143
|
*/
|
|
137
144
|
export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport {
|
|
138
145
|
const channel = deps.channel()
|
|
139
|
-
const
|
|
146
|
+
const preferExtension = (channel === 'edge' || channel === 'chrome') && deps.systemProfile?.() === 'user'
|
|
147
|
+
const carrier = preferExtension ? 'extension' : carrierOf(channel)
|
|
148
|
+
const extension = carrier === 'extension' ? deps.extensionConnection?.() ?? {
|
|
149
|
+
state: 'extension-missing' as const, connected: false, browser: channel as 'edge' | 'chrome', detail: 'Optional extension is not connected; managed CDP is available as fallback.',
|
|
150
|
+
} : undefined
|
|
140
151
|
|
|
141
152
|
// The binary check comes first and wins: a runtime that is on disk is ready whatever the
|
|
142
153
|
// provisioning state machine last said, which is also how a runtime installed by hand (or by an
|
|
@@ -156,7 +167,7 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
|
|
|
156
167
|
|
|
157
168
|
const bridgeStatus = deps.bridge()
|
|
158
169
|
const endpoint = deps.endpoint()
|
|
159
|
-
const
|
|
170
|
+
const installedBridge: BridgeReadiness = bridgeStatus === undefined
|
|
160
171
|
? {
|
|
161
172
|
present: false,
|
|
162
173
|
state: 'absent',
|
|
@@ -171,22 +182,30 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
|
|
|
171
182
|
running: endpoint?.alive === true,
|
|
172
183
|
runningDetail: endpoint?.detail ?? 'no desktop shell has published a bridge endpoint',
|
|
173
184
|
...bridgeStatus.command === undefined ? {} : { command: bridgeStatus.command },
|
|
185
|
+
...bridgeStatus.mainExtension === undefined ? {} : { mainExtension: bridgeStatus.mainExtension },
|
|
186
|
+
...bridgeStatus.code === undefined ? {} : { code: bridgeStatus.code },
|
|
174
187
|
}
|
|
175
188
|
|
|
189
|
+
const bridgeError = deps.bridgeError?.()
|
|
190
|
+
const bridge: BridgeReadiness = bridgeError === undefined ? installedBridge
|
|
191
|
+
: { ...installedBridge, state: 'stale', detail: bridgeError }
|
|
192
|
+
|
|
176
193
|
// The sidebar needs BOTH halves: our patch inside the shell it will be driven through, and that
|
|
177
194
|
// shell actually running. Either one alone is the false green this report exists to prevent.
|
|
178
195
|
const sidebarReady = bridge.state === 'installed' && bridge.running
|
|
179
196
|
|
|
180
|
-
const
|
|
197
|
+
const selected = preferExtension ? deps.selectedCarrier?.() ?? (extension?.connected ? 'extension' : 'cdp') : undefined
|
|
198
|
+
const checkSystemBrowser = carrier === 'system' || selected === 'cdp'
|
|
181
199
|
const detected = checkSystemBrowser ? (deps.detectBrowser ?? detectBrowser)(channel) : undefined
|
|
200
|
+
const connection = checkSystemBrowser ? deps.systemConnection?.() : undefined
|
|
182
201
|
const systemBrowser: SystemBrowserReadiness = {
|
|
202
|
+
...connection?.launch === undefined ? {} : { launch: connection.launch },
|
|
183
203
|
checked: checkSystemBrowser,
|
|
184
204
|
present: detected !== undefined,
|
|
185
205
|
...detected === undefined ? {} : { kind: detected.kind, path: detected.path },
|
|
186
|
-
detail: detected !== undefined ?
|
|
206
|
+
detail: detected !== undefined ? connection?.detail ?? 'Browser has not launched; run a browser command to establish CDP. No live CDP connection.'
|
|
187
207
|
: !checkSystemBrowser ? `the ${carrier} channel uses its own carrier`
|
|
188
|
-
:
|
|
189
|
-
: `the selected ${channel} installation was not found`,
|
|
208
|
+
: `the selected ${channel} installation was not found`,
|
|
190
209
|
}
|
|
191
210
|
|
|
192
211
|
let readiness: Readiness
|
|
@@ -194,20 +213,22 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
|
|
|
194
213
|
if (carrier === 'sidebar') {
|
|
195
214
|
resolvedCarrier = 'sidebar'
|
|
196
215
|
readiness = sidebarReady ? 'ready' : 'blocked'
|
|
197
|
-
} else if (
|
|
198
|
-
resolvedCarrier = '
|
|
199
|
-
readiness =
|
|
200
|
-
} else if (carrier === '
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
resolvedCarrier = deps.selectedCarrier?.() ?? (sidebarReady ? 'sidebar' : detected !== undefined ? 'system' : 'bundled')
|
|
204
|
-
readiness = (resolvedCarrier === 'sidebar' ? sidebarReady : resolvedCarrier === 'system' ? detected !== undefined : electronReady(state)) ? 'ready' : 'blocked'
|
|
216
|
+
} else if (selected === 'cdp') {
|
|
217
|
+
resolvedCarrier = 'cdp'
|
|
218
|
+
readiness = detected !== undefined && connection?.connected === true ? 'ready' : 'blocked'
|
|
219
|
+
} else if (carrier === 'extension') {
|
|
220
|
+
resolvedCarrier = 'extension'
|
|
221
|
+
readiness = extension?.state === 'connected' && extension.connected ? 'ready' : 'blocked'
|
|
205
222
|
} else {
|
|
206
223
|
resolvedCarrier = 'system'
|
|
207
|
-
readiness = detected !== undefined ? 'ready' : 'blocked'
|
|
224
|
+
readiness = detected !== undefined && connection?.connected === true ? 'ready' : 'blocked'
|
|
208
225
|
}
|
|
209
226
|
|
|
210
227
|
return {
|
|
228
|
+
...deps.nativeHostRegistration ? { nativeHostRegistration: deps.nativeHostRegistration() } : {},
|
|
229
|
+
controlledProfile: resolvedCarrier === 'extension' ? 'user' : resolvedCarrier === 'system' || resolvedCarrier === 'cdp' ? 'plugin' : 'sidebar',
|
|
230
|
+
...(preferExtension && resolvedCarrier === 'cdp' ? { fallbackReason: deps.fallbackReason?.() ?? (extension?.state === 'disabled' ? 'disabled' : 'not-connected') } : {}),
|
|
231
|
+
...extension === undefined ? {} : { extension },
|
|
211
232
|
channel,
|
|
212
233
|
carrier,
|
|
213
234
|
resolvedCarrier,
|
|
@@ -216,8 +237,6 @@ export function readRuntimeStatus(deps: RuntimeStatusDeps): RuntimeStatusReport
|
|
|
216
237
|
...resolvedCarrier === 'system' && detected !== undefined ? { executable: detected.path } : {},
|
|
217
238
|
electron,
|
|
218
239
|
bridge,
|
|
219
|
-
|
|
220
|
-
// the shared attempt exists to prevent.
|
|
221
|
-
canProvision: !electronReady(state) && state !== 'preparing',
|
|
240
|
+
canProvision: false,
|
|
222
241
|
}
|
|
223
242
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs'
|
|
1
2
|
/**
|
|
2
3
|
* Plugin-owned settings document — the switches the browser settings panel
|
|
3
4
|
* exposes, stored next to the browsing history so both follow the same rules:
|
|
@@ -11,8 +12,8 @@
|
|
|
11
12
|
|
|
12
13
|
import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
13
14
|
import { dirname, join } from 'node:path'
|
|
14
|
-
import { dshHome } from './paths.
|
|
15
|
-
import type { BrowserChannel } from './system-browser.
|
|
15
|
+
import { dshHome } from './paths.ts'
|
|
16
|
+
import type { BrowserChannel } from './system-browser.ts'
|
|
16
17
|
|
|
17
18
|
/** Vision/operation strategy the provider prefers when the model can see. */
|
|
18
19
|
export type VisionStrategy = 'auto' | 'nonVisual'
|
|
@@ -28,6 +29,18 @@ export type HeadlessMode = 'auto' | 'headless' | 'windowed'
|
|
|
28
29
|
/** Every value {@link HeadlessMode} accepts, for validation and the settings UI. */
|
|
29
30
|
export const HEADLESS_MODES = ['auto', 'headless', 'windowed'] as const
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Which profile the browser runs on.
|
|
34
|
+
*
|
|
35
|
+
* `plugin` 是插件自己的目录(默认):不碰用户的窗口、书签与登录态,也不会因为用户开着浏览器而启动失败。
|
|
36
|
+
* `user` 复用用户自己的 profile,登录态天然可用,但要求用户的浏览器先关掉——否则 Chromium 以
|
|
37
|
+
* exit 21(`PROFILE_IN_USE`)退出。
|
|
38
|
+
*/
|
|
39
|
+
export type SystemProfile = 'user' | 'plugin'
|
|
40
|
+
|
|
41
|
+
/** Every value {@link SystemProfile} accepts, for validation and the settings UI. */
|
|
42
|
+
export const SYSTEM_PROFILES = ['user', 'plugin'] as const
|
|
43
|
+
|
|
31
44
|
/** The full settings document, with every field resolved. */
|
|
32
45
|
export interface BrowserSettings {
|
|
33
46
|
/** Persistent browsing history (visited pages). */
|
|
@@ -90,6 +103,11 @@ export interface BrowserSettings {
|
|
|
90
103
|
* immediately after launch".
|
|
91
104
|
*/
|
|
92
105
|
readonly headless: HeadlessMode
|
|
106
|
+
/**
|
|
107
|
+
* `plugin` (default) launches a separate DSH-owned persistent profile.
|
|
108
|
+
* Explicit `user` attaches to the running, paired extension profile; never launches it.
|
|
109
|
+
*/
|
|
110
|
+
readonly systemProfile: SystemProfile
|
|
93
111
|
}
|
|
94
112
|
/** Whether the agent may read cookies / export login state. */
|
|
95
113
|
readonly credentials: {
|
|
@@ -160,10 +178,8 @@ export const DEFAULT_SETTINGS: BrowserSettings = {
|
|
|
160
178
|
cookies: { persist: true },
|
|
161
179
|
ui: { autoExpandOnce: true, closeWithSession: false, virtualCursor: true, quiet: false },
|
|
162
180
|
vision: { strategy: 'auto' },
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
// it starts a real Chrome/Edge with its own profile.
|
|
166
|
-
browser: { channel: 'bundled', headless: 'auto' },
|
|
181
|
+
// External browsers require an explicit choice; automatic modes never open native windows.
|
|
182
|
+
browser: { channel: 'sidebar', headless: 'auto', systemProfile: 'plugin' },
|
|
167
183
|
credentials: { allowRead: true },
|
|
168
184
|
// Off unless the host turns it on. A frame can show a CAPTCHA, an account name, or logged-in
|
|
169
185
|
// content, so watching is an explicit decision rather than something a remote client can arrange.
|
|
@@ -182,7 +198,7 @@ export const DEFAULT_SETTINGS: BrowserSettings = {
|
|
|
182
198
|
*/
|
|
183
199
|
export function settingsPath(): string {
|
|
184
200
|
const home = dshHome()
|
|
185
|
-
return join(home,
|
|
201
|
+
return join(home, BROWSER_PROFILE_DIR, 'settings.json')
|
|
186
202
|
}
|
|
187
203
|
|
|
188
204
|
/** Coerce one boolean field, keeping the default when absent or mistyped. */
|
|
@@ -367,6 +383,10 @@ export function resolveSettings(raw: unknown, warn?: (message: string) => void):
|
|
|
367
383
|
browser: {
|
|
368
384
|
channel: resolveChannel(browser?.channel, warn),
|
|
369
385
|
headless: resolveHeadless(browser?.headless, warn),
|
|
386
|
+
// 不认识的值退回 `plugin`:这一侧不会与用户正在运行的浏览器抢 profile,是"装好即用"的前提。
|
|
387
|
+
// 之前这一层不产出该字段,`entry.ts` 的 `systemProfile !== 'plugin'` 恒成立,浏览器总是跑在用户
|
|
388
|
+
// profile 上——用户开着 Edge 时 Chromium 以 exit 21 退出,插件报"引擎起不来"。
|
|
389
|
+
systemProfile: (browser as { systemProfile?: unknown } | undefined)?.systemProfile === 'user' ? 'user' : 'plugin',
|
|
370
390
|
},
|
|
371
391
|
credentials: {
|
|
372
392
|
// `gate` returns false for anything present-and-not-a-boolean, so an unreadable section
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { SHORTCUTS_ROUTE, SHORTCUT_ADD_ROUTE, SHORTCUT_REMOVE_ROUTE } from '../../assets/browser-policy.mjs'
|
|
2
|
+
/**
|
|
3
|
+
* HTTP face of the shared start-page shortcut list.
|
|
4
|
+
*
|
|
5
|
+
* Three exact paths, deliberately minimal: the sidebar keeps editing the section
|
|
6
|
+
* through the settings RPC (its own UI), while this face exists so an agent — which
|
|
7
|
+
* has no sidebar and no settings form — can list, add and drop shortcuts on the same
|
|
8
|
+
* data. Both writers go through `ctx.settings`, so there is exactly one list.
|
|
9
|
+
* @module dsh-browser/browser-electron/shortcuts-route
|
|
10
|
+
*/
|
|
11
|
+
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
12
|
+
import type { BrowserHttpHandler } from './authenticated-route.ts'
|
|
13
|
+
import { isDirectLoopback } from './authenticated-route.ts'
|
|
14
|
+
import { readJsonBody } from './http-body.ts'
|
|
15
|
+
import { replyJson } from './json-reply.ts'
|
|
16
|
+
import { sameOrigin } from './settings-route.ts'
|
|
17
|
+
import { ShortcutError, type createShortcutStore } from './startpage-shortcuts.ts'
|
|
18
|
+
|
|
19
|
+
/** Read the shared shortcut list. */
|
|
20
|
+
export { SHORTCUTS_ROUTE }
|
|
21
|
+
/** Append one shortcut. */
|
|
22
|
+
export { SHORTCUT_ADD_ROUTE }
|
|
23
|
+
/** Drop one shortcut by id. */
|
|
24
|
+
export { SHORTCUT_REMOVE_ROUTE }
|
|
25
|
+
|
|
26
|
+
type Store = ReturnType<typeof createShortcutStore>
|
|
27
|
+
|
|
28
|
+
/** The handlers, one per registered exact path. */
|
|
29
|
+
export interface ShortcutRouteHandlers {
|
|
30
|
+
readonly list: BrowserHttpHandler
|
|
31
|
+
readonly add: BrowserHttpHandler
|
|
32
|
+
readonly remove: BrowserHttpHandler
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function requireWrite(request: IncomingMessage, response: ServerResponse): boolean {
|
|
36
|
+
if (request.method !== 'POST') { replyJson(response, 405, { ok: false, error: 'method-not-allowed' }); return false }
|
|
37
|
+
if (!sameOrigin(request, true)) { replyJson(response, 403, { ok: false, error: 'not-same-origin' }); return false }
|
|
38
|
+
if (!isDirectLoopback(request)) { replyJson(response, 403, { ok: false, error: 'local-request-required' }); return false }
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Turn a refusal into a status a caller can branch on.
|
|
44
|
+
* @param error - anything a handler threw.
|
|
45
|
+
* @param response - the response to write when it is a known refusal.
|
|
46
|
+
* @returns true when the error was answered.
|
|
47
|
+
*/
|
|
48
|
+
function refuse(error: unknown, response: ServerResponse): boolean {
|
|
49
|
+
if (!(error instanceof ShortcutError)) return false
|
|
50
|
+
const status = error.code === 'unavailable' ? 503
|
|
51
|
+
: error.code === 'conflict' ? 409
|
|
52
|
+
: error.code === 'limit' ? 422
|
|
53
|
+
: 400
|
|
54
|
+
replyJson(response, status, { ok: false, error: error.code, message: error.message })
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Build every shortcut handler over one store. */
|
|
59
|
+
export function createShortcutRouteHandlers(store: Store): ShortcutRouteHandlers {
|
|
60
|
+
const list: BrowserHttpHandler = (request, response) => {
|
|
61
|
+
if (request.method !== 'GET') { replyJson(response, 405, { ok: false, error: 'method-not-allowed' }); return }
|
|
62
|
+
try {
|
|
63
|
+
const reading = store.list()
|
|
64
|
+
replyJson(response, 200, { ok: true, shortcuts: reading.shortcuts, revision: reading.revision })
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (refuse(error, response)) return
|
|
67
|
+
replyJson(response, 500, { ok: false, error: String(error) })
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const add: BrowserHttpHandler = async (request, response) => {
|
|
72
|
+
if (!requireWrite(request, response)) return
|
|
73
|
+
let body: Record<string, unknown>
|
|
74
|
+
try {
|
|
75
|
+
body = await readJsonBody<Record<string, unknown>>(request)
|
|
76
|
+
} catch (error) {
|
|
77
|
+
replyJson(response, 400, { ok: false, error: `unreadable body: ${String(error)}` })
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const result = await store.add({ title: body.title, url: body.url, iconKey: body.iconKey })
|
|
82
|
+
replyJson(response, 200, { ok: true, shortcut: result.shortcut, shortcuts: result.shortcuts })
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (refuse(error, response)) return
|
|
85
|
+
replyJson(response, 500, { ok: false, error: String(error) })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const remove: BrowserHttpHandler = async (request, response) => {
|
|
90
|
+
if (!requireWrite(request, response)) return
|
|
91
|
+
let body: Record<string, unknown>
|
|
92
|
+
try {
|
|
93
|
+
body = await readJsonBody<Record<string, unknown>>(request)
|
|
94
|
+
} catch (error) {
|
|
95
|
+
replyJson(response, 400, { ok: false, error: `unreadable body: ${String(error)}` })
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
if (typeof body.id !== 'string' || body.id === '') {
|
|
99
|
+
replyJson(response, 400, { ok: false, error: 'id is required' })
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const result = await store.remove(body.id)
|
|
104
|
+
replyJson(response, result.removed ? 200 : 404, { ok: result.removed, shortcuts: result.shortcuts })
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (refuse(error, response)) return
|
|
107
|
+
replyJson(response, 500, { ok: false, error: String(error) })
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return { list, add, remove }
|
|
112
|
+
}
|