dsh-builtin-browser 1.0.3 → 1.1.0
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 +16 -1
- package/README.en.md +89 -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/desktop-bridge/desktop-identity.json +10 -2
- package/desktop-bridge/install.mjs +28 -2
- package/docs/issue-replies-2026-11-28.md +141 -0
- package/dsh-host-patch/apply.mjs +1 -1
- package/dsh-host-patch/rc3.json +4 -4
- package/dsh-host-patch/rc5.json +4 -4
- package/dsh-host-patch/v023-alpha2.json +2 -2
- package/lib/browser-electron/bridge-status.js +24 -1
- package/lib/browser-electron/desktop-identity.js +47 -8
- package/lib/client.js +2 -1
- package/native-host/install.mjs +5 -0
- package/package.json +20 -2
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +69 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +40 -0
- package/scripts/install-electron.mjs +101 -0
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +58 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +98 -0
- package/skills/dsh-builtin-browser/references/batch.md +68 -0
- package/skills/dsh-builtin-browser/references/deliver.md +31 -0
- package/skills/dsh-builtin-browser/references/locate.md +11 -0
- package/skills/dsh-builtin-browser/references/recover.md +11 -0
- package/skills/dsh-builtin-browser/references/verify.md +13 -0
- 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/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +578 -0
- package/src/browser/takeover-target.ts +45 -0
- package/src/browser/types.ts +870 -0
- package/src/browser-electron/authenticated-route.ts +109 -0
- package/src/browser-electron/automatic-maintenance.ts +736 -0
- package/src/browser-electron/bridge-auto.ts +159 -0
- package/src/browser-electron/bridge-connection.ts +386 -0
- package/src/browser-electron/bridge-endpoint.ts +129 -0
- package/src/browser-electron/bridge-install.ts +290 -0
- package/src/browser-electron/bridge-maintenance.ts +189 -0
- package/src/browser-electron/bridge-status.ts +412 -0
- package/src/browser-electron/desktop-bridge-host.ts +253 -0
- package/src/browser-electron/desktop-identity.ts +400 -0
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +347 -0
- package/src/browser-electron/entry.ts +1378 -0
- package/src/browser-electron/ephemeral-profile.ts +189 -0
- package/src/browser-electron/extension-browser.ts +230 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/file-write.ts +31 -0
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +177 -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 +716 -0
- package/src/browser-electron/guest-runtime.ts +408 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +120 -0
- package/src/browser-electron/history-store.ts +224 -0
- package/src/browser-electron/host-main.ts +1385 -0
- package/src/browser-electron/host-patch-maintenance.ts +121 -0
- package/src/browser-electron/http-body.ts +65 -0
- package/src/browser-electron/json-reply.ts +47 -0
- package/src/browser-electron/maintenance-broker.ts +166 -0
- package/src/browser-electron/maintenance-lifecycle.ts +91 -0
- package/src/browser-electron/maintenance-route.ts +68 -0
- package/src/browser-electron/missing-system-browser.ts +114 -0
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +25 -0
- package/src/browser-electron/preferred-browser.ts +130 -0
- package/src/browser-electron/preview-route.ts +215 -0
- package/src/browser-electron/process-ownership.ts +174 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +47 -0
- package/src/browser-electron/profile-extension.ts +129 -0
- package/src/browser-electron/profile-lease.ts +211 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider-core.ts +1107 -0
- package/src/browser-electron/provider-interaction.ts +1034 -0
- package/src/browser-electron/provider-media.ts +589 -0
- package/src/browser-electron/provider-navigation.ts +323 -0
- package/src/browser-electron/provider-observation.ts +664 -0
- package/src/browser-electron/provider-tabs.ts +372 -0
- package/src/browser-electron/provider.ts +666 -0
- package/src/browser-electron/reference-route.ts +598 -0
- package/src/browser-electron/remote-host.ts +1538 -0
- package/src/browser-electron/rpc-input.ts +13 -0
- package/src/browser-electron/rpc-ops.ts +41 -0
- package/src/browser-electron/runtime-diagnostics.ts +38 -0
- package/src/browser-electron/runtime-route.ts +105 -0
- package/src/browser-electron/runtime-status.ts +309 -0
- package/src/browser-electron/settings-route.ts +64 -0
- package/src/browser-electron/settings-store.ts +593 -0
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +300 -0
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +1850 -0
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/virtual-cursor.ts +162 -0
- package/src/browser-electron/windows-system.ts +24 -0
- 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 +1346 -0
- package/src/browser-reference/store.ts +172 -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 +106 -0
- package/src/client/apply-guard.ts +22 -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 +182 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -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 +56 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +36 -0
- package/src/client/electron/ElectronWebViewImpl.ts +371 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
- package/src/client/electron/NativeChildPresentation.ts +53 -0
- package/src/client/electron/NativeViewPage.ts +265 -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 +333 -0
- package/src/client/locales.ts +860 -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 +208 -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 +447 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +72 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +512 -0
- package/src/client/reference/client/production/http-transport.ts +212 -0
- package/src/client/reference/client/production/production-submission.ts +70 -0
- package/src/client/reference/client/production/protocol.ts +234 -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 +1056 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +99 -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 +67 -0
- package/src/client/reference/client/reveal.ts +109 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/session-schedule.ts +36 -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 +42 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +2773 -0
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +300 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +315 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +365 -0
- package/src/client/view/StartPage.tsx +598 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/compat/host-features.ts +92 -0
- package/src/index.ts +110 -0
- 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 +219 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +28 -0
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +555 -0
- package/src/tool-browser/code-worker.ts +725 -0
- package/src/tool-browser/element-fields.ts +167 -0
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +265 -0
- package/src/tool-browser/page-probe.ts +675 -0
- package/src/tool-browser/panel-page.ts +126 -0
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +199 -0
- package/src/tool-browser/tools-debug.ts +806 -0
- package/src/tool-browser/tools-interaction.ts +956 -0
- package/src/tool-browser/tools-navigation.ts +786 -0
- package/src/tool-browser/tools-observation.ts +474 -0
- package/src/tool-browser/tools-reference.ts +294 -0
- package/src/types/electron-shim.d.ts +144 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +35 -0
- package/tools/accept-desktop.mjs +148 -0
- package/dist/client.d.cts +0 -516
- package/dist/client.d.mts +0 -516
- package/dist/index.cjs +0 -92
- package/dist/index.d.mts +0 -2960
- package/dist/index.mjs +0 -24
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +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 +0 -218
- 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 +0 -260
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A host that exists only to explain why the browser you asked for is not here.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
* When the browser setting names a browser explicitly (Chrome or Edge rather than
|
|
6
|
+
* "bundled" or "automatic"), the plugin used to log a warning and quietly fall back
|
|
7
|
+
* to its own Electron window. That is worse than failing: you asked for Chrome, you
|
|
8
|
+
* got an Electron window, and the error that eventually surfaced talked about
|
|
9
|
+
* Electron — pointing at something you never chose and never wanted to install. The
|
|
10
|
+
* actual problem ("no Chrome on this machine") never reached you.
|
|
11
|
+
*
|
|
12
|
+
* So the two choices are treated as the different requests they are:
|
|
13
|
+
* - `auto` means "any browser will do", and falling back to the bundled one is the
|
|
14
|
+
* behaviour it asks for;
|
|
15
|
+
* - `chrome` / `edge` are explicit, and an explicit request that cannot be met is
|
|
16
|
+
* reported as such, with the ways out of it.
|
|
17
|
+
*
|
|
18
|
+
* `available()` reports true on purpose. Reporting false would make the provider pick
|
|
19
|
+
* a different carrier and hide the problem again, which is exactly the bug.
|
|
20
|
+
*/
|
|
21
|
+
import type { ElectronBrowserViewHost, ElectronViewHandle } from './provider.ts'
|
|
22
|
+
import type { BrowserChannel } from './system-browser.ts'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How each product is named in the message, and what to install.
|
|
26
|
+
*
|
|
27
|
+
* Only chrome and edge can appear: the constructor's type excludes `bundled` and `auto`,
|
|
28
|
+
* and `BrowserChannel` has no `brave`. A brave entry here would be unreachable code.
|
|
29
|
+
*/
|
|
30
|
+
const PRODUCT: Record<string, { label: string; install: string; variable: string }> = {
|
|
31
|
+
chrome: {
|
|
32
|
+
label: 'Google Chrome',
|
|
33
|
+
install: 'install Google Chrome',
|
|
34
|
+
variable: 'DSH_BROWSER_CHROME_PATH',
|
|
35
|
+
},
|
|
36
|
+
edge: {
|
|
37
|
+
label: 'Microsoft Edge',
|
|
38
|
+
install: 'install Microsoft Edge',
|
|
39
|
+
variable: 'DSH_BROWSER_EDGE_PATH',
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** How the setting is named to the user. */
|
|
44
|
+
const SETTING_LABEL: Record<string, string> = {
|
|
45
|
+
chrome: 'installed Chrome',
|
|
46
|
+
edge: 'installed Edge',
|
|
47
|
+
auto: 'automatic',
|
|
48
|
+
bundled: 'bundled',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A carrier that cannot carry anything: every command explains the real problem.
|
|
53
|
+
*
|
|
54
|
+
* The message is written to be acted on, not just read: it says which browser was
|
|
55
|
+
* requested, where the plugin looked, and the three concrete ways to resolve it.
|
|
56
|
+
*/
|
|
57
|
+
export class MissingSystemBrowserHost implements ElectronBrowserViewHost {
|
|
58
|
+
private readonly kind: Exclude<BrowserChannel, 'bundled' | 'auto'>
|
|
59
|
+
private readonly searched: readonly string[]
|
|
60
|
+
constructor(kind: Exclude<BrowserChannel, 'bundled' | 'auto'>, searched: readonly string[]) {
|
|
61
|
+
this.kind = kind
|
|
62
|
+
this.searched = searched
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @returns always true: see the module comment — reporting false would hide this. */
|
|
66
|
+
available(): boolean {
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The message every command fails with.
|
|
72
|
+
* @returns a multi-line explanation with the fixes.
|
|
73
|
+
*/
|
|
74
|
+
private explain(): string {
|
|
75
|
+
const product = PRODUCT[this.kind] ?? { label: this.kind, install: `install ${this.kind}`, variable: 'DSH_BROWSER_<KIND>_PATH' }
|
|
76
|
+
const searched = this.searched.length > 0 ? this.searched.join(', ') : 'PATH and the usual install locations'
|
|
77
|
+
return [
|
|
78
|
+
`dsh-builtin-browser: the browser you selected is not installed — no ${product.label} was found.`,
|
|
79
|
+
``,
|
|
80
|
+
` Setting: browser carrier = "${SETTING_LABEL[this.kind] ?? this.kind}"`,
|
|
81
|
+
` Looked for: ${searched}`,
|
|
82
|
+
``,
|
|
83
|
+
`Nothing else is wrong: the plugin falls back to its own bundled browser only when the`,
|
|
84
|
+
`setting is "bundled" or "automatic". Because this one names a browser explicitly, it`,
|
|
85
|
+
`reports the missing browser instead of silently using a different one.`,
|
|
86
|
+
``,
|
|
87
|
+
`To fix it, any ONE of these is enough:`,
|
|
88
|
+
` 1. ${product.install}, then restart DSH;`,
|
|
89
|
+
` 2. point ${product.variable} at its executable;`,
|
|
90
|
+
` 3. set the browser carrier back to "bundled" (or "automatic" to let it`,
|
|
91
|
+
` fall back on its own next time).`,
|
|
92
|
+
].join('\n')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Create a handle whose every command fails with the explanation.
|
|
97
|
+
* @returns a handle that never reaches a page.
|
|
98
|
+
*/
|
|
99
|
+
createView(): ElectronViewHandle {
|
|
100
|
+
const message = this.explain()
|
|
101
|
+
return {
|
|
102
|
+
id: `missing-${this.kind}`,
|
|
103
|
+
sendCommand: async () => { throw new Error(message) },
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Accept a handle for destruction. Nothing was created, so nothing is released.
|
|
109
|
+
* @param handle - the handle returned by {@link createView}.
|
|
110
|
+
*/
|
|
111
|
+
destroyView(handle: ElectronViewHandle): void {
|
|
112
|
+
void handle
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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, QuietRevealOptions } 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
|
+
readonly browser: 'edge' | 'chrome'
|
|
31
|
+
readonly fallback: ElectronBrowserViewHost & { connectionStatus?: () => { connected: boolean; detail: string } }
|
|
32
|
+
private readonly bound = EXTENSION_READY_TIMEOUT_MS
|
|
33
|
+
constructor(browser: 'edge' | 'chrome', fallback: ElectronBrowserViewHost & { connectionStatus?: () => { connected: boolean; detail: string } }, client?: NativeBrowserClient, bound = EXTENSION_READY_TIMEOUT_MS) {
|
|
34
|
+
this.browser = browser
|
|
35
|
+
this.fallback = fallback
|
|
36
|
+
this.bound = bound
|
|
37
|
+
this.extension = new ExtensionBrowserViewHost(browser, client)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
activeCarrier(): 'extension' | 'cdp' { return this.selected ?? (this.extension.connectionStatus().connected ? 'extension' : 'cdp') }
|
|
41
|
+
get disposed(): boolean { return this.released }
|
|
42
|
+
connectionStatus() { return this.extension.connectionStatus() }
|
|
43
|
+
async refreshStatus() { await this.extension.refreshStatus() }
|
|
44
|
+
async prepare(scope?: BrowserSessionId) { if (scope) await (await this.route(scope)).prepare?.(scope) }
|
|
45
|
+
referenceOverlayOwnerFor(scope: BrowserSessionId): 'client' | undefined {
|
|
46
|
+
const host = this.decisions.get(scope)
|
|
47
|
+
return host ? host.referenceOverlayOwner : 'client'
|
|
48
|
+
}
|
|
49
|
+
connectedView(id: string) {
|
|
50
|
+
const view = this.mapped.get(id)
|
|
51
|
+
return !!view && !view.dead && (this.decisions.get(sessionWireId(readTabHandle(id))) === this.fallback
|
|
52
|
+
? this.fallback.connectionStatus?.().connected === true : this.extension.connectedView(id))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async revealQuietWindow(handle: ElectronViewHandle, options?: QuietRevealOptions): Promise<boolean> {
|
|
56
|
+
const real = await this.mapped.get(handle.id)?.real?.catch(() => undefined)
|
|
57
|
+
return await real?.host.revealQuietWindow?.(real.handle, options) === true
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private route(scope: BrowserSessionId): Promise<ElectronBrowserViewHost> {
|
|
61
|
+
if (this.released) return Promise.reject(new Error('browser carrier was released'))
|
|
62
|
+
let route = this.routes.get(scope)
|
|
63
|
+
if (!route) {
|
|
64
|
+
route = (async () => {
|
|
65
|
+
const ready = await extensionReady(() => this.extension.prepare(), this.bound)
|
|
66
|
+
if (this.released) throw new Error('browser carrier was released')
|
|
67
|
+
this.selected = ready ? 'extension' : 'cdp'
|
|
68
|
+
const state = this.extension.connectionStatus().state
|
|
69
|
+
this.fallbackReason = ready ? undefined : state === 'disabled' ? 'disabled' : state === 'extension-missing' ? 'extension-not-installed' : 'not-connected'
|
|
70
|
+
const host = ready ? this.extension : this.fallback
|
|
71
|
+
this.decisions.set(scope, host)
|
|
72
|
+
return host
|
|
73
|
+
})()
|
|
74
|
+
this.routes.set(scope, route)
|
|
75
|
+
}
|
|
76
|
+
return route
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
createView(id: BrowserTabWireId): ElectronViewHandle {
|
|
80
|
+
if (this.mapped.has(id)) throw new Error('browser view already exists')
|
|
81
|
+
const view: { handle: ElectronViewHandle; real?: Promise<{ host: ElectronBrowserViewHost; handle: ElectronViewHandle }>; dead: boolean } = {
|
|
82
|
+
dead: false, handle: { id, supportsCdpJpeg: true, sendCommand: async (method, params) => {
|
|
83
|
+
if (view.dead || this.released) throw new Error('browser view was released')
|
|
84
|
+
view.real ??= this.route(sessionWireId(readTabHandle(id))).then(host => {
|
|
85
|
+
if (view.dead || this.released) throw new Error('browser view was released')
|
|
86
|
+
return { host, handle: host.createView(id) }
|
|
87
|
+
})
|
|
88
|
+
const real = await view.real
|
|
89
|
+
return real.handle.sendCommand(method, params)
|
|
90
|
+
} },
|
|
91
|
+
}
|
|
92
|
+
this.mapped.set(id, view)
|
|
93
|
+
return view.handle
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
destroyView(handle: ElectronViewHandle) {
|
|
97
|
+
const view = this.mapped.get(handle.id)
|
|
98
|
+
if (!view) return
|
|
99
|
+
view.dead = true; this.mapped.delete(handle.id)
|
|
100
|
+
void view.real?.then(real => real.host.destroyView(real.handle)).catch(() => {})
|
|
101
|
+
}
|
|
102
|
+
async listPages(scope: BrowserSessionId, options: { requireRunning?: boolean } = {}) {
|
|
103
|
+
if (options.requireRunning && !this.routes.has(scope)) return []
|
|
104
|
+
return (await this.route(scope)).listPages?.(scope, options) ?? []
|
|
105
|
+
}
|
|
106
|
+
async adoptPage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))) {
|
|
107
|
+
const host = await this.route(scope)
|
|
108
|
+
if (!host.adoptPage) throw new Error('carrier does not support page adoption')
|
|
109
|
+
const handle = await host.adoptPage(id, scope)
|
|
110
|
+
this.mapped.set(id, { handle, real: Promise.resolve({ host, handle }), dead: false })
|
|
111
|
+
return handle
|
|
112
|
+
}
|
|
113
|
+
async closePage(id: BrowserTabWireId, scope = sessionWireId(readTabHandle(id))) {
|
|
114
|
+
const host = await this.route(scope)
|
|
115
|
+
if (!host.closePage) throw new Error('carrier does not support explicit close')
|
|
116
|
+
await host.closePage(id, scope)
|
|
117
|
+
const view = this.mapped.get(id)
|
|
118
|
+
if (view) this.destroyView(view.handle)
|
|
119
|
+
}
|
|
120
|
+
async retireSession(scope: BrowserSessionId) {
|
|
121
|
+
try { await (await this.routes.get(scope))?.retireSession?.(scope) }
|
|
122
|
+
finally { this.routes.delete(scope); this.decisions.delete(scope) }
|
|
123
|
+
}
|
|
124
|
+
dispose() {
|
|
125
|
+
if (this.released) return
|
|
126
|
+
this.released = true
|
|
127
|
+
for (const view of [...this.mapped.values()]) this.destroyView(view.handle)
|
|
128
|
+
this.extension.dispose(); this.fallback.dispose?.()
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
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 { detectDesktopShell, 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
|
+
preferredBrowser?: string,
|
|
199
|
+
): Promise<void> {
|
|
200
|
+
if (request.method !== 'GET') {
|
|
201
|
+
replyJson(response, 405, { error: 'method-not-allowed' })
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
if (!sameOrigin(request)) {
|
|
205
|
+
replyJson(response, 403, { error: 'not-same-origin' })
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
const shell = detectDesktopShell({ localAppData, registry, conventions, preferredBrowser })
|
|
209
|
+
// Only a verified official install is read for a bridge; any other shell is reported as missing
|
|
210
|
+
// without a repair command, and `shell` says why.
|
|
211
|
+
const status = shell.kind === 'official-supported' && shell.root !== undefined
|
|
212
|
+
? readBridgeStatus(shell.root, mainExtension)
|
|
213
|
+
: { state: 'missing' as const, present: false, archivePresent: false, detail: shell.reason }
|
|
214
|
+
replyJson(response, 200, { ok: true, bridge: status, shell })
|
|
215
|
+
}
|