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
|
@@ -144,8 +144,10 @@ export interface ElectronBrowserViewHost {
|
|
|
144
144
|
* @param label - human-readable session/task label, when the provider knows
|
|
145
145
|
* one; the host may surface it (e.g. in the window title) so a human can
|
|
146
146
|
* tell which task's page is currently visible.
|
|
147
|
+
* @param options - presentation policy; `quiet` asks for a surface without taking
|
|
148
|
+
* over the screen (see {@link PresentOptions}).
|
|
147
149
|
*/
|
|
148
|
-
showView?(handle: ElectronViewHandle, label?: string): void
|
|
150
|
+
showView?(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void
|
|
149
151
|
/**
|
|
150
152
|
* Optional: (re)present a view and WAIT until the host confirms it. Chromium
|
|
151
153
|
* silently drops CDP-synthesized input (`Input.*`) for a view that has no
|
|
@@ -158,8 +160,9 @@ export interface ElectronBrowserViewHost {
|
|
|
158
160
|
* assumed to present every view (headless/probe hosts).
|
|
159
161
|
* @param handle - the handle to present.
|
|
160
162
|
* @param label - human-readable session/task label, as in {@link showView}.
|
|
163
|
+
* @param options - presentation policy, as in {@link showView}.
|
|
161
164
|
*/
|
|
162
|
-
presentView?(handle: ElectronViewHandle, label?: string): Promise<void>
|
|
165
|
+
presentView?(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void>
|
|
163
166
|
/**
|
|
164
167
|
* Optional: pages this carrier holds that the provider never created.
|
|
165
168
|
*
|
|
@@ -328,7 +331,7 @@ export interface ElectronViewHandle {
|
|
|
328
331
|
* @param params - CDP command parameters.
|
|
329
332
|
* @returns the CDP `result` object.
|
|
330
333
|
*/
|
|
331
|
-
sendCommand(method: string, params?: Record<string, unknown
|
|
334
|
+
sendCommand(method: string, params?: Record<string, unknown>, options?: CommandOptions): Promise<Record<string, unknown>>
|
|
332
335
|
/**
|
|
333
336
|
* Whether this view's CDP can encode JPEG and honour a quality setting.
|
|
334
337
|
*
|
|
@@ -610,12 +613,53 @@ export function toCdpCookie(cookie: ExportedCookie): Record<string, unknown> | u
|
|
|
610
613
|
}
|
|
611
614
|
}
|
|
612
615
|
|
|
616
|
+
/**
|
|
617
|
+
* How the carrier should present a view before it is used.
|
|
618
|
+
*
|
|
619
|
+
* `quiet` is the resolved `ui.quiet` switch. It does not mean "invisible": Chromium drops
|
|
620
|
+
* synthesized `Input.*` for a view without a display surface, so input still needs one. It means
|
|
621
|
+
* the carrier must get that surface without taking the screen over — no application activation
|
|
622
|
+
* and no keyboard focus. Navigation and tab switching only reveal the view inside its window; the
|
|
623
|
+
* pre-input barrier may restore a minimized window (it needs the surface), but even then it shows
|
|
624
|
+
* it inactive instead of focusing or raising it. A host that cannot honour this (a headless probe,
|
|
625
|
+
* the desktop sidebar) simply ignores it.
|
|
626
|
+
*/
|
|
627
|
+
export interface PresentOptions {
|
|
628
|
+
readonly quiet?: boolean
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* How a command should reach its page.
|
|
633
|
+
*
|
|
634
|
+
* Reported as issue #46: opening the live preview pushed the conversation's sidebar browser panel
|
|
635
|
+
* to the front — a read-only "look at it" action changing the reader's layout. The chain was
|
|
636
|
+
* `capturePassive` → `sendCommand('Page.captureScreenshot')` → the host's guest lookup → the bridge's
|
|
637
|
+
* `ensureSidebar` → a retry that asked the client half to `openSession`, which is exactly what a tool
|
|
638
|
+
* call is allowed to do and a preview is not.
|
|
639
|
+
*
|
|
640
|
+
* `present: false` says "this command must not make anything visible": use the page this
|
|
641
|
+
* conversation already has, and treat "not displayed" as a state to report rather than a condition
|
|
642
|
+
* to fix.
|
|
643
|
+
*/
|
|
644
|
+
export interface CommandOptions {
|
|
645
|
+
/** Present the view first (default), or only use a page that is already there. */
|
|
646
|
+
readonly present?: boolean
|
|
647
|
+
}
|
|
648
|
+
|
|
613
649
|
/** Native capture options the self-hosted view handle understands. */
|
|
614
650
|
export interface ScreenshotOptions {
|
|
615
651
|
readonly format?: 'png' | 'jpeg'
|
|
616
652
|
readonly quality?: number
|
|
617
653
|
readonly maxWidth?: number
|
|
618
654
|
readonly maxHeight?: number
|
|
655
|
+
/**
|
|
656
|
+
* Capture without presenting the window first (`ui.quiet`).
|
|
657
|
+
*
|
|
658
|
+
* The self-hosted host answers this by skipping its restore/show/focus step: a visible window
|
|
659
|
+
* still captures through `capturePage()`, and a minimized or hidden one falls through to the
|
|
660
|
+
* CDP path, which needs no display surface.
|
|
661
|
+
*/
|
|
662
|
+
readonly quiet?: boolean
|
|
619
663
|
}
|
|
620
664
|
/** CDP method for runtime evaluation (the execute path). */
|
|
621
665
|
export const CDP_RUNTIME_EVALUATE = 'Runtime.evaluate'
|
|
@@ -1198,7 +1242,7 @@ export class ElectronBrowserProvider implements BrowserProvider {
|
|
|
1198
1242
|
const timeoutMs = 10_000
|
|
1199
1243
|
try {
|
|
1200
1244
|
await withTimeout(
|
|
1201
|
-
present(handle, s.label),
|
|
1245
|
+
present(handle, s.label, { quiet: this.isQuiet() }),
|
|
1202
1246
|
timeoutMs,
|
|
1203
1247
|
signal,
|
|
1204
1248
|
`browser: presenting the page view timed out after ${timeoutMs}ms`,
|
|
@@ -3225,13 +3269,19 @@ export class ElectronBrowserProvider implements BrowserProvider {
|
|
|
3225
3269
|
}
|
|
3226
3270
|
// Real Chrome/Edge (and the sidebar): CDP. Viewport only — `captureBeyondViewport` would pull
|
|
3227
3271
|
// the whole document, which is neither what a viewer shows nor bounded in size.
|
|
3272
|
+
//
|
|
3273
|
+
// `present: false` is load-bearing (issue #46): a preview is read-only, so it must not reach the
|
|
3274
|
+
// carrier's present path, which for the sidebar asks the shell to display this conversation —
|
|
3275
|
+
// the reported symptom was the sidebar browser panel jumping to the front when someone opened
|
|
3276
|
+
// the preview. A page that is not displayed now reads as "unavailable", which the route already
|
|
3277
|
+
// turns into the panel's paused state.
|
|
3228
3278
|
const result = await withTimeout(
|
|
3229
3279
|
handle.sendCommand(CDP_PAGE_CAPTURE_SCREENSHOT, {
|
|
3230
3280
|
format: 'jpeg',
|
|
3231
3281
|
quality: PREVIEW_QUALITY,
|
|
3232
3282
|
fromSurface: true,
|
|
3233
3283
|
captureBeyondViewport: false,
|
|
3234
|
-
}),
|
|
3284
|
+
}, { present: false }),
|
|
3235
3285
|
timeoutMs,
|
|
3236
3286
|
undefined,
|
|
3237
3287
|
timeoutMessage,
|
|
@@ -3263,14 +3313,18 @@ export class ElectronBrowserProvider implements BrowserProvider {
|
|
|
3263
3313
|
// can produce JPEG (CDP JPEG hangs on Electron 43).
|
|
3264
3314
|
const capturable = handle
|
|
3265
3315
|
if (request?.fullPage !== true && typeof capturable.capture === 'function') {
|
|
3266
|
-
// Ensure the target view is the visible one before capturing.
|
|
3267
|
-
|
|
3316
|
+
// Ensure the target view is the visible one before capturing — unless quiet mode is on.
|
|
3317
|
+
// There, presenting the view is exactly what the user asked to avoid (it restores and
|
|
3318
|
+
// raises the window); the host switches the visible tab inside the window and, if the
|
|
3319
|
+
// window has no surface to capture, falls through to CDP.
|
|
3320
|
+
if (!this.isQuiet()) this.showActive(s)
|
|
3268
3321
|
const timeoutMs = 30_000
|
|
3269
3322
|
const shot = await withTimeout(
|
|
3270
3323
|
capturable.capture({
|
|
3271
3324
|
...format === 'jpeg' ? { format, quality: request?.quality } : {},
|
|
3272
3325
|
...request?.maxWidth !== undefined ? { maxWidth: request.maxWidth } : {},
|
|
3273
3326
|
...request?.maxHeight !== undefined ? { maxHeight: request.maxHeight } : {},
|
|
3327
|
+
quiet: this.isQuiet(),
|
|
3274
3328
|
}),
|
|
3275
3329
|
timeoutMs,
|
|
3276
3330
|
signal,
|
|
@@ -3744,6 +3798,17 @@ export class ElectronBrowserProvider implements BrowserProvider {
|
|
|
3744
3798
|
if (!reported) process.stderr.write(`[dsh-browser] user action failed: ${message}\n`)
|
|
3745
3799
|
}
|
|
3746
3800
|
|
|
3801
|
+
/**
|
|
3802
|
+
* Whether the operator asked for quiet mode (`ui.quiet`).
|
|
3803
|
+
*
|
|
3804
|
+
* Read live on every call rather than captured at construction: the panel writes the document
|
|
3805
|
+
* and the next operation is expected to honour it, without a restart.
|
|
3806
|
+
* @returns true when the carrier must present views without taking the screen over.
|
|
3807
|
+
*/
|
|
3808
|
+
private isQuiet(): boolean {
|
|
3809
|
+
return this.settingsSource?.().ui.quiet === true
|
|
3810
|
+
}
|
|
3811
|
+
|
|
3747
3812
|
/**
|
|
3748
3813
|
* Ask the host to show the active tab's view, carrying the session label.
|
|
3749
3814
|
*
|
|
@@ -3756,7 +3821,7 @@ export class ElectronBrowserProvider implements BrowserProvider {
|
|
|
3756
3821
|
* silently desynchronising the two and failing every screenshot.
|
|
3757
3822
|
*/
|
|
3758
3823
|
private showActive(s: Session): void {
|
|
3759
|
-
this.host.showView?.(this.activeTab(s).handle, s.label)
|
|
3824
|
+
this.host.showView?.(this.activeTab(s).handle, s.label, { quiet: this.isQuiet() })
|
|
3760
3825
|
const autoExpand = this.settingsSource === undefined || this.settingsSource().ui.autoExpandOnce
|
|
3761
3826
|
if (autoExpand) return
|
|
3762
3827
|
// Best effort: a carrier that owns no presentation (self-hosted) simply has none.
|
|
@@ -35,7 +35,7 @@ import { existsSync, readFileSync, readdirSync, readlinkSync } from 'node:fs'
|
|
|
35
35
|
import { basename, dirname, isAbsolute, join } from 'node:path'
|
|
36
36
|
import { createServer, type Server, type Socket } from 'node:net'
|
|
37
37
|
import { fileURLToPath } from 'node:url'
|
|
38
|
-
import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle, ScreenshotOptions } from './provider.js'
|
|
38
|
+
import type { BrowserUserAction, ElectronBrowserViewHost, ElectronViewHandle, PresentOptions, ScreenshotOptions } from './provider.js'
|
|
39
39
|
import type { ExportedCookie } from '../browser/types.js'
|
|
40
40
|
|
|
41
41
|
/** How long to wait for the child to signal readiness before failing. */
|
|
@@ -139,13 +139,13 @@ function resolveElectronPathImpl(inputs: ElectronPathInputs): string {
|
|
|
139
139
|
if (hostExe !== undefined) return hostExe
|
|
140
140
|
throw new Error(
|
|
141
141
|
'dsh-builtin-browser: cannot locate a spawnable Electron binary. ' +
|
|
142
|
-
'The electron package ships with the plugin
|
|
143
|
-
'
|
|
144
|
-
'
|
|
145
|
-
'
|
|
146
|
-
'
|
|
147
|
-
'
|
|
148
|
-
'
|
|
142
|
+
'The electron package ships with the plugin and its binary is downloaded on first use, not at install time ' +
|
|
143
|
+
'(issue #41: an install-time download made default profiles refuse the plugin). The plugin prepares it ' +
|
|
144
|
+
'automatically when the bundled carrier is selected; to do it by hand, run ' +
|
|
145
|
+
'`npx --no dsh-browser-install-electron` in the profile that installed the plugin, then retry. ' +
|
|
146
|
+
'Alternatively set ELECTRON_PATH to an electron executable. Note: the host\'s own executable cannot be ' +
|
|
147
|
+
'reused when it is a packaged Electron app (e.g. DSH Desktop.exe) — only a real electron binary can be ' +
|
|
148
|
+
'spawned.',
|
|
149
149
|
)
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -1196,13 +1196,19 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
1196
1196
|
return view
|
|
1197
1197
|
}
|
|
1198
1198
|
|
|
1199
|
-
showView(handle: ElectronViewHandle, label?: string): void {
|
|
1199
|
+
showView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): void {
|
|
1200
1200
|
// Fire-and-forget by design (visibility is best-effort), but a rejected
|
|
1201
1201
|
// promise must not become an unhandled rejection (crash on Node >= 15).
|
|
1202
1202
|
// The label (session/task id) rides along so the child can show it in the
|
|
1203
1203
|
// window title — a human can then tell which task's page is visible.
|
|
1204
|
+
// `quiet` is only sent when it is on: the child's default is the documented
|
|
1205
|
+
// "present and raise" behaviour, so an old child keeps working either way.
|
|
1204
1206
|
void this.ready()
|
|
1205
|
-
.then(() => this.client?.call('showView', {
|
|
1207
|
+
.then(() => this.client?.call('showView', {
|
|
1208
|
+
viewId: handle.id,
|
|
1209
|
+
...label !== undefined ? { label } : {},
|
|
1210
|
+
...options?.quiet === true ? { quiet: true } : {},
|
|
1211
|
+
}))
|
|
1206
1212
|
.catch(() => { /* host unavailable */ })
|
|
1207
1213
|
}
|
|
1208
1214
|
|
|
@@ -1221,7 +1227,7 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
1221
1227
|
* in order: its reply is queued behind the showView and so only arrives once
|
|
1222
1228
|
* the visibility change has been applied.
|
|
1223
1229
|
*/
|
|
1224
|
-
async presentView(handle: ElectronViewHandle, label?: string): Promise<void> {
|
|
1230
|
+
async presentView(handle: ElectronViewHandle, label?: string, options?: PresentOptions): Promise<void> {
|
|
1225
1231
|
await this.ready()
|
|
1226
1232
|
const client = this.client
|
|
1227
1233
|
if (client === undefined) throw new HostGoneError('browser host unavailable')
|
|
@@ -1232,7 +1238,15 @@ export class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
|
1232
1238
|
await withTimeout(handle.ensureMaterialized(), PRESENT_TIMEOUT_MS, 'browser host did not materialize the view')
|
|
1233
1239
|
}
|
|
1234
1240
|
await withTimeout(
|
|
1235
|
-
client.call('showView', {
|
|
1241
|
+
client.call('showView', {
|
|
1242
|
+
viewId: handle.id,
|
|
1243
|
+
...label !== undefined ? { label } : {},
|
|
1244
|
+
// `needSurface` tells the child this is the pre-input barrier: under quiet mode this
|
|
1245
|
+
// is the only presentation allowed to un-minimize a window, because Chromium drops
|
|
1246
|
+
// `Input.*` without a display surface. One line below in the child, and only read
|
|
1247
|
+
// there when `quiet` is set.
|
|
1248
|
+
...options?.quiet === true ? { quiet: true, needSurface: true } : {},
|
|
1249
|
+
}),
|
|
1236
1250
|
PRESENT_TIMEOUT_MS,
|
|
1237
1251
|
'browser host did not confirm the view presentation',
|
|
1238
1252
|
)
|
|
@@ -48,6 +48,25 @@ export interface BrowserSettings {
|
|
|
48
48
|
readonly closeWithSession: boolean
|
|
49
49
|
/** Show the synthetic cursor/click feedback while the agent operates. */
|
|
50
50
|
readonly virtualCursor: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Quiet mode: drive the page without taking over the screen.
|
|
53
|
+
*
|
|
54
|
+
* Off (the default) keeps the contract this plugin is built on — human and agent share one
|
|
55
|
+
* window, so an operation raises it and the user can see what is being driven. On, the
|
|
56
|
+
* carrier never activates the application and never steals keyboard focus:
|
|
57
|
+
* - screenshots of a minimized or hidden window go through CDP `Page.captureScreenshot`
|
|
58
|
+
* instead of `capturePage()`, so grabbing an image stops being a reason to show a window;
|
|
59
|
+
* - navigation and tab switching only change which view is visible INSIDE the window; a
|
|
60
|
+
* minimized window stays minimized;
|
|
61
|
+
* - synthesized input still needs a display surface (Chromium drops `Input.*` for a view
|
|
62
|
+
* without one), so that one barrier may restore a minimized window — with
|
|
63
|
+
* `showInactive()`, which shows it without becoming the key window, and without
|
|
64
|
+
* `moveTop()`.
|
|
65
|
+
*
|
|
66
|
+
* Reported as issue #35: a minimized browser window was restored and focused by the next
|
|
67
|
+
* screenshot or click, pulling the user out of whatever they were typing in.
|
|
68
|
+
*/
|
|
69
|
+
readonly quiet: boolean
|
|
51
70
|
}
|
|
52
71
|
/** Visual vs non-visual operation strategy. */
|
|
53
72
|
readonly vision: {
|
|
@@ -111,7 +130,7 @@ export interface BrowserSettings {
|
|
|
111
130
|
export const DEFAULT_SETTINGS: BrowserSettings = {
|
|
112
131
|
history: { enabled: true, maxEntries: 5_000, maxAgeDays: 90 },
|
|
113
132
|
cookies: { persist: true },
|
|
114
|
-
ui: { autoExpandOnce: true, closeWithSession: false, virtualCursor: true },
|
|
133
|
+
ui: { autoExpandOnce: true, closeWithSession: false, virtualCursor: true, quiet: false },
|
|
115
134
|
vision: { strategy: 'auto' },
|
|
116
135
|
// Bundled by default: it needs nothing installed, and on the desktop the carrier
|
|
117
136
|
// is the sidebar anyway. Choosing a system browser is an explicit opt-in because
|
|
@@ -296,6 +315,10 @@ export function resolveSettings(raw: unknown, warn?: (message: string) => void):
|
|
|
296
315
|
autoExpandOnce: bool(ui?.autoExpandOnce, DEFAULT_SETTINGS.ui.autoExpandOnce),
|
|
297
316
|
closeWithSession: bool(ui?.closeWithSession, DEFAULT_SETTINGS.ui.closeWithSession),
|
|
298
317
|
virtualCursor: bool(ui?.virtualCursor, DEFAULT_SETTINGS.ui.virtualCursor),
|
|
318
|
+
// Presentation preference, not a capability gate: a mistyped value keeps the documented
|
|
319
|
+
// default (off) instead of being read as "on", because quiet mode changes how every
|
|
320
|
+
// operation presents itself and should never be the accidental result of a bad edit.
|
|
321
|
+
quiet: bool(ui?.quiet, DEFAULT_SETTINGS.ui.quiet),
|
|
299
322
|
},
|
|
300
323
|
vision: { strategy: vision?.strategy === 'nonVisual' ? 'nonVisual' : DEFAULT_SETTINGS.vision.strategy },
|
|
301
324
|
browser: {
|
|
@@ -87,6 +87,14 @@ declare module 'electron' {
|
|
|
87
87
|
isMinimized(): boolean
|
|
88
88
|
isFocused(): boolean
|
|
89
89
|
show(): void
|
|
90
|
+
/**
|
|
91
|
+
* Show the window without activating the application or taking keyboard focus.
|
|
92
|
+
*
|
|
93
|
+
* Not in the type definitions of older Electron releases, but present since Electron 2 —
|
|
94
|
+
* quiet mode (`ui.quiet`) depends on it to give a view a display surface without stealing
|
|
95
|
+
* the foreground.
|
|
96
|
+
*/
|
|
97
|
+
showInactive(): void
|
|
90
98
|
restore(): void
|
|
91
99
|
focus(): void
|
|
92
100
|
moveTop(): void
|