dsh-builtin-browser 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/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 +386 -0
- package/src/browser-electron/desktop-bridge-host.ts +253 -0
- package/src/browser-electron/desktop-identity.ts +353 -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 +2768 -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,347 @@
|
|
|
1
|
+
/** Prepare an Electron runtime in the plugin-owned runtime directory (or an explicit external package), never the plugin dependency closure. */
|
|
2
|
+
import { spawn } from 'node:child_process'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync } from 'node:fs'
|
|
5
|
+
import { isAbsolute, join } from 'node:path'
|
|
6
|
+
|
|
7
|
+
import { internals, managedElectronDir } from './remote-host.ts'
|
|
8
|
+
|
|
9
|
+
/** How long a background provision may run before it is abandoned. */
|
|
10
|
+
export const PROVISION_TIMEOUT_MS = 180_000
|
|
11
|
+
|
|
12
|
+
/** Default Electron package version fetched into the managed runtime directory when none is already installed. */
|
|
13
|
+
export const MANAGED_ELECTRON_VERSION = '44.10.0'
|
|
14
|
+
|
|
15
|
+
/** What happened, in terms a log line can carry. */
|
|
16
|
+
export interface ProvisionResult {
|
|
17
|
+
/** `present` — nothing to do; `ready` — provisioned now; `skipped` — opted out; `failed`. */
|
|
18
|
+
readonly status: 'present' | 'ready' | 'skipped' | 'failed'
|
|
19
|
+
/** One line for the log; never contains a stack trace a user has to decode. */
|
|
20
|
+
readonly detail: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The state a settings panel shows, which is one state wider than {@link ProvisionResult}.
|
|
25
|
+
*
|
|
26
|
+
* `idle` and `preparing` are the two a log line never needs and a user always does: "nothing has
|
|
27
|
+
* been asked for yet" and "a ~100 MB download is running right now" are the states in which a first
|
|
28
|
+
* browser call is slow, and until this existed neither was visible anywhere in the product — the
|
|
29
|
+
* only trace was a log line the panel cannot read.
|
|
30
|
+
*/
|
|
31
|
+
export interface ProvisionSnapshot {
|
|
32
|
+
/** `idle` and `preparing` are provisional; the rest are terminal for this attempt. */
|
|
33
|
+
readonly state: 'idle' | 'preparing' | 'present' | 'ready' | 'skipped' | 'failed'
|
|
34
|
+
/** One line, already user-facing: never a stack trace. */
|
|
35
|
+
readonly detail: string
|
|
36
|
+
/** When the state last changed, ISO. */
|
|
37
|
+
readonly at: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const IDLE: ProvisionSnapshot = {
|
|
41
|
+
state: 'idle',
|
|
42
|
+
detail: 'the runtime has not been asked for yet',
|
|
43
|
+
at: new Date(0).toISOString(),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let latest: ProvisionSnapshot = IDLE
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The current provisioning state, for a readiness report.
|
|
50
|
+
*
|
|
51
|
+
* Deliberately a snapshot rather than a promise: a panel polling this must be able to answer in one
|
|
52
|
+
* synchronous read, without awaiting (and thereby echoing) the download it is reporting on.
|
|
53
|
+
* @returns the last state written, or the idle state before anything ran.
|
|
54
|
+
*/
|
|
55
|
+
export function provisionSnapshot(): ProvisionSnapshot {
|
|
56
|
+
return latest
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Replace the reported state. Internal: every terminal result is recorded here. */
|
|
60
|
+
function record(result: ProvisionResult): ProvisionResult {
|
|
61
|
+
latest = { state: result.status, detail: result.detail, at: new Date().toISOString() }
|
|
62
|
+
return result
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Everything this module touches from the outside, so a test can drive it without Electron. */
|
|
66
|
+
export interface ProvisionDeps {
|
|
67
|
+
/** Whether a spawnable binary already exists. */
|
|
68
|
+
readonly hasBinary: () => boolean
|
|
69
|
+
/** The electron package's own installer script, or undefined when it is not there yet. */
|
|
70
|
+
readonly installerScript: () => string | undefined
|
|
71
|
+
/**
|
|
72
|
+
* Optional bootstrap step when `installerScript()` is not on disk yet (e.g. fetching the lightweight
|
|
73
|
+
* `electron` npm wrapper package into `$DSH_HOME/dsh-builtin-browser-host/electron-runtime`).
|
|
74
|
+
*/
|
|
75
|
+
readonly bootstrapPackage?: (signal?: AbortSignal) => Promise<{ ok: boolean; detail?: string }>
|
|
76
|
+
/** Runs the installer; resolves to an exit code, or rejects/returns null on failure. */
|
|
77
|
+
readonly run: (script: string, signal?: AbortSignal) => Promise<{ code: number | null; detail?: string }>
|
|
78
|
+
/** Where the outcome goes. */
|
|
79
|
+
readonly log: (message: string) => void
|
|
80
|
+
/** Opt-out honoured exactly like the install script honours it. */
|
|
81
|
+
readonly skip: () => boolean
|
|
82
|
+
/** Budget for one provision. */
|
|
83
|
+
readonly timeoutMs: number
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Whether a spawnable Electron binary is already available.
|
|
88
|
+
*
|
|
89
|
+
* Resolved through the same probe the host uses, so this can never disagree with what a launch
|
|
90
|
+
* would find: a second, cheaper-looking check would be the classic way to report "ready" and then
|
|
91
|
+
* fail at spawn time.
|
|
92
|
+
* @returns true when a launch would find a binary.
|
|
93
|
+
*/
|
|
94
|
+
export function hasElectronRuntime(): boolean {
|
|
95
|
+
try {
|
|
96
|
+
internals.resolveElectronPath()
|
|
97
|
+
return true
|
|
98
|
+
} catch {
|
|
99
|
+
return false
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Resolve the target `electron` package directory: explicit external override, else plugin-managed runtime dir. */
|
|
104
|
+
function targetPackageDir(): string | undefined {
|
|
105
|
+
const override = process.env.DSH_BROWSER_ELECTRON_PACKAGE
|
|
106
|
+
if (override !== undefined) {
|
|
107
|
+
if (!override || !isAbsolute(override)) return undefined
|
|
108
|
+
return override
|
|
109
|
+
}
|
|
110
|
+
return join(managedElectronDir(), 'node_modules', 'electron')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @returns the electron package's `install.js` path when present and valid, or undefined.
|
|
115
|
+
*/
|
|
116
|
+
function electronInstallerScript(): string | undefined {
|
|
117
|
+
try {
|
|
118
|
+
const directory = targetPackageDir()
|
|
119
|
+
if (!directory) return undefined
|
|
120
|
+
const metadata = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')) as { name?: unknown }
|
|
121
|
+
if (metadata.name !== 'electron') return undefined
|
|
122
|
+
const script = join(directory, 'install.js')
|
|
123
|
+
return existsSync(script) ? script : undefined
|
|
124
|
+
} catch {
|
|
125
|
+
return undefined
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The Electron version the installed package asks for, for a log line that names the download. */
|
|
130
|
+
function electronVersion(): string {
|
|
131
|
+
try {
|
|
132
|
+
const directory = targetPackageDir()
|
|
133
|
+
if (!directory) return MANAGED_ELECTRON_VERSION
|
|
134
|
+
const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')) as { version?: unknown }
|
|
135
|
+
return typeof manifest.version === 'string' ? manifest.version : MANAGED_ELECTRON_VERSION
|
|
136
|
+
} catch {
|
|
137
|
+
return MANAGED_ELECTRON_VERSION
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Fetch the lightweight `electron` npm wrapper (`--ignore-scripts`, ~100 KB) into the managed runtime
|
|
143
|
+
* directory so its `install.js` can subsequently download the platform binary with full mirror/proxy support.
|
|
144
|
+
*/
|
|
145
|
+
async function bootstrapManagedPackage(signal?: AbortSignal): Promise<{ ok: boolean; detail?: string }> {
|
|
146
|
+
if (process.env.DSH_BROWSER_ELECTRON_PACKAGE !== undefined) {
|
|
147
|
+
return { ok: false, detail: 'DSH_BROWSER_ELECTRON_PACKAGE is set; provide an existing absolute electron package directory' }
|
|
148
|
+
}
|
|
149
|
+
const runtimeDir = managedElectronDir()
|
|
150
|
+
const targetPkg = join(runtimeDir, 'node_modules', 'electron')
|
|
151
|
+
if (existsSync(join(targetPkg, 'install.js'))) return { ok: true }
|
|
152
|
+
mkdirSync(runtimeDir, { recursive: true })
|
|
153
|
+
const stagingDir = join(runtimeDir, `.staging-${process.pid}-${randomUUID()}`)
|
|
154
|
+
mkdirSync(stagingDir, { recursive: true })
|
|
155
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'
|
|
156
|
+
const spec = `electron@${process.env.DSH_BROWSER_ELECTRON_VERSION || MANAGED_ELECTRON_VERSION}`
|
|
157
|
+
try {
|
|
158
|
+
const outcome = await new Promise<{ code: number | null; detail?: string }>(resolve => {
|
|
159
|
+
const child = spawn(npm, ['install', '--no-save', '--no-package-lock', '--ignore-scripts', '--prefix', stagingDir, spec], {
|
|
160
|
+
env: { ...process.env, ELECTRON_SKIP_BINARY_DOWNLOAD: '1' },
|
|
161
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
162
|
+
shell: process.platform === 'win32',
|
|
163
|
+
windowsHide: true,
|
|
164
|
+
})
|
|
165
|
+
let stderr = ''
|
|
166
|
+
child.stderr?.on('data', chunk => { stderr = (stderr + String(chunk)).slice(-2048) })
|
|
167
|
+
let failure: string | undefined
|
|
168
|
+
const abort = (): void => { try { child.kill('SIGKILL') } catch {} }
|
|
169
|
+
signal?.addEventListener('abort', abort, { once: true })
|
|
170
|
+
if (signal?.aborted) abort()
|
|
171
|
+
child.once('error', error => { failure = String(error) })
|
|
172
|
+
child.once('close', code => {
|
|
173
|
+
signal?.removeEventListener('abort', abort)
|
|
174
|
+
resolve({ code, detail: failure ?? (stderr.trim() || undefined) })
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
if (outcome.code !== 0) {
|
|
178
|
+
return { ok: false, detail: outcome.detail ?? `npm install ${spec} exited ${String(outcome.code)}` }
|
|
179
|
+
}
|
|
180
|
+
const stagedPkg = join(stagingDir, 'node_modules', 'electron')
|
|
181
|
+
if (!existsSync(join(stagedPkg, 'install.js'))) {
|
|
182
|
+
return { ok: false, detail: `downloaded ${spec} package is missing install.js` }
|
|
183
|
+
}
|
|
184
|
+
mkdirSync(join(runtimeDir, 'node_modules'), { recursive: true })
|
|
185
|
+
rmSync(targetPkg, { recursive: true, force: true })
|
|
186
|
+
renameSync(stagedPkg, targetPkg)
|
|
187
|
+
return { ok: true }
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return { ok: false, detail: String(error) }
|
|
190
|
+
} finally {
|
|
191
|
+
rmSync(stagingDir, { recursive: true, force: true })
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let runningInstaller: Promise<{ code: number | null; detail?: string }> | undefined
|
|
196
|
+
|
|
197
|
+
/** The real dependencies: this process's spawn, fs and logger. */
|
|
198
|
+
export function defaultDeps(log: (message: string) => void = () => {}): ProvisionDeps {
|
|
199
|
+
return {
|
|
200
|
+
hasBinary: hasElectronRuntime,
|
|
201
|
+
installerScript: electronInstallerScript,
|
|
202
|
+
bootstrapPackage: bootstrapManagedPackage,
|
|
203
|
+
run: (script, signal) => {
|
|
204
|
+
if (runningInstaller !== undefined) return runningInstaller
|
|
205
|
+
const run = new Promise<{ code: number | null; detail?: string }>(resolve => {
|
|
206
|
+
const child = spawn(process.execPath, [script], {
|
|
207
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
208
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
209
|
+
windowsHide: true,
|
|
210
|
+
})
|
|
211
|
+
let stderr = ''
|
|
212
|
+
child.stderr?.on('data', chunk => { stderr = (stderr + String(chunk)).slice(-2048) })
|
|
213
|
+
let failure: string | undefined
|
|
214
|
+
const abort = (): void => { child.kill('SIGKILL') }
|
|
215
|
+
signal?.addEventListener('abort', abort, { once: true })
|
|
216
|
+
if (signal?.aborted) abort()
|
|
217
|
+
child.once('error', error => { failure = String(error) })
|
|
218
|
+
child.once('close', code => {
|
|
219
|
+
signal?.removeEventListener('abort', abort)
|
|
220
|
+
resolve({ code, detail: failure ?? (stderr.trim() || undefined) })
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
runningInstaller = run
|
|
224
|
+
const clear = (): void => { if (runningInstaller === run) runningInstaller = undefined }
|
|
225
|
+
void run.then(clear, clear)
|
|
226
|
+
return run
|
|
227
|
+
},
|
|
228
|
+
log,
|
|
229
|
+
skip: () => typeof process.env.ELECTRON_SKIP_BINARY_DOWNLOAD === 'string'
|
|
230
|
+
&& process.env.ELECTRON_SKIP_BINARY_DOWNLOAD !== '',
|
|
231
|
+
timeoutMs: PROVISION_TIMEOUT_MS,
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Provision the runtime once per process, when it is missing.
|
|
237
|
+
*
|
|
238
|
+
* Concurrent callers share the first attempt: two tool calls arriving together must not start two
|
|
239
|
+
* downloads into the same directory.
|
|
240
|
+
* @param deps - the effects, defaulted to this process's.
|
|
241
|
+
* @returns what happened. Never throws.
|
|
242
|
+
*/
|
|
243
|
+
export async function ensureElectronRuntime(deps: ProvisionDeps = defaultDeps()): Promise<ProvisionResult> {
|
|
244
|
+
if (deps.hasBinary()) return record({ status: 'present', detail: 'an Electron runtime is already available' })
|
|
245
|
+
if (deps.skip()) return record({ status: 'skipped', detail: 'ELECTRON_SKIP_BINARY_DOWNLOAD is set' })
|
|
246
|
+
const version = electronVersion()
|
|
247
|
+
latest = {
|
|
248
|
+
state: 'preparing',
|
|
249
|
+
detail: `downloading Electron ${version} (one time, about a minute)`,
|
|
250
|
+
at: new Date().toISOString(),
|
|
251
|
+
}
|
|
252
|
+
deps.log(`preparing Electron ${version} in the background (a missing runtime needs a download)`)
|
|
253
|
+
// The bound has to be a REFERENCED timer, and it has to be cleared when the race finishes.
|
|
254
|
+
//
|
|
255
|
+
// A first version unref'd it — "do not keep the process alive for a download" — which is exactly
|
|
256
|
+
// backwards: with nothing else on the loop the timer never fires, the promise never settles, and a
|
|
257
|
+
// caller waiting on it hangs with no error at all. CI caught it before a user could: the test for
|
|
258
|
+
// this path failed with "Promise resolution is still pending but the event loop has already
|
|
259
|
+
// resolved". Keep it referenced, and clear it so a success does not leave a 180 s handle behind.
|
|
260
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
261
|
+
const controller = new AbortController()
|
|
262
|
+
const timeout = new Promise<{ code: number | null; detail: string }>(resolve => {
|
|
263
|
+
timer = setTimeout(
|
|
264
|
+
() => {
|
|
265
|
+
controller.abort()
|
|
266
|
+
resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` })
|
|
267
|
+
},
|
|
268
|
+
deps.timeoutMs,
|
|
269
|
+
)
|
|
270
|
+
})
|
|
271
|
+
let outcome: { code: number | null; detail?: string }
|
|
272
|
+
try {
|
|
273
|
+
outcome = await Promise.race([
|
|
274
|
+
(async (): Promise<{ code: number | null; detail?: string }> => {
|
|
275
|
+
let script = deps.installerScript()
|
|
276
|
+
if (script === undefined && deps.bootstrapPackage !== undefined) {
|
|
277
|
+
const boot = await deps.bootstrapPackage(controller.signal)
|
|
278
|
+
if (!boot.ok) return { code: 1, detail: boot.detail ?? 'could not fetch electron package' }
|
|
279
|
+
script = deps.installerScript()
|
|
280
|
+
}
|
|
281
|
+
if (script === undefined) {
|
|
282
|
+
return { code: 1, detail: 'the installed electron package has no install.js; retry from Settings → Browser → Readiness or run `npx --no dsh-browser-install-electron`' }
|
|
283
|
+
}
|
|
284
|
+
return await deps.run(script, controller.signal)
|
|
285
|
+
})(),
|
|
286
|
+
timeout,
|
|
287
|
+
])
|
|
288
|
+
} catch (error) {
|
|
289
|
+
return record({ status: 'failed', detail: `the download failed: ${String(error)}` })
|
|
290
|
+
} finally {
|
|
291
|
+
if (timer !== undefined) clearTimeout(timer)
|
|
292
|
+
}
|
|
293
|
+
if (outcome.code !== 0) {
|
|
294
|
+
return record({
|
|
295
|
+
status: 'failed',
|
|
296
|
+
detail: `Electron provisioning did not finish (${outcome.detail ?? `exit ${String(outcome.code)}`}); `
|
|
297
|
+
+ 'the browser still works through a sidebar, Chrome or Edge; retry from Settings → Browser → '
|
|
298
|
+
+ 'Readiness ("Prepare the bundled browser"), or run `npx --no dsh-browser-install-electron`',
|
|
299
|
+
})
|
|
300
|
+
}
|
|
301
|
+
return record({ status: 'ready', detail: 'the Electron runtime is ready' })
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** One attempt per process, shared by every caller. */
|
|
305
|
+
let attempt: Promise<ProvisionResult> | undefined
|
|
306
|
+
/** Whether {@link attempt} has settled, which is what makes a retry possible. */
|
|
307
|
+
let settled = false
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Start (or join) the single background attempt.
|
|
311
|
+
*
|
|
312
|
+
* Returns immediately with the shared promise, so a caller that does not care can ignore it and one
|
|
313
|
+
* that does can await it — the returned promise never rejects.
|
|
314
|
+
*
|
|
315
|
+
* `force` is the second half of the settings panel's retry button. Without it the memoised attempt
|
|
316
|
+
* made a failed download permanent for the life of the process: the panel could offer a button, the
|
|
317
|
+
* button could call this, and the answer would be the failure it was trying to replace. An attempt
|
|
318
|
+
* still IN FLIGHT is always joined, never restarted — two downloads into one directory is the one
|
|
319
|
+
* outcome worth refusing.
|
|
320
|
+
* @param log - where the outcome goes.
|
|
321
|
+
* @param deps - the effects; defaulted to this process's, overridable so a test can drive it.
|
|
322
|
+
* @param options - `force` discards a settled attempt so a new one may start.
|
|
323
|
+
* @returns the shared attempt.
|
|
324
|
+
*/
|
|
325
|
+
export function provisionElectronInBackground(
|
|
326
|
+
log: (message: string) => void,
|
|
327
|
+
deps: ProvisionDeps = defaultDeps(log),
|
|
328
|
+
options: { readonly force?: boolean } = {},
|
|
329
|
+
): Promise<ProvisionResult> {
|
|
330
|
+
if (options.force === true && settled) {
|
|
331
|
+
attempt = undefined
|
|
332
|
+
settled = false
|
|
333
|
+
}
|
|
334
|
+
attempt ??= ensureElectronRuntime(deps).then(result => {
|
|
335
|
+
settled = true
|
|
336
|
+
log(`electron runtime: ${result.status} — ${result.detail}`)
|
|
337
|
+
return result
|
|
338
|
+
})
|
|
339
|
+
return attempt
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** Forget the attempt. Tests only: a real process provisions at most once. */
|
|
343
|
+
export function resetProvisionStateForTest(): void {
|
|
344
|
+
attempt = undefined
|
|
345
|
+
settled = false
|
|
346
|
+
latest = IDLE
|
|
347
|
+
}
|