dsh-builtin-browser 0.5.2 → 0.5.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 +145 -0
- package/README.en.md +77 -68
- package/README.md +69 -89
- package/client.js +147 -15
- package/desktop-bridge/desktop-identity.json +9 -0
- package/desktop-bridge/install.mjs +220 -1
- package/desktop-bridge/plugin-browser-bridge.js +5 -0
- package/docs/README.md +1 -1
- package/docs/architecture.md +1 -1
- package/docs/limitations.md +19 -1
- package/docs/tool-reference.md +2 -1
- package/lib/browser-electron/bridge-status.d.ts +5 -3
- package/lib/browser-electron/bridge-status.js +53 -9
- package/lib/browser-electron/desktop-bridge-host.d.ts +25 -25
- package/lib/browser-electron/desktop-bridge-host.js +67 -40
- package/lib/browser-electron/desktop-identity.d.ts +58 -0
- package/lib/browser-electron/desktop-identity.js +236 -0
- package/lib/browser-electron/electron-provision.d.ts +59 -0
- package/lib/browser-electron/electron-provision.js +176 -0
- package/lib/browser-electron/entry.js +12 -0
- package/lib/browser-electron/host-main.js +68 -14
- package/lib/browser-electron/provider.d.ts +53 -3
- package/lib/browser-electron/provider.js +26 -5
- package/lib/browser-electron/remote-host.d.ts +3 -3
- package/lib/browser-electron/remote-host.js +25 -11
- package/lib/browser-electron/settings-store.d.ts +19 -0
- package/lib/browser-electron/settings-store.js +5 -1
- package/package.json +2 -3
- package/src/browser-electron/bridge-status.ts +56 -10
- package/src/browser-electron/desktop-bridge-host.ts +70 -41
- package/src/browser-electron/desktop-identity.ts +260 -0
- package/src/browser-electron/electron-provision.ts +208 -0
- package/src/browser-electron/entry.ts +12 -0
- package/src/browser-electron/host-main.ts +62 -12
- package/src/browser-electron/provider.ts +73 -8
- package/src/browser-electron/remote-host.ts +26 -12
- package/src/browser-electron/settings-store.ts +24 -1
- package/src/types/electron-shim.d.ts +8 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** How long a background provision may run before it is abandoned. */
|
|
2
|
+
export declare const PROVISION_TIMEOUT_MS = 180000;
|
|
3
|
+
/** What happened, in terms a log line can carry. */
|
|
4
|
+
export interface ProvisionResult {
|
|
5
|
+
/** `present` — nothing to do; `ready` — provisioned now; `skipped` — opted out; `failed`. */
|
|
6
|
+
readonly status: 'present' | 'ready' | 'skipped' | 'failed';
|
|
7
|
+
/** One line for the log; never contains a stack trace a user has to decode. */
|
|
8
|
+
readonly detail: string;
|
|
9
|
+
}
|
|
10
|
+
/** Everything this module touches from the outside, so a test can drive it without Electron. */
|
|
11
|
+
export interface ProvisionDeps {
|
|
12
|
+
/** Whether a spawnable binary already exists. */
|
|
13
|
+
readonly hasBinary: () => boolean;
|
|
14
|
+
/** The installed electron package's own installer script, or undefined when it is not there. */
|
|
15
|
+
readonly installerScript: () => string | undefined;
|
|
16
|
+
/** Runs the installer; resolves to an exit code, or rejects/returns null on failure. */
|
|
17
|
+
readonly run: (script: string) => Promise<{
|
|
18
|
+
code: number | null;
|
|
19
|
+
detail?: string;
|
|
20
|
+
}>;
|
|
21
|
+
/** Where the outcome goes. */
|
|
22
|
+
readonly log: (message: string) => void;
|
|
23
|
+
/** Opt-out honoured exactly like the install script honours it. */
|
|
24
|
+
readonly skip: () => boolean;
|
|
25
|
+
/** Budget for one provision. */
|
|
26
|
+
readonly timeoutMs: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether a spawnable Electron binary is already available.
|
|
30
|
+
*
|
|
31
|
+
* Resolved through the same probe the host uses, so this can never disagree with what a launch
|
|
32
|
+
* would find: a second, cheaper-looking check would be the classic way to report "ready" and then
|
|
33
|
+
* fail at spawn time.
|
|
34
|
+
* @returns true when a launch would find a binary.
|
|
35
|
+
*/
|
|
36
|
+
export declare function hasElectronRuntime(): boolean;
|
|
37
|
+
/** The real dependencies: this process's spawn, fs and logger. */
|
|
38
|
+
export declare function defaultDeps(log?: (message: string) => void): ProvisionDeps;
|
|
39
|
+
/**
|
|
40
|
+
* Provision the runtime once per process, when it is missing.
|
|
41
|
+
*
|
|
42
|
+
* Concurrent callers share the first attempt: two tool calls arriving together must not start two
|
|
43
|
+
* downloads into the same directory.
|
|
44
|
+
* @param deps - the effects, defaulted to this process's.
|
|
45
|
+
* @returns what happened. Never throws.
|
|
46
|
+
*/
|
|
47
|
+
export declare function ensureElectronRuntime(deps?: ProvisionDeps): Promise<ProvisionResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Start (or join) the single background attempt.
|
|
50
|
+
*
|
|
51
|
+
* Returns immediately with the shared promise, so a caller that does not care can ignore it and one
|
|
52
|
+
* that does can await it — the returned promise never rejects.
|
|
53
|
+
* @param log - where the outcome goes.
|
|
54
|
+
* @param deps - the effects; defaulted to this process's, overridable so a test can drive it.
|
|
55
|
+
* @returns the shared attempt.
|
|
56
|
+
*/
|
|
57
|
+
export declare function provisionElectronInBackground(log: (message: string) => void, deps?: ProvisionDeps): Promise<ProvisionResult>;
|
|
58
|
+
/** Forget the attempt. Tests only: a real process provisions at most once. */
|
|
59
|
+
export declare function resetProvisionStateForTest(): void;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prepare the Electron runtime *when it is needed*, instead of making installation depend on it.
|
|
3
|
+
*
|
|
4
|
+
* Reported as issue #41, from a real plugin-market install of 0.5.2:
|
|
5
|
+
*
|
|
6
|
+
* [ERR_PNPM_IGNORED_BUILDS] Ignored build scripts: dsh-builtin-browser@0.5.2
|
|
7
|
+
*
|
|
8
|
+
* and, once the build script was allowed:
|
|
9
|
+
*
|
|
10
|
+
* postinstall: Preparing Electron 44.10.1 … TypeError: fetch failed
|
|
11
|
+
* postinstall: Electron installation failed (exit 1). … [ELIFECYCLE] Command failed with exit code 1
|
|
12
|
+
*
|
|
13
|
+
* Two defects in one design, and both are about WHERE the download lives:
|
|
14
|
+
*
|
|
15
|
+
* 1. A `postinstall` puts a ~100 MB network download inside package installation. pnpm blocks
|
|
16
|
+
* install scripts by default (`strict-dep-builds`), so the plugin could not be installed at all
|
|
17
|
+
* on a default pnpm 11 profile; and if the download fails for any reason the *whole install*
|
|
18
|
+
* fails, which is a network condition reported as "the plugin is broken".
|
|
19
|
+
* 2. Nothing forced the download to happen at install time. The carrier that needs Electron is one
|
|
20
|
+
* of four, and on the desktop the sidebar needs none.
|
|
21
|
+
*
|
|
22
|
+
* So installation is offline by construction now, and this module does the work later: on plugin
|
|
23
|
+
* start when the operator explicitly asked for the bundled carrier, and never fatally — a failure
|
|
24
|
+
* here is a log line plus the existing, actionable resolution error that names the command to run.
|
|
25
|
+
*
|
|
26
|
+
* Being non-fatal is the point, not a detail: this runs inside a request-serving process, and a
|
|
27
|
+
* download that hangs must not be able to hold a browser tool call open.
|
|
28
|
+
* @module dsh-browser/browser-electron/electron-provision
|
|
29
|
+
*/
|
|
30
|
+
import { spawn } from 'node:child_process';
|
|
31
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
32
|
+
import { createRequire } from 'node:module';
|
|
33
|
+
import { dirname, join } from 'node:path';
|
|
34
|
+
import { internals } from './remote-host.js';
|
|
35
|
+
/** How long a background provision may run before it is abandoned. */
|
|
36
|
+
export const PROVISION_TIMEOUT_MS = 180_000;
|
|
37
|
+
/**
|
|
38
|
+
* Whether a spawnable Electron binary is already available.
|
|
39
|
+
*
|
|
40
|
+
* Resolved through the same probe the host uses, so this can never disagree with what a launch
|
|
41
|
+
* would find: a second, cheaper-looking check would be the classic way to report "ready" and then
|
|
42
|
+
* fail at spawn time.
|
|
43
|
+
* @returns true when a launch would find a binary.
|
|
44
|
+
*/
|
|
45
|
+
export function hasElectronRuntime() {
|
|
46
|
+
try {
|
|
47
|
+
internals.resolveElectronPath();
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The installed electron package's installer script.
|
|
56
|
+
*
|
|
57
|
+
* `require.resolve('electron/package.json')` is used rather than `require('electron')`: inside an
|
|
58
|
+
* Electron main process that module name is the built-in API, and requiring the package would
|
|
59
|
+
* download the binary as a side effect of asking about it.
|
|
60
|
+
* @returns the path to the dependency's own install script, or undefined.
|
|
61
|
+
*/
|
|
62
|
+
function electronInstallerScript() {
|
|
63
|
+
try {
|
|
64
|
+
const require = createRequire(import.meta.url);
|
|
65
|
+
const manifestPath = require.resolve('electron/package.json');
|
|
66
|
+
const script = join(dirname(manifestPath), 'install.js');
|
|
67
|
+
return existsSync(script) ? script : undefined;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** The Electron version the installed package asks for, for a log line that names the download. */
|
|
74
|
+
function electronVersion() {
|
|
75
|
+
try {
|
|
76
|
+
const require = createRequire(import.meta.url);
|
|
77
|
+
const manifest = JSON.parse(readFileSync(require.resolve('electron/package.json'), 'utf8'));
|
|
78
|
+
return typeof manifest.version === 'string' ? manifest.version : 'unknown';
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return 'unknown';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** The real dependencies: this process's spawn, fs and logger. */
|
|
85
|
+
export function defaultDeps(log = () => { }) {
|
|
86
|
+
return {
|
|
87
|
+
hasBinary: hasElectronRuntime,
|
|
88
|
+
installerScript: electronInstallerScript,
|
|
89
|
+
run: async (script) => {
|
|
90
|
+
const child = spawn(process.execPath, [script], {
|
|
91
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
92
|
+
stdio: ['ignore', 'ignore', 'ignore'],
|
|
93
|
+
windowsHide: true,
|
|
94
|
+
});
|
|
95
|
+
return await new Promise(resolve => {
|
|
96
|
+
child.once('error', error => resolve({ code: null, detail: String(error) }));
|
|
97
|
+
child.once('close', code => resolve({ code, detail: undefined }));
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
log,
|
|
101
|
+
skip: () => typeof process.env.ELECTRON_SKIP_BINARY_DOWNLOAD === 'string'
|
|
102
|
+
&& process.env.ELECTRON_SKIP_BINARY_DOWNLOAD !== '',
|
|
103
|
+
timeoutMs: PROVISION_TIMEOUT_MS,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Provision the runtime once per process, when it is missing.
|
|
108
|
+
*
|
|
109
|
+
* Concurrent callers share the first attempt: two tool calls arriving together must not start two
|
|
110
|
+
* downloads into the same directory.
|
|
111
|
+
* @param deps - the effects, defaulted to this process's.
|
|
112
|
+
* @returns what happened. Never throws.
|
|
113
|
+
*/
|
|
114
|
+
export async function ensureElectronRuntime(deps = defaultDeps()) {
|
|
115
|
+
if (deps.hasBinary())
|
|
116
|
+
return { status: 'present', detail: 'an Electron runtime is already available' };
|
|
117
|
+
if (deps.skip())
|
|
118
|
+
return { status: 'skipped', detail: 'ELECTRON_SKIP_BINARY_DOWNLOAD is set' };
|
|
119
|
+
const script = deps.installerScript();
|
|
120
|
+
if (script === undefined) {
|
|
121
|
+
return { status: 'failed', detail: 'the installed electron package has no install.js; reinstall the plugin in this profile' };
|
|
122
|
+
}
|
|
123
|
+
deps.log(`preparing Electron ${electronVersion()} in the background (a missing runtime needs a download)`);
|
|
124
|
+
// The bound has to be a REFERENCED timer, and it has to be cleared when the race finishes.
|
|
125
|
+
//
|
|
126
|
+
// A first version unref'd it — "do not keep the process alive for a download" — which is exactly
|
|
127
|
+
// backwards: with nothing else on the loop the timer never fires, the promise never settles, and a
|
|
128
|
+
// caller waiting on it hangs with no error at all. CI caught it before a user could: the test for
|
|
129
|
+
// this path failed with "Promise resolution is still pending but the event loop has already
|
|
130
|
+
// resolved". Keep it referenced, and clear it so a success does not leave a 180 s handle behind.
|
|
131
|
+
let timer;
|
|
132
|
+
const timeout = new Promise(resolve => {
|
|
133
|
+
timer = setTimeout(() => resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` }), deps.timeoutMs);
|
|
134
|
+
});
|
|
135
|
+
let outcome;
|
|
136
|
+
try {
|
|
137
|
+
outcome = await Promise.race([deps.run(script), timeout]);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
return { status: 'failed', detail: `the download failed: ${String(error)}` };
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
if (timer !== undefined)
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
}
|
|
146
|
+
if (outcome.code !== 0) {
|
|
147
|
+
return {
|
|
148
|
+
status: 'failed',
|
|
149
|
+
detail: `Electron provisioning did not finish (${outcome.detail ?? `exit ${String(outcome.code)}`}); `
|
|
150
|
+
+ 'the browser still works through a sidebar, Chrome or Edge, and `npx --no dsh-browser-install-electron` retries it',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return { status: 'ready', detail: 'the Electron runtime is ready' };
|
|
154
|
+
}
|
|
155
|
+
/** One attempt per process, shared by every caller. */
|
|
156
|
+
let attempt;
|
|
157
|
+
/**
|
|
158
|
+
* Start (or join) the single background attempt.
|
|
159
|
+
*
|
|
160
|
+
* Returns immediately with the shared promise, so a caller that does not care can ignore it and one
|
|
161
|
+
* that does can await it — the returned promise never rejects.
|
|
162
|
+
* @param log - where the outcome goes.
|
|
163
|
+
* @param deps - the effects; defaulted to this process's, overridable so a test can drive it.
|
|
164
|
+
* @returns the shared attempt.
|
|
165
|
+
*/
|
|
166
|
+
export function provisionElectronInBackground(log, deps = defaultDeps(log)) {
|
|
167
|
+
attempt ??= ensureElectronRuntime(deps).then(result => {
|
|
168
|
+
log(`electron runtime: ${result.status} — ${result.detail}`);
|
|
169
|
+
return result;
|
|
170
|
+
});
|
|
171
|
+
return attempt;
|
|
172
|
+
}
|
|
173
|
+
/** Forget the attempt. Tests only: a real process provisions at most once. */
|
|
174
|
+
export function resetProvisionStateForTest() {
|
|
175
|
+
attempt = undefined;
|
|
176
|
+
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import z from '@deepseek-ai/schemastery';
|
|
13
13
|
import { ElectronBrowserProvider } from './provider.js';
|
|
14
|
+
import { provisionElectronInBackground } from './electron-provision.js';
|
|
14
15
|
import { randomUUID } from 'node:crypto';
|
|
15
16
|
import { existsSync, mkdirSync, renameSync, statSync } from 'node:fs';
|
|
16
17
|
import { homedir } from 'node:os';
|
|
@@ -116,6 +117,17 @@ export function apply(ctx, config) {
|
|
|
116
117
|
// different lifetimes (a spawned child vs. the shell's view), and pretending
|
|
117
118
|
// otherwise would leave a stray window behind.
|
|
118
119
|
const selfHosted = new RemoteElectronViewHost(defaultHostMainPath());
|
|
120
|
+
// The self-hosted carrier is the only one that needs Electron, and it is prepared HERE, lazily,
|
|
121
|
+
// rather than during package installation (issue #41: a `postinstall` download made a default
|
|
122
|
+
// pnpm 11 profile refuse the install outright, and a failed fetch failed the install too).
|
|
123
|
+
//
|
|
124
|
+
// Non-fatal by construction: this never rejects, never blocks a tool call, and its failure leaves
|
|
125
|
+
// the sidebar / Chrome / Edge carriers untouched. Only the two channels that can use the bundled
|
|
126
|
+
// runtime are worth the download; an explicit chrome/edge choice is not.
|
|
127
|
+
const wantedChannel = settings.get().browser.channel;
|
|
128
|
+
if (wantedChannel === 'bundled' || wantedChannel === 'auto') {
|
|
129
|
+
void provisionElectronInBackground(message => ctx.logger?.info?.(`dsh-builtin-browser: ${message}`));
|
|
130
|
+
}
|
|
119
131
|
let unregister = ctx.browser.registerBrowserProvider(new ElectronBrowserProvider(selfHosted, providerConfig));
|
|
120
132
|
let disposed = false;
|
|
121
133
|
let carrierChoice = 0;
|
|
@@ -536,8 +536,17 @@ function updateWindowTitle(win, viewId, label) {
|
|
|
536
536
|
}
|
|
537
537
|
catch { /* destroyed */ }
|
|
538
538
|
}
|
|
539
|
-
/**
|
|
540
|
-
|
|
539
|
+
/**
|
|
540
|
+
* Make one view the visible (topmost) one WITHIN its window, leaving the window itself alone.
|
|
541
|
+
*
|
|
542
|
+
* Split out of {@link showViewInWindow} for quiet-mode capture: a screenshot still has to look
|
|
543
|
+
* at the active tab rather than another tab of the same window, but it must not show, restore,
|
|
544
|
+
* raise or focus the window to do it. Everything here is contentView-local.
|
|
545
|
+
* @param win - the window holding the view.
|
|
546
|
+
* @param viewId - the view to reveal.
|
|
547
|
+
* @param label - session/task label, when known, for the window title.
|
|
548
|
+
*/
|
|
549
|
+
function revealViewInWindow(win, viewId, label) {
|
|
541
550
|
const entry = win.views.get(viewId);
|
|
542
551
|
if (entry === undefined)
|
|
543
552
|
return;
|
|
@@ -578,12 +587,43 @@ function showViewInWindow(win, viewId, label) {
|
|
|
578
587
|
// Always refresh the title: it reflects the CURRENT page of the visible
|
|
579
588
|
// view, which changes as the agent navigates.
|
|
580
589
|
updateWindowTitle(win, viewId, label);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Make one view the visible one within its window, and — outside quiet mode — raise the window.
|
|
593
|
+
* @param win - the window holding the view.
|
|
594
|
+
* @param viewId - the view to present.
|
|
595
|
+
* @param label - session/task label, when known, for the window title.
|
|
596
|
+
* @param quiet - `ui.quiet`: present without taking the screen over.
|
|
597
|
+
* @param needSurface - quiet mode only: this presentation is the barrier before synthesized
|
|
598
|
+
* input, so the window has to be visible even if the user minimized it. A navigation or a tab
|
|
599
|
+
* switch does not need that and leaves a minimized window alone.
|
|
600
|
+
*/
|
|
601
|
+
function showViewInWindow(win, viewId, label, quiet = false, needSurface = false) {
|
|
602
|
+
revealViewInWindow(win, viewId, label);
|
|
581
603
|
// Raise this session's window so the human sees the page being worked on
|
|
582
604
|
// (moveTop raises without stealing keyboard focus).
|
|
605
|
+
//
|
|
606
|
+
// Quiet mode (`ui.quiet`): the user asked not to be interrupted, so this must not
|
|
607
|
+
// activate the application, steal keyboard focus, or pull the window in front of the one
|
|
608
|
+
// they are using. Chromium drops `Input.*` for a view with no display surface, so the one
|
|
609
|
+
// case that still needs a visible window — the barrier before synthesized input — restores
|
|
610
|
+
// it with `showInactive()`, which shows it without becoming the key window, and never calls
|
|
611
|
+
// `moveTop()`. Everything else (navigation, tab switching, screenshots) leaves a minimized
|
|
612
|
+
// window minimized.
|
|
583
613
|
try {
|
|
584
|
-
if (
|
|
585
|
-
|
|
586
|
-
|
|
614
|
+
if (quiet) {
|
|
615
|
+
if (!needSurface)
|
|
616
|
+
return;
|
|
617
|
+
if (win.window.isMinimized())
|
|
618
|
+
win.window.restore();
|
|
619
|
+
if (!win.window.isVisible())
|
|
620
|
+
win.window.showInactive();
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
if (!win.window.isVisible())
|
|
624
|
+
win.window.show();
|
|
625
|
+
win.window.moveTop();
|
|
626
|
+
}
|
|
587
627
|
}
|
|
588
628
|
catch { /* closing */ }
|
|
589
629
|
}
|
|
@@ -751,7 +791,7 @@ async function handle(op, msg) {
|
|
|
751
791
|
throw new Error('showView missing viewId');
|
|
752
792
|
const win = windowOfView(viewId);
|
|
753
793
|
if (win !== undefined)
|
|
754
|
-
showViewInWindow(win, viewId, typeof msg.label === 'string' ? msg.label : undefined);
|
|
794
|
+
showViewInWindow(win, viewId, typeof msg.label === 'string' ? msg.label : undefined, msg.quiet === true, msg.needSurface === true);
|
|
755
795
|
reply(msg.id, { ok: true });
|
|
756
796
|
return;
|
|
757
797
|
}
|
|
@@ -829,17 +869,31 @@ async function handle(op, msg) {
|
|
|
829
869
|
const wantQuality = typeof msg.quality === 'number' ? msg.quality : 80;
|
|
830
870
|
const maxW = typeof msg.maxWidth === 'number' ? msg.maxWidth : 0;
|
|
831
871
|
const maxH = typeof msg.maxHeight === 'number' ? msg.maxHeight : 0;
|
|
872
|
+
// Quiet mode: a screenshot is not a reason to take the screen over. Skipping the
|
|
873
|
+
// raise below is what makes a minimized window survive a screenshot: capturePage on
|
|
874
|
+
// a hidden view returns an empty image, and the CDP fallback captures without needing
|
|
875
|
+
// a display surface. The default path keeps the raise, because there a screenshot is
|
|
876
|
+
// how the human follows what the agent is doing.
|
|
877
|
+
const quiet = msg.quiet === true;
|
|
832
878
|
let mime = 'image/png';
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
879
|
+
if (quiet) {
|
|
880
|
+
// The active tab has to be the visible one INSIDE the window, or the capture may read
|
|
881
|
+
// another tab. Keep that switch contentView-local: show/restore/focus are precisely
|
|
882
|
+
// what quiet mode forbids.
|
|
883
|
+
revealViewInWindow(win, viewId);
|
|
836
884
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
885
|
+
else {
|
|
886
|
+
try {
|
|
887
|
+
if (!win.window.isVisible())
|
|
888
|
+
win.window.show();
|
|
889
|
+
}
|
|
890
|
+
catch { /* closing */ }
|
|
891
|
+
try {
|
|
892
|
+
win.window.restore();
|
|
893
|
+
}
|
|
894
|
+
catch { /* not minimized */ }
|
|
895
|
+
win.window.focus();
|
|
840
896
|
}
|
|
841
|
-
catch { /* not minimized */ }
|
|
842
|
-
win.window.focus();
|
|
843
897
|
let base64 = '';
|
|
844
898
|
let renderedSize;
|
|
845
899
|
try {
|
|
@@ -43,8 +43,10 @@ export interface ElectronBrowserViewHost {
|
|
|
43
43
|
* @param label - human-readable session/task label, when the provider knows
|
|
44
44
|
* one; the host may surface it (e.g. in the window title) so a human can
|
|
45
45
|
* tell which task's page is currently visible.
|
|
46
|
+
* @param options - presentation policy; `quiet` asks for a surface without taking
|
|
47
|
+
* over the screen (see {@link PresentOptions}).
|
|
46
48
|
*/
|
|
47
|
-
showView?(handle: ElectronViewHandle, label?: string): void;
|
|
49
|
+
showView?(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void;
|
|
48
50
|
/**
|
|
49
51
|
* Optional: (re)present a view and WAIT until the host confirms it. Chromium
|
|
50
52
|
* silently drops CDP-synthesized input (`Input.*`) for a view that has no
|
|
@@ -57,8 +59,9 @@ export interface ElectronBrowserViewHost {
|
|
|
57
59
|
* assumed to present every view (headless/probe hosts).
|
|
58
60
|
* @param handle - the handle to present.
|
|
59
61
|
* @param label - human-readable session/task label, as in {@link showView}.
|
|
62
|
+
* @param options - presentation policy, as in {@link showView}.
|
|
60
63
|
*/
|
|
61
|
-
presentView?(handle: ElectronViewHandle, label?: string): Promise<void>;
|
|
64
|
+
presentView?(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void>;
|
|
62
65
|
/**
|
|
63
66
|
* Optional: pages this carrier holds that the provider never created.
|
|
64
67
|
*
|
|
@@ -243,7 +246,7 @@ export interface ElectronViewHandle {
|
|
|
243
246
|
* @param params - CDP command parameters.
|
|
244
247
|
* @returns the CDP `result` object.
|
|
245
248
|
*/
|
|
246
|
-
sendCommand(method: string, params?: Record<string, unknown
|
|
249
|
+
sendCommand(method: string, params?: Record<string, unknown>, options?: CommandOptions): Promise<Record<string, unknown>>;
|
|
247
250
|
/**
|
|
248
251
|
* Whether this view's CDP can encode JPEG and honour a quality setting.
|
|
249
252
|
*
|
|
@@ -419,12 +422,51 @@ export declare function toExportedCookies(raw: unknown): ExportedCookie[];
|
|
|
419
422
|
* @returns the CDP cookie, or undefined when it lacks a usable domain.
|
|
420
423
|
*/
|
|
421
424
|
export declare function toCdpCookie(cookie: ExportedCookie): Record<string, unknown> | undefined;
|
|
425
|
+
/**
|
|
426
|
+
* How the carrier should present a view before it is used.
|
|
427
|
+
*
|
|
428
|
+
* `quiet` is the resolved `ui.quiet` switch. It does not mean "invisible": Chromium drops
|
|
429
|
+
* synthesized `Input.*` for a view without a display surface, so input still needs one. It means
|
|
430
|
+
* the carrier must get that surface without taking the screen over — no application activation
|
|
431
|
+
* and no keyboard focus. Navigation and tab switching only reveal the view inside its window; the
|
|
432
|
+
* pre-input barrier may restore a minimized window (it needs the surface), but even then it shows
|
|
433
|
+
* it inactive instead of focusing or raising it. A host that cannot honour this (a headless probe,
|
|
434
|
+
* the desktop sidebar) simply ignores it.
|
|
435
|
+
*/
|
|
436
|
+
export interface PresentOptions {
|
|
437
|
+
readonly quiet?: boolean;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* How a command should reach its page.
|
|
441
|
+
*
|
|
442
|
+
* Reported as issue #46: opening the live preview pushed the conversation's sidebar browser panel
|
|
443
|
+
* to the front — a read-only "look at it" action changing the reader's layout. The chain was
|
|
444
|
+
* `capturePassive` → `sendCommand('Page.captureScreenshot')` → the host's guest lookup → the bridge's
|
|
445
|
+
* `ensureSidebar` → a retry that asked the client half to `openSession`, which is exactly what a tool
|
|
446
|
+
* call is allowed to do and a preview is not.
|
|
447
|
+
*
|
|
448
|
+
* `present: false` says "this command must not make anything visible": use the page this
|
|
449
|
+
* conversation already has, and treat "not displayed" as a state to report rather than a condition
|
|
450
|
+
* to fix.
|
|
451
|
+
*/
|
|
452
|
+
export interface CommandOptions {
|
|
453
|
+
/** Present the view first (default), or only use a page that is already there. */
|
|
454
|
+
readonly present?: boolean;
|
|
455
|
+
}
|
|
422
456
|
/** Native capture options the self-hosted view handle understands. */
|
|
423
457
|
export interface ScreenshotOptions {
|
|
424
458
|
readonly format?: 'png' | 'jpeg';
|
|
425
459
|
readonly quality?: number;
|
|
426
460
|
readonly maxWidth?: number;
|
|
427
461
|
readonly maxHeight?: number;
|
|
462
|
+
/**
|
|
463
|
+
* Capture without presenting the window first (`ui.quiet`).
|
|
464
|
+
*
|
|
465
|
+
* The self-hosted host answers this by skipping its restore/show/focus step: a visible window
|
|
466
|
+
* still captures through `capturePage()`, and a minimized or hidden one falls through to the
|
|
467
|
+
* CDP path, which needs no display surface.
|
|
468
|
+
*/
|
|
469
|
+
readonly quiet?: boolean;
|
|
428
470
|
}
|
|
429
471
|
/** CDP method for runtime evaluation (the execute path). */
|
|
430
472
|
export declare const CDP_RUNTIME_EVALUATE = "Runtime.evaluate";
|
|
@@ -885,6 +927,14 @@ export declare class ElectronBrowserProvider implements BrowserProvider {
|
|
|
885
927
|
* diagnostics: it can never be allowed to become the failure.
|
|
886
928
|
*/
|
|
887
929
|
private notifyUserActionError;
|
|
930
|
+
/**
|
|
931
|
+
* Whether the operator asked for quiet mode (`ui.quiet`).
|
|
932
|
+
*
|
|
933
|
+
* Read live on every call rather than captured at construction: the panel writes the document
|
|
934
|
+
* and the next operation is expected to honour it, without a restart.
|
|
935
|
+
* @returns true when the carrier must present views without taking the screen over.
|
|
936
|
+
*/
|
|
937
|
+
private isQuiet;
|
|
888
938
|
/**
|
|
889
939
|
* Ask the host to show the active tab's view, carrying the session label.
|
|
890
940
|
*
|
|
@@ -738,7 +738,7 @@ export class ElectronBrowserProvider {
|
|
|
738
738
|
signal?.throwIfAborted();
|
|
739
739
|
const timeoutMs = 10_000;
|
|
740
740
|
try {
|
|
741
|
-
await withTimeout(present(handle, s.label), timeoutMs, signal, `browser: presenting the page view timed out after ${timeoutMs}ms`);
|
|
741
|
+
await withTimeout(present(handle, s.label, { quiet: this.isQuiet() }), timeoutMs, signal, `browser: presenting the page view timed out after ${timeoutMs}ms`);
|
|
742
742
|
this.showActive(s);
|
|
743
743
|
}
|
|
744
744
|
catch (error) {
|
|
@@ -2606,12 +2606,18 @@ export class ElectronBrowserProvider {
|
|
|
2606
2606
|
}
|
|
2607
2607
|
// Real Chrome/Edge (and the sidebar): CDP. Viewport only — `captureBeyondViewport` would pull
|
|
2608
2608
|
// the whole document, which is neither what a viewer shows nor bounded in size.
|
|
2609
|
+
//
|
|
2610
|
+
// `present: false` is load-bearing (issue #46): a preview is read-only, so it must not reach the
|
|
2611
|
+
// carrier's present path, which for the sidebar asks the shell to display this conversation —
|
|
2612
|
+
// the reported symptom was the sidebar browser panel jumping to the front when someone opened
|
|
2613
|
+
// the preview. A page that is not displayed now reads as "unavailable", which the route already
|
|
2614
|
+
// turns into the panel's paused state.
|
|
2609
2615
|
const result = await withTimeout(handle.sendCommand(CDP_PAGE_CAPTURE_SCREENSHOT, {
|
|
2610
2616
|
format: 'jpeg',
|
|
2611
2617
|
quality: PREVIEW_QUALITY,
|
|
2612
2618
|
fromSurface: true,
|
|
2613
2619
|
captureBeyondViewport: false,
|
|
2614
|
-
}), timeoutMs, undefined, timeoutMessage);
|
|
2620
|
+
}, { present: false }), timeoutMs, undefined, timeoutMessage);
|
|
2615
2621
|
const base64 = typeof result?.data === 'string' ? result.data : '';
|
|
2616
2622
|
if (base64 === '') {
|
|
2617
2623
|
throw new BrowserError('browser: preview unavailable (the carrier returned no image)', 'BROWSER_PREVIEW_UNAVAILABLE');
|
|
@@ -2632,13 +2638,18 @@ export class ElectronBrowserProvider {
|
|
|
2632
2638
|
// can produce JPEG (CDP JPEG hangs on Electron 43).
|
|
2633
2639
|
const capturable = handle;
|
|
2634
2640
|
if (request?.fullPage !== true && typeof capturable.capture === 'function') {
|
|
2635
|
-
// Ensure the target view is the visible one before capturing.
|
|
2636
|
-
|
|
2641
|
+
// Ensure the target view is the visible one before capturing — unless quiet mode is on.
|
|
2642
|
+
// There, presenting the view is exactly what the user asked to avoid (it restores and
|
|
2643
|
+
// raises the window); the host switches the visible tab inside the window and, if the
|
|
2644
|
+
// window has no surface to capture, falls through to CDP.
|
|
2645
|
+
if (!this.isQuiet())
|
|
2646
|
+
this.showActive(s);
|
|
2637
2647
|
const timeoutMs = 30_000;
|
|
2638
2648
|
const shot = await withTimeout(capturable.capture({
|
|
2639
2649
|
...format === 'jpeg' ? { format, quality: request?.quality } : {},
|
|
2640
2650
|
...request?.maxWidth !== undefined ? { maxWidth: request.maxWidth } : {},
|
|
2641
2651
|
...request?.maxHeight !== undefined ? { maxHeight: request.maxHeight } : {},
|
|
2652
|
+
quiet: this.isQuiet(),
|
|
2642
2653
|
}), timeoutMs, signal, `browser: screenshot timed out after ${timeoutMs}ms`);
|
|
2643
2654
|
if (shot.base64 === '') {
|
|
2644
2655
|
throw new BrowserError('browser: capture returned an empty image (view not painted); retry shortly', 'BROWSER_SCREENSHOT_FAILED');
|
|
@@ -3089,6 +3100,16 @@ export class ElectronBrowserProvider {
|
|
|
3089
3100
|
if (!reported)
|
|
3090
3101
|
process.stderr.write(`[dsh-browser] user action failed: ${message}\n`);
|
|
3091
3102
|
}
|
|
3103
|
+
/**
|
|
3104
|
+
* Whether the operator asked for quiet mode (`ui.quiet`).
|
|
3105
|
+
*
|
|
3106
|
+
* Read live on every call rather than captured at construction: the panel writes the document
|
|
3107
|
+
* and the next operation is expected to honour it, without a restart.
|
|
3108
|
+
* @returns true when the carrier must present views without taking the screen over.
|
|
3109
|
+
*/
|
|
3110
|
+
isQuiet() {
|
|
3111
|
+
return this.settingsSource?.().ui.quiet === true;
|
|
3112
|
+
}
|
|
3092
3113
|
/**
|
|
3093
3114
|
* Ask the host to show the active tab's view, carrying the session label.
|
|
3094
3115
|
*
|
|
@@ -3101,7 +3122,7 @@ export class ElectronBrowserProvider {
|
|
|
3101
3122
|
* silently desynchronising the two and failing every screenshot.
|
|
3102
3123
|
*/
|
|
3103
3124
|
showActive(s) {
|
|
3104
|
-
this.host.showView?.(this.activeTab(s).handle, s.label);
|
|
3125
|
+
this.host.showView?.(this.activeTab(s).handle, s.label, { quiet: this.isQuiet() });
|
|
3105
3126
|
const autoExpand = this.settingsSource === undefined || this.settingsSource().ui.autoExpandOnce;
|
|
3106
3127
|
if (autoExpand)
|
|
3107
3128
|
return;
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* unauthenticated peer can neither read traffic nor drive a session.
|
|
27
27
|
* @module dsh-browser/browser-electron/remote-host
|
|
28
28
|
*/
|
|
29
|
-
import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle } from './provider.js';
|
|
29
|
+
import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle, PresentOptions } from './provider.js';
|
|
30
30
|
/**
|
|
31
31
|
* Locate a SPAWNABLE Electron binary — one that runs a script given as an
|
|
32
32
|
* argument, i.e. a BARE electron, never a packaged app executable:
|
|
@@ -209,7 +209,7 @@ export declare class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
209
209
|
private onChildExit;
|
|
210
210
|
createView(): ElectronViewHandle;
|
|
211
211
|
private ensureView;
|
|
212
|
-
showView(handle: ElectronViewHandle, label?: string): void;
|
|
212
|
+
showView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void;
|
|
213
213
|
/**
|
|
214
214
|
* (Re)present a view and WAIT for the child to confirm it, so the provider
|
|
215
215
|
* can dispatch CDP `Input.*` knowing the view has a display surface.
|
|
@@ -225,7 +225,7 @@ export declare class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
225
225
|
* in order: its reply is queued behind the showView and so only arrives once
|
|
226
226
|
* the visibility change has been applied.
|
|
227
227
|
*/
|
|
228
|
-
presentView(handle: ElectronViewHandle, label?: string): Promise<void>;
|
|
228
|
+
presentView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void>;
|
|
229
229
|
/** Route a view into its session's own window (one window per session). */
|
|
230
230
|
groupView(handle: ElectronViewHandle, windowId: string, label?: string): void;
|
|
231
231
|
/** Register the provider's handler for user-initiated toolbar actions. */
|
|
@@ -95,13 +95,13 @@ function resolveElectronPathImpl(inputs) {
|
|
|
95
95
|
if (hostExe !== undefined)
|
|
96
96
|
return hostExe;
|
|
97
97
|
throw new Error('dsh-builtin-browser: cannot locate a spawnable Electron binary. ' +
|
|
98
|
-
'The electron package ships with the plugin
|
|
99
|
-
'
|
|
100
|
-
'
|
|
101
|
-
'
|
|
102
|
-
'
|
|
103
|
-
'
|
|
104
|
-
'
|
|
98
|
+
'The electron package ships with the plugin and its binary is downloaded on first use, not at install time ' +
|
|
99
|
+
'(issue #41: an install-time download made default profiles refuse the plugin). The plugin prepares it ' +
|
|
100
|
+
'automatically when the bundled carrier is selected; to do it by hand, run ' +
|
|
101
|
+
'`npx --no dsh-browser-install-electron` in the profile that installed the plugin, then retry. ' +
|
|
102
|
+
'Alternatively set ELECTRON_PATH to an electron executable. Note: the host\'s own executable cannot be ' +
|
|
103
|
+
'reused when it is a packaged Electron app (e.g. DSH Desktop.exe) — only a real electron binary can be ' +
|
|
104
|
+
'spawned.');
|
|
105
105
|
}
|
|
106
106
|
/** DSH install anchors: electron installed separately (profile / global prefix), newest wins. */
|
|
107
107
|
function anchoredElectronBinary() {
|
|
@@ -1154,13 +1154,19 @@ export class RemoteElectronViewHost {
|
|
|
1154
1154
|
this.views.set(id, view);
|
|
1155
1155
|
return view;
|
|
1156
1156
|
}
|
|
1157
|
-
showView(handle, label) {
|
|
1157
|
+
showView(handle, label, options) {
|
|
1158
1158
|
// Fire-and-forget by design (visibility is best-effort), but a rejected
|
|
1159
1159
|
// promise must not become an unhandled rejection (crash on Node >= 15).
|
|
1160
1160
|
// The label (session/task id) rides along so the child can show it in the
|
|
1161
1161
|
// window title — a human can then tell which task's page is visible.
|
|
1162
|
+
// `quiet` is only sent when it is on: the child's default is the documented
|
|
1163
|
+
// "present and raise" behaviour, so an old child keeps working either way.
|
|
1162
1164
|
void this.ready()
|
|
1163
|
-
.then(() => this.client?.call('showView', {
|
|
1165
|
+
.then(() => this.client?.call('showView', {
|
|
1166
|
+
viewId: handle.id,
|
|
1167
|
+
...label !== undefined ? { label } : {},
|
|
1168
|
+
...options?.quiet === true ? { quiet: true } : {},
|
|
1169
|
+
}))
|
|
1164
1170
|
.catch(() => { });
|
|
1165
1171
|
}
|
|
1166
1172
|
/**
|
|
@@ -1178,7 +1184,7 @@ export class RemoteElectronViewHost {
|
|
|
1178
1184
|
* in order: its reply is queued behind the showView and so only arrives once
|
|
1179
1185
|
* the visibility change has been applied.
|
|
1180
1186
|
*/
|
|
1181
|
-
async presentView(handle, label) {
|
|
1187
|
+
async presentView(handle, label, options) {
|
|
1182
1188
|
await this.ready();
|
|
1183
1189
|
const client = this.client;
|
|
1184
1190
|
if (client === undefined)
|
|
@@ -1189,7 +1195,15 @@ export class RemoteElectronViewHost {
|
|
|
1189
1195
|
if (handle instanceof DeferredRemoteView) {
|
|
1190
1196
|
await withTimeout(handle.ensureMaterialized(), PRESENT_TIMEOUT_MS, 'browser host did not materialize the view');
|
|
1191
1197
|
}
|
|
1192
|
-
await withTimeout(client.call('showView', {
|
|
1198
|
+
await withTimeout(client.call('showView', {
|
|
1199
|
+
viewId: handle.id,
|
|
1200
|
+
...label !== undefined ? { label } : {},
|
|
1201
|
+
// `needSurface` tells the child this is the pre-input barrier: under quiet mode this
|
|
1202
|
+
// is the only presentation allowed to un-minimize a window, because Chromium drops
|
|
1203
|
+
// `Input.*` without a display surface. One line below in the child, and only read
|
|
1204
|
+
// there when `quiet` is set.
|
|
1205
|
+
...options?.quiet === true ? { quiet: true, needSurface: true } : {},
|
|
1206
|
+
}), PRESENT_TIMEOUT_MS, 'browser host did not confirm the view presentation');
|
|
1193
1207
|
await withTimeout(client.call('ping'), PRESENT_TIMEOUT_MS, 'browser host stopped answering');
|
|
1194
1208
|
}
|
|
1195
1209
|
/** Route a view into its session's own window (one window per session). */
|