dsh-builtin-browser 1.0.1 → 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/CHANGELOG.md +55 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/tool-reference.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- package/dsh-host-patch/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +0 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -44
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +16 -36
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +15 -12
- package/scripts/fix-exports.mjs +6 -16
- package/scripts/install-electron.mjs +55 -5
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +26 -15
- package/skills/dsh-builtin-browser/SKILL.md +27 -2
- package/skills/dsh-builtin-browser/references/batch.md +15 -0
- package/src/browser/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/runtime.ts +18 -0
- package/src/browser/takeover-target.ts +16 -7
- package/src/browser/types.ts +56 -3
- package/src/browser-electron/authenticated-route.ts +29 -4
- package/src/browser-electron/automatic-maintenance.ts +23 -13
- package/src/browser-electron/bridge-connection.ts +11 -10
- package/src/browser-electron/bridge-install.ts +2 -1
- package/src/browser-electron/bridge-status.ts +61 -22
- package/src/browser-electron/desktop-bridge-host.ts +9 -7
- package/src/browser-electron/desktop-identity.ts +38 -5
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/electron-provision.ts +104 -18
- package/src/browser-electron/entry.ts +1378 -1299
- package/src/browser-electron/extension-browser.ts +11 -4
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +3 -2
- package/src/browser-electron/guest-route.ts +180 -32
- package/src/browser-electron/guest-runtime.ts +61 -10
- package/src/browser-electron/guest-storage.ts +5 -2
- package/src/browser-electron/history-store.ts +3 -6
- package/src/browser-electron/host-main.ts +8 -4
- package/src/browser-electron/host-patch-maintenance.ts +18 -9
- package/src/browser-electron/maintenance-route.ts +2 -1
- package/src/browser-electron/missing-system-browser.ts +11 -10
- package/src/browser-electron/preferred-browser.ts +13 -3
- package/src/browser-electron/preview-route.ts +9 -12
- package/src/browser-electron/process-ownership.ts +9 -3
- package/src/browser-electron/profile-command.ts +2 -1
- package/src/browser-electron/profile-extension.ts +5 -0
- package/src/browser-electron/profile-lease.ts +131 -35
- 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 +158 -4063
- package/src/browser-electron/reference-route.ts +598 -608
- package/src/browser-electron/remote-host.ts +118 -42
- package/src/browser-electron/runtime-status.ts +80 -13
- package/src/browser-electron/settings-store.ts +10 -6
- package/src/browser-electron/sidebar-only-host.ts +4 -2
- package/src/browser-electron/system-browser.ts +537 -184
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/virtual-cursor.ts +24 -14
- package/src/browser-reference/service.ts +38 -7
- package/src/browser-reference/web-sources.ts +4 -1
- package/src/client/apply-guard.ts +22 -0
- package/src/client/browser/BrowserController.ts +3 -3
- package/src/client/browser/IframeImpl.ts +182 -176
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -0
- package/src/client/browser/web-reference-source.ts +5 -1
- package/src/client/definition.tsx +36 -30
- package/src/client/electron/ElectronWebViewImpl.ts +20 -13
- package/src/client/electron/ElectronWebviewPresentation.ts +4 -2
- package/src/client/electron/NativeChildPresentation.ts +11 -3
- package/src/client/electron/NativeViewPage.ts +19 -5
- package/src/client/index.ts +333 -293
- package/src/client/locales.ts +9 -6
- package/src/client/reference/client/plugin.ts +21 -2
- package/src/client/reference/client/production/ReferenceCapsules.tsx +3 -3
- package/src/client/reference/client/production/assembly.ts +4 -28
- package/src/client/reference/client/production/availability.ts +0 -2
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/draft-adapter.ts +4 -0
- package/src/client/reference/client/production/http-transport.ts +0 -5
- package/src/client/reference/client/production/production-submission.ts +50 -290
- package/src/client/reference/client/production/protocol.ts +7 -4
- package/src/client/reference/client/production/runtime.ts +41 -86
- package/src/client/reference/client/production/source-marker.ts +49 -13
- package/src/client/reference/client/production/user-text-rule.ts +10 -1
- package/src/client/reference/client/reveal.ts +3 -1
- package/src/client/reference/client/session-schedule.ts +36 -0
- package/src/client/settings/index.ts +8 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +163 -52
- package/src/client/startpage/controller.ts +3 -6
- package/src/client/view/BrowserBody.tsx +2 -1
- package/src/client/view/IframePresentation.ts +37 -16
- package/src/client/view/StartPage.tsx +2 -1
- package/src/compat/host-features.ts +92 -0
- package/src/reference-source.ts +1 -1
- package/src/reference-text.ts +23 -1
- package/src/takeover-protocol.ts +11 -2
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +173 -19
- package/src/tool-browser/code-worker.ts +101 -15
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +66 -3534
- package/src/tool-browser/page-probe.ts +229 -28
- package/src/tool-browser/panel-page.ts +3 -1
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +3 -2
- 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/web-guest.ts +35 -34
- package/dist/client.cjs +0 -43167
- 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/lib/browser-reference/submission-receipts.js +0 -139
- package/src/browser-reference/submission-receipts.ts +0 -122
|
@@ -10,6 +10,7 @@ import { replyJson } from './json-reply.js';
|
|
|
10
10
|
import { sameOrigin } from './settings-route.js';
|
|
11
11
|
import { importReferenceBundle } from '../browser-reference/import.js';
|
|
12
12
|
import { validateFrameSelector } from '../browser-reference/entry.js';
|
|
13
|
+
import { MAX_FROZEN_CAPTURE_CHARS } from '../browser-reference/page-script.js';
|
|
13
14
|
import { summarizeReference } from '../browser-reference/service.js';
|
|
14
15
|
/** Paths this module serves. */
|
|
15
16
|
export { REFERENCE_LIST_ROUTE };
|
|
@@ -78,6 +79,12 @@ function requireRead(request, response) {
|
|
|
78
79
|
}
|
|
79
80
|
return true;
|
|
80
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The page-side bar posts its whole frozen capture, images inlined, and that capture is bounded by
|
|
84
|
+
* `MAX_FROZEN_CAPTURE_CHARS`. JSON keeps non-ASCII raw, so a character can take three UTF-8 bytes;
|
|
85
|
+
* the other fields are short and bounded on their own.
|
|
86
|
+
*/
|
|
87
|
+
const MAX_CAPTURE_BODY_BYTES = MAX_FROZEN_CAPTURE_CHARS * 3 + 64 * 1024;
|
|
81
88
|
/** Build every reference handler over one service. */
|
|
82
89
|
export function createReferenceRouteHandlers(options) {
|
|
83
90
|
const { service, queue } = options;
|
|
@@ -153,7 +160,7 @@ export function createReferenceRouteHandlers(options) {
|
|
|
153
160
|
return;
|
|
154
161
|
let body;
|
|
155
162
|
try {
|
|
156
|
-
body = await readJsonBody(request);
|
|
163
|
+
body = await readJsonBody(request, MAX_CAPTURE_BODY_BYTES);
|
|
157
164
|
}
|
|
158
165
|
catch (error) {
|
|
159
166
|
replyJson(response, 400, { ok: false, error: `unreadable body: ${String(error)}` });
|
|
@@ -246,6 +253,7 @@ export function createReferenceRouteHandlers(options) {
|
|
|
246
253
|
...target !== undefined ? { target } : {},
|
|
247
254
|
...comment !== undefined ? { comment } : {},
|
|
248
255
|
...frozenCapture !== undefined ? { frozenCapture } : {},
|
|
256
|
+
...typeof request.headers.host === 'string' ? { dshHost: request.headers.host } : {},
|
|
249
257
|
});
|
|
250
258
|
if (outcome.reference === undefined) {
|
|
251
259
|
replyJson(response, 422, { ok: false, failures: outcome.failures });
|
|
@@ -424,7 +432,6 @@ export function createReferenceRouteHandlers(options) {
|
|
|
424
432
|
replyJson(response, 400, { ok: false, error: 'invalid since' });
|
|
425
433
|
return;
|
|
426
434
|
}
|
|
427
|
-
const unverified = options.receipts?.recover(sessionId);
|
|
428
435
|
const includeConsumed = url.searchParams.get('includeConsumed') === '1';
|
|
429
436
|
const snapshot = queue.list({ sessionId, includeConsumed, ...since > 0 ? { since } : {} });
|
|
430
437
|
// The cursor must never hide work that is still PENDING, whatever includeConsumed says. The client
|
|
@@ -438,7 +445,6 @@ export function createReferenceRouteHandlers(options) {
|
|
|
438
445
|
replyJson(response, 200, {
|
|
439
446
|
ok: true,
|
|
440
447
|
sequence: snapshot.sequence,
|
|
441
|
-
...(unverified === undefined ? {} : { tracksSubmissions: true, unverified }),
|
|
442
448
|
deliveries: pending.map(record => ({
|
|
443
449
|
intentId: record.intentId,
|
|
444
450
|
sessionId: record.sessionId,
|
|
@@ -476,21 +482,6 @@ export function createReferenceRouteHandlers(options) {
|
|
|
476
482
|
replyJson(response, 400, { ok: false, error: `unreadable body: ${String(error)}` });
|
|
477
483
|
return;
|
|
478
484
|
}
|
|
479
|
-
if (body.phase === 'submitting') {
|
|
480
|
-
const sessionId = stringOf(body.sessionId, 200);
|
|
481
|
-
const requestId = stringOf(body.requestId, 200);
|
|
482
|
-
const ids = body.intentIds;
|
|
483
|
-
if (sessionId === undefined || requestId === undefined || !Array.isArray(ids) || !ids.every(id => typeof id === 'string')) {
|
|
484
|
-
replyJson(response, 400, { ok: false, error: 'invalid-submission' });
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
if (!options.receipts?.bind(sessionId, requestId, ids)) {
|
|
488
|
-
replyJson(response, 409, { ok: false, error: 'submission-not-bound' });
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
replyJson(response, 200, { ok: true, state: 'submitting' });
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
485
|
let intentId = stringOf(body.intentId, 200);
|
|
495
486
|
// The records menu knows a reference id, not the intent that carried it.
|
|
496
487
|
// Resolve it rather than making every caller learn the internal id.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs';
|
|
1
|
+
import { BROWSER_PROFILE_DIR, LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs';
|
|
2
2
|
/**
|
|
3
3
|
* Legacy standalone Electron browser host (not a supported package export): an
|
|
4
4
|
* {@link ElectronBrowserViewHost} implementation that spawns the plugin's own
|
|
@@ -26,14 +26,14 @@ import { LOOPBACK_IPV4 } from '../../assets/browser-policy.mjs';
|
|
|
26
26
|
* @module dsh-browser/browser-electron/remote-host
|
|
27
27
|
*/
|
|
28
28
|
import { execFileSync, spawn } from 'node:child_process';
|
|
29
|
-
import { appendFileSync, mkdirSync, statSync, writeFileSync } from 'node:fs';
|
|
29
|
+
import { appendFileSync, mkdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
30
30
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
31
31
|
import { createRequire } from 'node:module';
|
|
32
32
|
import { existsSync, readFileSync, readdirSync, readlinkSync } from 'node:fs';
|
|
33
33
|
import { basename, dirname, isAbsolute, join } from 'node:path';
|
|
34
34
|
import { createServer } from 'node:net';
|
|
35
35
|
import { withTimeoutShared } from './timing.js';
|
|
36
|
-
import { browserHostLogPath } from './paths.js';
|
|
36
|
+
import { browserHostLogPath, dshHome } from './paths.js';
|
|
37
37
|
import { fileURLToPath } from 'node:url';
|
|
38
38
|
import { readTabHandle, tabWireId } from '../browser/handles.js';
|
|
39
39
|
/** How long to wait for the child to signal readiness before failing. */
|
|
@@ -42,11 +42,24 @@ const READY_TIMEOUT_MS = 20_000;
|
|
|
42
42
|
const PRESENT_TIMEOUT_MS = 10_000;
|
|
43
43
|
/** Safety cap on a single RPC reply line (base64 downloads are the big ones). */
|
|
44
44
|
const MAX_RPC_BUFFER_BYTES = 512 * 1024 * 1024;
|
|
45
|
+
/**
|
|
46
|
+
* Plugin-owned runtime root (`$DSH_HOME/dsh-builtin-browser-host/electron-runtime`).
|
|
47
|
+
* Lives outside DSH profile `node_modules` so plugin upgrades do not delete it
|
|
48
|
+
* as unreferenced residue and pnpm never blocks its postinstall.
|
|
49
|
+
*/
|
|
50
|
+
export function managedElectronDir(home = dshHome()) {
|
|
51
|
+
return join(home, BROWSER_PROFILE_DIR, 'electron-runtime');
|
|
52
|
+
}
|
|
53
|
+
function managedElectronBinary() {
|
|
54
|
+
const pkgRoot = join(managedElectronDir(), 'node_modules', 'electron');
|
|
55
|
+
return electronDistExe(pkgRoot);
|
|
56
|
+
}
|
|
45
57
|
function resolveElectronPath() {
|
|
46
58
|
return resolveElectronPathImpl({
|
|
47
59
|
override: process.env.ELECTRON_PATH,
|
|
48
60
|
inElectron: typeof process.versions.electron === 'string',
|
|
49
61
|
execPath: process.execPath,
|
|
62
|
+
managed: managedElectronBinary,
|
|
50
63
|
bundled: bundledElectronBinary,
|
|
51
64
|
anchored: anchoredElectronBinary,
|
|
52
65
|
ancestry: hostElectronViaProcessTree,
|
|
@@ -54,9 +67,9 @@ function resolveElectronPath() {
|
|
|
54
67
|
}
|
|
55
68
|
/**
|
|
56
69
|
* Pure selection over the discovery probes, in order:
|
|
57
|
-
* 0. override (user intent) → 1. bundled package →
|
|
58
|
-
*
|
|
59
|
-
* Packaged app executables are never reused (steps
|
|
70
|
+
* 0. override (user intent) → 1. managed runtime → 2. bundled package → 3. anchors (newest) →
|
|
71
|
+
* 4. in-process BARE host → 5. process ancestry → throw.
|
|
72
|
+
* Packaged app executables are never reused (steps 4/5 skip them).
|
|
60
73
|
*/
|
|
61
74
|
function resolveElectronPathImpl(inputs) {
|
|
62
75
|
// 0. Explicit override first: a user-set ELECTRON_PATH is a deliberate
|
|
@@ -65,7 +78,11 @@ function resolveElectronPathImpl(inputs) {
|
|
|
65
78
|
const override = inputs.override;
|
|
66
79
|
if (typeof override === 'string' && override.length > 0 && existsSync(override))
|
|
67
80
|
return override;
|
|
68
|
-
// 1.
|
|
81
|
+
// 1. Plugin-managed standalone runtime (on-demand download target).
|
|
82
|
+
const managed = inputs.managed?.();
|
|
83
|
+
if (managed !== undefined)
|
|
84
|
+
return managed;
|
|
85
|
+
// 2. The plugin's own electron package (filesystem probe). Never require():
|
|
69
86
|
// inside an Electron main process require('electron') is the built-in
|
|
70
87
|
// API module, not the npm package, and electron 44+ downloads its binary
|
|
71
88
|
// on first require — probing must stay side-effect free (available()
|
|
@@ -73,14 +90,14 @@ function resolveElectronPathImpl(inputs) {
|
|
|
73
90
|
const bundled = inputs.bundled();
|
|
74
91
|
if (bundled !== undefined)
|
|
75
92
|
return bundled;
|
|
76
|
-
//
|
|
77
|
-
// pnpm store layouts — was already scanned in step
|
|
93
|
+
// 3. DSH install anchors, newest wins. (The plugin's own tree — plain and
|
|
94
|
+
// pnpm store layouts — was already scanned in step 2; the anchors cover
|
|
78
95
|
// electron installed separately, e.g. `dsh plugin add electron` into the
|
|
79
96
|
// profile or a global prefix.)
|
|
80
97
|
const anchored = inputs.anchored();
|
|
81
98
|
if (anchored !== undefined)
|
|
82
99
|
return anchored;
|
|
83
|
-
//
|
|
100
|
+
// 4. The current process IS a bare Electron (dev hosts, e.g. `electron .`):
|
|
84
101
|
// reuse the host binary — it cannot be missing because we are running on
|
|
85
102
|
// it. A PACKAGED app executable (resources/app.asar beside it, e.g. DSH
|
|
86
103
|
// Desktop.exe) is NOT spawnable as bare electron: it ignores the script
|
|
@@ -91,20 +108,16 @@ function resolveElectronPathImpl(inputs) {
|
|
|
91
108
|
if (typeof exe === 'string' && exe.length > 0 && existsSync(exe) && isBareElectron(exe))
|
|
92
109
|
return exe;
|
|
93
110
|
}
|
|
94
|
-
//
|
|
111
|
+
// 5. Last resort for bare-Electron hosts: walk the process ancestry (the
|
|
95
112
|
// plugin may run in a child Node process of an Electron main process).
|
|
96
113
|
const hostExe = inputs.ancestry();
|
|
97
114
|
if (hostExe !== undefined)
|
|
98
115
|
return hostExe;
|
|
99
116
|
throw new Error('dsh-builtin-browser: cannot locate a spawnable Electron binary. ' +
|
|
100
|
-
'
|
|
101
|
-
'(
|
|
102
|
-
'
|
|
103
|
-
'
|
|
104
|
-
'by hand instead, run `npx --no dsh-browser-install-electron` in the profile that installed the ' +
|
|
105
|
-
'plugin, then retry. Alternatively set ELECTRON_PATH to an electron executable. Note: the host\'s own ' +
|
|
106
|
-
'executable cannot be reused when it is a packaged Electron app (e.g. DSH Desktop.exe) — only a real ' +
|
|
107
|
-
'electron binary can be spawned.');
|
|
117
|
+
'Select "Standalone Electron window" in Settings → Browser and click "Prepare the bundled browser" ' +
|
|
118
|
+
'(or run `npx --no dsh-browser-install-electron`) to download it once into your DSH data directory, ' +
|
|
119
|
+
'or set ELECTRON_PATH to an existing electron executable. Note: a packaged Electron app executable ' +
|
|
120
|
+
'(e.g. DSH Desktop.exe) cannot be reused — only a bare electron binary can be spawned.');
|
|
108
121
|
}
|
|
109
122
|
/** DSH install anchors: electron installed separately (profile / global prefix), newest wins. */
|
|
110
123
|
function anchoredElectronBinary() {
|
|
@@ -374,13 +387,6 @@ class HostGoneError extends Error {
|
|
|
374
387
|
* connects back and speaks the same one-JSON-per-line protocol.
|
|
375
388
|
*/
|
|
376
389
|
class ElectronChildClient {
|
|
377
|
-
hostMainPath;
|
|
378
|
-
port;
|
|
379
|
-
token;
|
|
380
|
-
onExit;
|
|
381
|
-
onUserAction;
|
|
382
|
-
onViewClosed;
|
|
383
|
-
executable;
|
|
384
390
|
child;
|
|
385
391
|
pending = new Map();
|
|
386
392
|
nextId = 1;
|
|
@@ -397,6 +403,14 @@ class ElectronChildClient {
|
|
|
397
403
|
*/
|
|
398
404
|
awaitingHello = true;
|
|
399
405
|
helloTimer;
|
|
406
|
+
hostMainPath;
|
|
407
|
+
port;
|
|
408
|
+
token;
|
|
409
|
+
onExit;
|
|
410
|
+
onUserAction;
|
|
411
|
+
onViewClosed;
|
|
412
|
+
executable;
|
|
413
|
+
userDataDir;
|
|
400
414
|
constructor(hostMainPath, port, token, onExit, onUserAction,
|
|
401
415
|
/**
|
|
402
416
|
* Called when the human closes a browser window. The session it showed is
|
|
@@ -406,7 +420,9 @@ class ElectronChildClient {
|
|
|
406
420
|
onViewClosed,
|
|
407
421
|
/** Test seam: the executable to spawn instead of the resolved Electron
|
|
408
422
|
* binary. Absent -> resolveElectronPath() (production behavior). */
|
|
409
|
-
executable
|
|
423
|
+
executable,
|
|
424
|
+
/** Optional ephemeral userData dir when cookies.persist is false. */
|
|
425
|
+
userDataDir) {
|
|
410
426
|
this.hostMainPath = hostMainPath;
|
|
411
427
|
this.port = port;
|
|
412
428
|
this.token = token;
|
|
@@ -414,6 +430,7 @@ class ElectronChildClient {
|
|
|
414
430
|
this.onUserAction = onUserAction;
|
|
415
431
|
this.onViewClosed = onViewClosed;
|
|
416
432
|
this.executable = executable;
|
|
433
|
+
this.userDataDir = userDataDir;
|
|
417
434
|
const electron = this.executable ?? resolveElectronPath();
|
|
418
435
|
const source = this.executable !== undefined
|
|
419
436
|
? 'provided'
|
|
@@ -440,6 +457,8 @@ class ElectronChildClient {
|
|
|
440
457
|
// expose argv, and preferred over stdin only when stdin cannot deliver):
|
|
441
458
|
// the child reads env only as a fallback after stdin yields nothing.
|
|
442
459
|
env.DSH_BROWSER_RPC_TOKEN = token;
|
|
460
|
+
if (this.userDataDir !== undefined)
|
|
461
|
+
env.DSH_BROWSER_USER_DATA_DIR = this.userDataDir;
|
|
443
462
|
this.child = spawn(electron, [hostMainPath, '--rpc-port', String(port)], {
|
|
444
463
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
445
464
|
windowsHide: false,
|
|
@@ -804,9 +823,6 @@ function formatDelay(ms) {
|
|
|
804
823
|
* ctx.electronViewHost.
|
|
805
824
|
*/
|
|
806
825
|
export class RemoteElectronViewHost {
|
|
807
|
-
hostMainPath;
|
|
808
|
-
spawnExecutable;
|
|
809
|
-
probe;
|
|
810
826
|
client;
|
|
811
827
|
server;
|
|
812
828
|
pendingSocket;
|
|
@@ -835,16 +851,23 @@ export class RemoteElectronViewHost {
|
|
|
835
851
|
* next open starts clean instead of resuming a window nobody can see.
|
|
836
852
|
*/
|
|
837
853
|
viewClosedHandler;
|
|
854
|
+
hostMainPath;
|
|
855
|
+
spawnExecutable;
|
|
856
|
+
probe;
|
|
857
|
+
ephemeralUserDataDir;
|
|
838
858
|
constructor(hostMainPath,
|
|
839
859
|
/** Test seam: the executable to spawn instead of the resolved Electron
|
|
840
860
|
* binary. Absent -> resolveElectronPath() (production behavior). */
|
|
841
861
|
spawnExecutable,
|
|
842
862
|
/** Test seam: the binary probe behind `available()`. Absent ->
|
|
843
863
|
* resolveElectronPath(). */
|
|
844
|
-
probe = resolveElectronPath
|
|
864
|
+
probe = resolveElectronPath,
|
|
865
|
+
/** Optional ephemeral userData directory when cookies.persist is false; removed on dispose(). */
|
|
866
|
+
ephemeralUserDataDir) {
|
|
845
867
|
this.hostMainPath = hostMainPath;
|
|
846
868
|
this.spawnExecutable = spawnExecutable;
|
|
847
869
|
this.probe = probe;
|
|
870
|
+
this.ephemeralUserDataDir = ephemeralUserDataDir;
|
|
848
871
|
}
|
|
849
872
|
/**
|
|
850
873
|
* Cheap usability probe: can we find an Electron binary to spawn? The scan
|
|
@@ -878,6 +901,17 @@ export class RemoteElectronViewHost {
|
|
|
878
901
|
}
|
|
879
902
|
return this.electronAvailable;
|
|
880
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* Retire a negative binary-probe cache immediately after on-demand provisioning
|
|
906
|
+
* finishes so the very next call sees the new binary without waiting out the
|
|
907
|
+
* cooldown or restarting DSH.
|
|
908
|
+
*/
|
|
909
|
+
refreshAvailability() {
|
|
910
|
+
if (this.electronAvailable === false) {
|
|
911
|
+
this.electronAvailable = undefined;
|
|
912
|
+
this.nextProbeAt = 0;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
881
915
|
/**
|
|
882
916
|
* Retire the cached "an Electron binary is here" answer.
|
|
883
917
|
*
|
|
@@ -1062,7 +1096,7 @@ export class RemoteElectronViewHost {
|
|
|
1062
1096
|
// Random per-spawn token: the child must prove knowledge of it (via
|
|
1063
1097
|
// stdin hello) before any command is written to the socket.
|
|
1064
1098
|
const token = randomBytes(24).toString('hex');
|
|
1065
|
-
this.client = new ElectronChildClient(this.hostMainPath, port, token, () => this.onChildExit(), action => this.userActionHandler?.(action), windowId => this.viewClosedHandler?.(windowId), this.spawnExecutable);
|
|
1099
|
+
this.client = new ElectronChildClient(this.hostMainPath, port, token, () => this.onChildExit(), action => this.userActionHandler?.(action), windowId => this.viewClosedHandler?.(windowId), this.spawnExecutable, this.ephemeralUserDataDir);
|
|
1066
1100
|
if (this.pendingSocket !== undefined) {
|
|
1067
1101
|
this.client.attach(this.pendingSocket);
|
|
1068
1102
|
this.pendingSocket = undefined;
|
|
@@ -1181,7 +1215,8 @@ export class RemoteElectronViewHost {
|
|
|
1181
1215
|
* - showing a view that does not exist yet is a no-op in the child, so the
|
|
1182
1216
|
* view must be materialized first (a fresh tab's createView races the
|
|
1183
1217
|
* provider's showActive);
|
|
1184
|
-
* - a view whose renderer was replaced by a navigation is
|
|
1218
|
+
* - a view whose renderer was replaced by a navigation is "already
|
|
1219
|
+
* visible" and therefore skipped by the child's flicker-avoidance fast
|
|
1185
1220
|
* path, leaving the new renderer without a surface.
|
|
1186
1221
|
*
|
|
1187
1222
|
* The barrier ping is meaningful because the child handles messages strictly
|
|
@@ -1253,13 +1288,22 @@ export class RemoteElectronViewHost {
|
|
|
1253
1288
|
this.pendingSocket = undefined;
|
|
1254
1289
|
this.readyPromise = undefined;
|
|
1255
1290
|
this.views.clear();
|
|
1291
|
+
if (this.ephemeralUserDataDir !== undefined) {
|
|
1292
|
+
const dir = this.ephemeralUserDataDir;
|
|
1293
|
+
setTimeout(() => {
|
|
1294
|
+
try {
|
|
1295
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1296
|
+
}
|
|
1297
|
+
catch { /* best-effort cleanup */ }
|
|
1298
|
+
}, 600).unref?.();
|
|
1299
|
+
}
|
|
1256
1300
|
}
|
|
1257
1301
|
}
|
|
1258
1302
|
/** A view handle that waits for child readiness before issuing commands. */
|
|
1259
1303
|
class DeferredRemoteView {
|
|
1304
|
+
materialized;
|
|
1260
1305
|
id;
|
|
1261
1306
|
materialize;
|
|
1262
|
-
materialized;
|
|
1263
1307
|
constructor(id, materialize) {
|
|
1264
1308
|
this.id = id;
|
|
1265
1309
|
this.materialize = materialize;
|
|
@@ -1395,6 +1439,7 @@ export const internals = {
|
|
|
1395
1439
|
electronDistExe,
|
|
1396
1440
|
electronExeBeside,
|
|
1397
1441
|
isBareElectron,
|
|
1442
|
+
managedElectronBinary,
|
|
1398
1443
|
resolveElectronPath,
|
|
1399
1444
|
resolveElectronPathImpl,
|
|
1400
1445
|
};
|
|
@@ -1,14 +1,32 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { detectBrowser } from './system-browser.js';
|
|
3
|
+
/** This plugin's own resolver, used when a caller does not inject one. */
|
|
4
|
+
const pluginRequire = createRequire(import.meta.url);
|
|
5
|
+
/** The host peers this plugin imports; read from the manifest so the list cannot drift. */
|
|
6
|
+
const HOST_PEERS = (() => {
|
|
7
|
+
try {
|
|
8
|
+
const manifest = pluginRequire('../../package.json');
|
|
9
|
+
return Object.freeze(Object.keys(manifest.peerDependencies ?? {}));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return Object.freeze([]);
|
|
13
|
+
}
|
|
14
|
+
})();
|
|
2
15
|
/** Which carrier a channel names. */
|
|
3
16
|
function carrierOf(channel) {
|
|
4
|
-
|
|
17
|
+
if (channel === 'chrome' || channel === 'edge')
|
|
18
|
+
return 'system';
|
|
19
|
+
if (channel === 'electron')
|
|
20
|
+
return 'bundled';
|
|
21
|
+
return 'sidebar';
|
|
5
22
|
}
|
|
6
23
|
/**
|
|
7
24
|
* Assemble the report.
|
|
8
25
|
*
|
|
9
26
|
* The `readiness` field is per carrier on purpose: "the browser is ready" is not a property of this
|
|
10
|
-
* plugin, it is a property of the carrier the user chose. A
|
|
11
|
-
* is ready; the sidebar carrier with no bridge is not, however healthy the
|
|
27
|
+
* plugin, it is a property of the carrier the user chose. A standalone Electron carrier with a
|
|
28
|
+
* finished download is ready; the sidebar carrier with no bridge is not, however healthy the
|
|
29
|
+
* Electron runtime is.
|
|
12
30
|
* @param deps - the readers; every one of them is a cheap, side-effect-free read.
|
|
13
31
|
* @returns the report the panel renders.
|
|
14
32
|
*/
|
|
@@ -59,7 +77,10 @@ export function readRuntimeStatus(deps) {
|
|
|
59
77
|
: { ...installedBridge, state: 'stale', detail: bridgeError };
|
|
60
78
|
// The sidebar needs BOTH halves: our patch inside the shell it will be driven through, and that
|
|
61
79
|
// shell actually running. Either one alone is the false green this report exists to prevent.
|
|
62
|
-
|
|
80
|
+
// On DSH Tauri the patch is the host patch, which starts the same bridge inside electron-rs.
|
|
81
|
+
const shell = deps.shell?.();
|
|
82
|
+
const sidebarReady = bridge.running && (bridge.state === 'installed'
|
|
83
|
+
|| (shell?.kind === 'tauri' && shell.running === true && shell.hostPatch?.status === 'applied'));
|
|
63
84
|
const selected = preferExtension ? deps.selectedCarrier?.() ?? (extension?.connected ? 'extension' : 'cdp') : undefined;
|
|
64
85
|
const checkSystemBrowser = carrier === 'system' || selected === 'cdp';
|
|
65
86
|
const detected = checkSystemBrowser ? (deps.detectBrowser ?? detectBrowser)(channel) : undefined;
|
|
@@ -79,6 +100,10 @@ export function readRuntimeStatus(deps) {
|
|
|
79
100
|
resolvedCarrier = 'sidebar';
|
|
80
101
|
readiness = sidebarReady ? 'ready' : 'blocked';
|
|
81
102
|
}
|
|
103
|
+
else if (carrier === 'bundled') {
|
|
104
|
+
resolvedCarrier = 'bundled';
|
|
105
|
+
readiness = runnable ? 'ready' : 'blocked';
|
|
106
|
+
}
|
|
82
107
|
else if (selected === 'cdp') {
|
|
83
108
|
resolvedCarrier = 'cdp';
|
|
84
109
|
readiness = detected !== undefined && connection?.connected === true ? 'ready' : 'blocked';
|
|
@@ -93,7 +118,7 @@ export function readRuntimeStatus(deps) {
|
|
|
93
118
|
}
|
|
94
119
|
return {
|
|
95
120
|
...deps.nativeHostRegistration ? { nativeHostRegistration: deps.nativeHostRegistration() } : {},
|
|
96
|
-
controlledProfile: resolvedCarrier === 'extension' ? 'user' : resolvedCarrier === 'system' || resolvedCarrier === 'cdp' ? 'plugin' : 'sidebar',
|
|
121
|
+
controlledProfile: resolvedCarrier === 'extension' ? 'user' : resolvedCarrier === 'system' || resolvedCarrier === 'cdp' || resolvedCarrier === 'bundled' ? 'plugin' : 'sidebar',
|
|
97
122
|
...(preferExtension && resolvedCarrier === 'cdp' ? { fallbackReason: deps.fallbackReason?.() ?? (extension?.state === 'disabled' ? 'disabled' : 'not-connected') } : {}),
|
|
98
123
|
...extension === undefined ? {} : { extension },
|
|
99
124
|
channel,
|
|
@@ -104,6 +129,31 @@ export function readRuntimeStatus(deps) {
|
|
|
104
129
|
...resolvedCarrier === 'system' && detected !== undefined ? { executable: detected.path } : {},
|
|
105
130
|
electron,
|
|
106
131
|
bridge,
|
|
107
|
-
|
|
132
|
+
...shell === undefined ? {} : { shell },
|
|
133
|
+
canProvision: resolvedCarrier === 'bundled' && !runnable && snapshot.state !== 'preparing',
|
|
134
|
+
...peerReport(deps.resolvePeer),
|
|
135
|
+
...deps.carrierHistory === undefined ? {} : { carrierHistory: deps.carrierHistory() },
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Resolve every host peer and report the failures (#59). Never throws: an unresolvable peer is a
|
|
140
|
+
* fact to display, not a reason to break the readiness report that needs it.
|
|
141
|
+
* @param resolve - the resolver to use; defaults to this plugin's own.
|
|
142
|
+
* @returns the report field, empty when the manifest declared no peers.
|
|
143
|
+
*/
|
|
144
|
+
function peerReport(resolve) {
|
|
145
|
+
if (HOST_PEERS.length === 0)
|
|
146
|
+
return {};
|
|
147
|
+
const lookup = resolve ?? ((name) => pluginRequire.resolve(name));
|
|
148
|
+
return {
|
|
149
|
+
peers: HOST_PEERS.map(name => {
|
|
150
|
+
try {
|
|
151
|
+
lookup(name);
|
|
152
|
+
return { name, resolved: true };
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
return { name, resolved: false, error: error instanceof Error ? error.message : String(error) };
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
108
158
|
};
|
|
109
159
|
}
|
|
@@ -84,7 +84,7 @@ const SETTINGS_WHEN_UNREADABLE = {
|
|
|
84
84
|
* Exported so the log line and the error message can quote the same set the parser accepts: a
|
|
85
85
|
* message that lists a value the code rejects (or omits one it takes) is worse than no message.
|
|
86
86
|
*/
|
|
87
|
-
export const BROWSER_CHANNELS = ['chrome', 'edge', 'auto', 'bundled', 'sidebar'];
|
|
87
|
+
export const BROWSER_CHANNELS = ['chrome', 'edge', 'electron', 'auto', 'bundled', 'sidebar'];
|
|
88
88
|
/**
|
|
89
89
|
* Coerce the headless mode, keeping `auto` when the value is not one of the known choices.
|
|
90
90
|
*
|
|
@@ -277,14 +277,11 @@ export function resolveSettings(raw, warn) {
|
|
|
277
277
|
* single-writer plugin and never throw at the caller.
|
|
278
278
|
*/
|
|
279
279
|
export class SettingsStore {
|
|
280
|
-
file;
|
|
281
|
-
log;
|
|
282
280
|
cached;
|
|
283
281
|
/** Last observed mtime, used to invalidate the cache on external edits. */
|
|
284
282
|
cachedMtimeMs = -1;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
*/
|
|
283
|
+
file;
|
|
284
|
+
log;
|
|
288
285
|
constructor(file = settingsPath(), log) {
|
|
289
286
|
this.file = file;
|
|
290
287
|
this.log = log;
|
|
@@ -5,7 +5,6 @@ import { readTabHandle, resolveSessionHandle, resolveTabHandle, sessionWireId }
|
|
|
5
5
|
* Discovery is deferred until a command needs the bridge; it never selects another carrier.
|
|
6
6
|
*/
|
|
7
7
|
export class SidebarOnlyHost {
|
|
8
|
-
loader;
|
|
9
8
|
referenceOverlayOwner = 'client';
|
|
10
9
|
views = new Map();
|
|
11
10
|
retiredSessions = new Set();
|
|
@@ -14,6 +13,7 @@ export class SidebarOnlyHost {
|
|
|
14
13
|
disposed = false;
|
|
15
14
|
discovery = new AbortController();
|
|
16
15
|
lostListener;
|
|
16
|
+
loader;
|
|
17
17
|
constructor(loader) {
|
|
18
18
|
this.loader = loader;
|
|
19
19
|
}
|