dsh-builtin-browser 0.5.3 → 0.5.5

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.
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * WHY
6
6
  * The plugin runs inside the desktop's Node-mode host, where there is no Electron
7
- * API — which is why it self-hosts a whole browser today. The shell, however, can
7
+ * API 鈥?which is why it self-hosts a whole browser today. The shell, however, can
8
8
  * own views, and its sidebar already displays real web pages. This host borrows
9
9
  * that page over the shell's bridge (see apps/desktop/bridge/plugin-browser-bridge.js),
10
10
  * so the agent and the human end up on ONE page instead of two.
@@ -13,7 +13,7 @@
13
13
  * It implements the same `ElectronBrowserViewHost` seam the self-hosted host does,
14
14
  * so the provider, the tools, browsing history, the synthetic cursor and the
15
15
  * teardown rules are all unchanged: only the carrier differs. Everything is
16
- * lazily materialized — a fresh shell has no sidebar guest until something asks
16
+ * lazily materialized 鈥?a fresh shell has no sidebar guest until something asks
17
17
  * for a page, and the bridge creates one on demand.
18
18
  *
19
19
  * FALLBACK
@@ -39,7 +39,7 @@ export function bridgeEndpointPath() {
39
39
  * A display state, not a dead carrier. It must never reach `reportLost`, and it must never be
40
40
  * retried as though a guest had vanished: retrying cannot attach a webview the shell has not
41
41
  * rendered, and treating it as loss swapped the surface to a fresh self-hosted window whose page was
42
- * blank — losing the page the user had open.
42
+ * blank 鈥?losing the page the user had open.
43
43
  */
44
44
  const PANEL_NOT_DISPLAYED = 'panel-not-displayed';
45
45
  /**
@@ -58,8 +58,8 @@ const PANEL_DISPLAY_RETRY_MS = 400;
58
58
  *
59
59
  * Thrown instead of a plain Error so callers can distinguish "the panel did not render" from "the
60
60
  * browser broke", which is exactly the distinction issue #37 says was missing. The plugin no longer
61
- * waits for a human to show the conversation — the client half asks the shell to (`openSession`) and
62
- * this host retries while it renders — so reaching here means the shell did not render it at all.
61
+ * waits for a human to show the conversation 鈥?the client half asks the shell to (`openSession`) and
62
+ * this host retries while it renders 鈥?so reaching here means the shell did not render it at all.
63
63
  */
64
64
  export class BrowserPanelNotDisplayedError extends Error {
65
65
  code = PANEL_NOT_DISPLAYED;
@@ -67,7 +67,7 @@ export class BrowserPanelNotDisplayedError extends Error {
67
67
  * @param detail - the bridge's own explanation, appended so the message says why.
68
68
  */
69
69
  constructor(detail) {
70
- super('dsh-builtin-browser: this conversation\'s sidebar page did not attach — the shell was asked to '
70
+ super('dsh-builtin-browser: this conversation\'s sidebar page did not attach 鈥?the shell was asked to '
71
71
  + 'show this conversation and its panel still did not render. Nothing was lost, and the page '
72
72
  + 'appears as soon as the panel mounts. '
73
73
  + `(${detail})`);
@@ -87,7 +87,7 @@ function isGuestGone(error) {
87
87
  return false;
88
88
  const message = error instanceof Error ? error.message : String(error);
89
89
  // The panel path reports its own failure when the renderer never produced a page, and that is the
90
- // same class as a vanished guest — worth one retry on a fresh panel — so it is listed here too.
90
+ // same class as a vanished guest 鈥?worth one retry on a fresh panel 鈥?so it is listed here too.
91
91
  return /guest \d+ is not available|sidebar unavailable|produced no page/i.test(message);
92
92
  }
93
93
  /**
@@ -95,7 +95,7 @@ function isGuestGone(error) {
95
95
  *
96
96
  * One sidebar exists per shell window, so every view this host hands out refers
97
97
  * to the same guest: the provider keeps its tab bookkeeping, and the tabs simply
98
- * share the visible page. That is the intended behaviour for this carrier — the
98
+ * share the visible page. That is the intended behaviour for this carrier 鈥?the
99
99
  * point is a single page both parties can see.
100
100
  */
101
101
  export class DesktopBridgeViewHost {
@@ -104,7 +104,7 @@ export class DesktopBridgeViewHost {
104
104
  * One entry per view this host handed out: the conversation it serves, and the guest backing it.
105
105
  *
106
106
  * The conversation belongs to the ENTRY, not to this host. A single plugin process serves every
107
- * conversation — DSH runs them all through one host instance — so an owner held on the host
107
+ * conversation 鈥?DSH runs them all through one host instance 鈥?so an owner held on the host
108
108
  * would be one conversation's id applied to all of them, and a page could still land in
109
109
  * another's sidebar however carefully the bridge checked it.
110
110
  */
@@ -114,7 +114,7 @@ export class DesktopBridgeViewHost {
114
114
  *
115
115
  * Every DSH session is its own plugin process, and the sidebar is one surface they all share.
116
116
  * A session can only see its own `views` map, so before the bridge kept a ledger it adopted
117
- * whichever tab it found — including one another session had opened, which is how a URL from
117
+ * whichever tab it found 鈥?including one another session had opened, which is how a URL from
118
118
  * one session appeared in another's sidebar. The id is per process, so two sessions never
119
119
  * collide and one session's tabs are never handed to another; it is deliberately not the DSH
120
120
  * session id, which this layer has no access to and does not need.
@@ -122,17 +122,17 @@ export class DesktopBridgeViewHost {
122
122
  * The whole ledger rests on that premise, so it was measured rather than assumed: with two
123
123
  * sessions running, the desktop had TWO host processes (plus one main, two renderers and a
124
124
  * gpu/utility pair). If sessions ever shared a process, every owner check in the bridge would
125
- * compare equal and the bleed would return in a new shape — so a change to how DSH spawns
125
+ * compare equal and the bleed would return in a new shape 鈥?so a change to how DSH spawns
126
126
  * sessions invalidates this file, not just this comment.
127
127
  *
128
128
  * It is now the CONVERSATION id rather than an invented uuid, read from the plugin's ctx by the
129
129
  * same path DSH's own desktop host uses. That matters because the shell keeps one sidebar per
130
130
  * conversation and writes its session id onto each sidebar container (on the React fiber,
131
- * measured on the running app) — so the bridge can only answer "is this sidebar mine" if it has
131
+ * measured on the running app) 鈥?so the bridge can only answer "is this sidebar mine" if it has
132
132
  * a comparable id. With an invented uuid it never could, which is how a command came to be typed
133
133
  * into another conversation's address bar.
134
134
  *
135
- * Falls back to a random uuid when the host cannot supply one — an older DSH, or a non-desktop
135
+ * Falls back to a random uuid when the host cannot supply one 鈥?an older DSH, or a non-desktop
136
136
  * composition. That is no worse than before: the bridge then knows only "this process", and it
137
137
  * refuses to operate on a sidebar it cannot prove is its own.
138
138
  */
@@ -142,8 +142,8 @@ export class DesktopBridgeViewHost {
142
142
  * conversation each belongs to.
143
143
  *
144
144
  * The provider destroys its view handles before it asks for a release, so the mapping is dropped
145
- * by then — keeping the guest ids here is what lets us close only our own tabs when several
146
- * conversations are running (requirements §4: each session gets its own page). The owner rides
145
+ * by then 鈥?keeping the guest ids here is what lets us close only our own tabs when several
146
+ * conversations are running (requirements 搂4: each session gets its own page). The owner rides
147
147
  * along for the same reason it does in {@link views}: a release names one conversation.
148
148
  */
149
149
  orphaned = new Map();
@@ -155,7 +155,7 @@ export class DesktopBridgeViewHost {
155
155
  * handler is stored anyway so the interface contract holds (a caller may register
156
156
  * one and must not be surprised) and so a future bridge operation can deliver it
157
157
  * without changing the provider. Consequently no user-action event is emitted while
158
- * the desktop sidebar is the carrier — by design, not by omission.
158
+ * the desktop sidebar is the carrier 鈥?by design, not by omission.
159
159
  */
160
160
  userActionHandler;
161
161
  /** Told when the shell behind this bridge exits; see `onLost`. */
@@ -219,7 +219,7 @@ export class DesktopBridgeViewHost {
219
219
  //
220
220
  // The sidebar browser renders as a <webview> only where the shell exposes
221
221
  // `dshDesktop.browser` and enables `webviewTag`. Where it renders as an <iframe> there is
222
- // no webContents, no `getWebContentsId()` and no CDP endpoint — and every tool here is
222
+ // no webContents, no `getWebContentsId()` and no CDP endpoint 鈥?and every tool here is
223
223
  // built on CDP, so adopting it means failing every call, with no path back to a carrier
224
224
  // that works. Reported on DSH Desktop 2.0.17 with both conditions measured.
225
225
  //
@@ -264,8 +264,8 @@ export class DesktopBridgeViewHost {
264
264
  * Every page this conversation's sidebar panel currently holds.
265
265
  *
266
266
  * The shell owns page creation inside the panel: a link the user or the agent clicks may open a
267
- * new page, and nothing tells the provider. Those pages are real — they are what the human sees
268
- * — but without this the tab model reports only the ones the provider created, so the rest are
267
+ * new page, and nothing tells the provider. Those pages are real 鈥?they are what the human sees
268
+ * 鈥?but without this the tab model reports only the ones the provider created, so the rest are
269
269
  * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
270
270
  *
271
271
  * The bridge's `list` already answers with the sidebar guests, which is the same information, so
@@ -276,14 +276,14 @@ export class DesktopBridgeViewHost {
276
276
  * Every sidebar page this conversation holds that THIS HOST did not open.
277
277
  *
278
278
  * The shell owns page creation inside the panel: a link the user or the agent clicks may open a
279
- * new page, and nothing tells the provider. Those pages are real — they are what the human sees
280
- * — but without this the tab model reports only the ones the provider created, so the rest are
279
+ * new page, and nothing tells the provider. Those pages are real 鈥?they are what the human sees
280
+ * 鈥?but without this the tab model reports only the ones the provider created, so the rest are
281
281
  * invisible to `dsh_browser_list_tabs` and unclosable through `dsh_browser_close_tab`.
282
282
  *
283
283
  * Pages this host opened are EXCLUDED here rather than deduplicated by the caller, because the
284
284
  * caller cannot do it: the provider knows a tab by its own id and the carrier knows a page by the
285
285
  * guest id, and the two never match. The first version returned everything and relied on the
286
- * caller to filter, which reported the same page twice — the mapping that makes the match
286
+ * caller to filter, which reported the same page twice 鈥?the mapping that makes the match
287
287
  * possible exists only here.
288
288
  * @returns the panel's pages that are not ours, or an empty list when the bridge cannot answer.
289
289
  */
@@ -308,7 +308,7 @@ export class DesktopBridgeViewHost {
308
308
  /**
309
309
  * Close one sidebar page by the id {@link listPages} reported.
310
310
  *
311
- * The bridge closes sidebar pages by TITLE, and only the ones the caller owns — that is what
311
+ * The bridge closes sidebar pages by TITLE, and only the ones the caller owns 鈥?that is what
312
312
  * stopped one conversation's teardown from destroying another's page. So the title is looked up
313
313
  * through the same listing, and a page that no longer appears is treated as already gone rather
314
314
  * than as an error: the caller asked for it to be closed, and it is.
@@ -326,8 +326,8 @@ export class DesktopBridgeViewHost {
326
326
  /**
327
327
  * The guest backing a view, materialized on first use.
328
328
  *
329
- * The conversation that called owns exactly one sidebar page on this carrier — a human and the
330
- * agent look at the same page — so every view resolves to that conversation's own guest, and the
329
+ * The conversation that called owns exactly one sidebar page on this carrier 鈥?a human and the
330
+ * agent look at the same page 鈥?so every view resolves to that conversation's own guest, and the
331
331
  * page does not multiply behind the provider's own tab bookkeeping.
332
332
  *
333
333
  * A cached guest is used as-is: probing it first cost a round-trip on every command, so liveness
@@ -335,14 +335,14 @@ export class DesktopBridgeViewHost {
335
335
  * @param viewId - the view whose guest is wanted.
336
336
  * @param url - address to use when this conversation has no page yet.
337
337
  */
338
- async guestFor(viewId, url) {
338
+ async guestFor(viewId, url, options) {
339
339
  const entry = this.views.get(viewId);
340
340
  // No liveness check here: verifying the cached guest cost a round-trip on every
341
341
  // command. A guest that has gone away is detected by the command itself failing,
342
342
  // and `createView`'s sendCommand then discards the cache and calls back in here.
343
343
  if (entry?.guest !== undefined)
344
344
  return entry.guest;
345
- // The conversation THIS VIEW serves — read from the view, never from the process.
345
+ // The conversation THIS VIEW serves 鈥?read from the view, never from the process.
346
346
  //
347
347
  // The difference is the whole bug. This host is one instance shared by every conversation, so
348
348
  // `this.owner` alone can only be "whichever conversation this process happens to name", and
@@ -354,6 +354,33 @@ export class DesktopBridgeViewHost {
354
354
  // conversation's own panel by id through the renderer, rather than by pressing the shell's
355
355
  // shortcut or clicking its card, both of which the shell delivers to whatever it displays.
356
356
  const owner = entry?.owner ?? this.owner;
357
+ // A command that must not present anything (issue #46: the live preview) takes a read-only path.
358
+ // It asks the bridge what this conversation ALREADY has and never enters the retry loop below 鈥? // that loop is what asks the shell to display the conversation, which is right for a tool call
359
+ // and wrong for "let me look at it". A page that is not on screen therefore reports as a display
360
+ // state, and the preview route turns that into the panel's paused state.
361
+ if (options?.present === false) {
362
+ // `list` and NOT `ensureSidebar`. This is deliberate and it is the whole fix: every version of
363
+ // `ensureSidebar` can drive the shell — the current one asks the renderer to display the
364
+ // conversation, and the pre-#37 one literally pressed the sidebar shortcut and typed into the
365
+ // address bar. `list` is a pure read on every version, so a preview cannot move anything even
366
+ // when the installed bridge is old (which is exactly the reporter's environment: the symptom
367
+ // appears only once a bridge is installed).
368
+ const listed = await this.connection.call({ op: 'list', owner }, 8_000);
369
+ const pages = Array.isArray(listed.sidebar)
370
+ ? listed.sidebar.filter(page => page !== null && typeof page === 'object' && page.type === 'webview')
371
+ : [];
372
+ const wanted = url !== undefined && url !== '' ? url : undefined;
373
+ const match = wanted === undefined
374
+ ? pages[0]
375
+ : pages.find(page => typeof page.url === 'string' && (page.url === wanted || page.url.startsWith(wanted))) ?? pages[0];
376
+ const id = match !== undefined ? Number(match.id) : Number.NaN;
377
+ if (!Number.isFinite(id) || id <= 0) {
378
+ throw new BrowserPanelNotDisplayedError('the preview asked for this conversation\'s page without presenting it, and no page is attached '
379
+ + `(the shell holds ${pages.length})`);
380
+ }
381
+ this.views.set(viewId, { guest: id, owner });
382
+ return id;
383
+ }
357
384
  const ask = () => this.connection.call({
358
385
  op: 'ensureSidebar',
359
386
  owner,
@@ -366,13 +393,13 @@ export class DesktopBridgeViewHost {
366
393
  // panel-not-displayed - the conversation exists but is not the one on screen;
367
394
  // "is not mounted" - its surface store was not minted when the tab was placed.
368
395
  // Both are gone one render later. Measured, this is the whole difference between "the sidebar
369
- // works once I click over to that conversation" and "it works" — the page is real either way,
396
+ // works once I click over to that conversation" and "it works" 鈥?the page is real either way,
370
397
  // and failing the call while the shell is already switching away from it just reported a
371
398
  // problem the plugin had already fixed.
372
399
  const displayRefusal = (value) => value.ok !== true
373
400
  && (String(value.code ?? '') === PANEL_NOT_DISPLAYED
374
401
  || String(value.error ?? '').includes('not mounted')
375
- // Bridges installed before issue #37 send the same refusal with NO code — the installed copy
402
+ // Bridges installed before issue #37 send the same refusal with NO code 鈥?the installed copy
376
403
  // on this machine is one of them (`panel-not-displayed` appears nowhere in it). Reading only
377
404
  // the code therefore turned a retryable display state into a hard failure for exactly the
378
405
  // users who had the old bridge, which is the majority until it is reinstalled. The wording
@@ -383,7 +410,7 @@ export class DesktopBridgeViewHost {
383
410
  answer = await ask();
384
411
  }
385
412
  if (answer.ok !== true) {
386
- // Reachable only after the retries above have run out, and the code still decides — not the
413
+ // Reachable only after the retries above have run out, and the code still decides 鈥?not the
387
414
  // wording:
388
415
  // panel-not-displayed -> the shell was asked to show the conversation (client half's
389
416
  // `openSession`) and did not render it in ~1.6 s: no loss, no swap.
@@ -421,13 +448,13 @@ export class DesktopBridgeViewHost {
421
448
  };
422
449
  return {
423
450
  id: viewId,
424
- sendCommand: async (method, params) => {
451
+ sendCommand: async (method, params, options) => {
425
452
  // No liveness probe up front. Checking first cost a whole round-trip on
426
453
  // every command; instead the command runs and its failure is what triggers
427
454
  // recovery. Only a genuinely missing guest is retried, so a real error (a
428
455
  // bad selector, a timeout) still surfaces unchanged.
429
456
  const url = navigateUrl(method, params);
430
- let guest = await this.guestFor(viewId, url);
457
+ let guest = await this.guestFor(viewId, url, options);
431
458
  try {
432
459
  return await run(guest, method, params);
433
460
  }
@@ -442,7 +469,7 @@ export class DesktopBridgeViewHost {
442
469
  const lost = this.views.get(viewId);
443
470
  if (lost !== undefined)
444
471
  delete lost.guest;
445
- guest = await this.guestFor(viewId, url);
472
+ guest = await this.guestFor(viewId, url, options);
446
473
  return await run(guest, method, params);
447
474
  }
448
475
  },
@@ -465,8 +492,8 @@ export class DesktopBridgeViewHost {
465
492
  * This used to be empty, on the reasoning that the sidebar is already on screen so there is
466
493
  * nothing to show. That confused "the sidebar is visible" with "this page is the one being
467
494
  * looked at": opening a page left it behind whatever the human had in front, which is issue
468
- * #23. The other two carriers both do this — the self-hosted window re-adds the view and the
469
- * system browser calls `Page.bringToFront` — so this carrier was the odd one out.
495
+ * #23. The other two carriers both do this 鈥?the self-hosted window re-adds the view and the
496
+ * system browser calls `Page.bringToFront` 鈥?so this carrier was the odd one out.
470
497
  *
471
498
  * Best-effort by design: the tab strip belongs to the shell's renderer, and failing to raise
472
499
  * it must not fail the navigation that has already happened.
@@ -474,7 +501,7 @@ export class DesktopBridgeViewHost {
474
501
  */
475
502
  showView(handle) {
476
503
  // `owner` is required: the bridge refuses to bring forward a guest held by another session.
477
- // It comes from the view, not the process — with several conversations live, a process-wide
504
+ // It comes from the view, not the process 鈥?with several conversations live, a process-wide
478
505
  // owner would raise the wrong conversation's tab.
479
506
  const owner = this.views.get(handle.id)?.owner ?? this.owner;
480
507
  const guest = this.views.get(handle.id)?.guest;
@@ -488,11 +515,11 @@ export class DesktopBridgeViewHost {
488
515
  this.userActionHandler = handler;
489
516
  }
490
517
  /**
491
- * Release the sidebar's browser pages (requirements §3, `ui.closeWithSession`).
518
+ * Release the sidebar's browser pages (requirements 搂3, `ui.closeWithSession`).
492
519
  *
493
520
  * Destroying our own view handles is not enough on this carrier: the sidebar
494
521
  * belongs to the shell and would happily keep the page (and its renderer) alive.
495
- * Closing the tabs is what actually ends the page — and only the page: cookies
522
+ * Closing the tabs is what actually ends the page 鈥?and only the page: cookies
496
523
  * live in the partition, history on disk, so both survive.
497
524
  * @param owner - the conversation whose pages to close. Omit to close every conversation's,
498
525
  * which is only correct from a teardown that is itself global.
@@ -500,7 +527,7 @@ export class DesktopBridgeViewHost {
500
527
  */
501
528
  async releasePage(owner) {
502
529
  // Only this conversation's tabs. The host is ONE instance shared by every conversation, so a
503
- // release that named none would close pages other conversations are still driving — "every
530
+ // release that named none would close pages other conversations are still driving 鈥?"every
504
531
  // webview currently visible" is precisely what must never be used here.
505
532
  const mine = [];
506
533
  for (const [viewId, entry] of [...this.views]) {
@@ -526,7 +553,7 @@ export class DesktopBridgeViewHost {
526
553
  // `owner` is REQUIRED here now that the bridge filters `list` by it. Without it the bridge
527
554
  // falls back to a different owner, so the guests this session holds are filtered out of the
528
555
  // answer, `mine.includes(...)` matches nothing, the title list comes back empty and this
529
- // returns without closing anything — the page stayed open and the human had to close it by
556
+ // returns without closing anything 鈥?the page stayed open and the human had to close it by
530
557
  // hand. Adding the ledger to the bridge without updating this call site is exactly the kind
531
558
  // of half-change that made the ownership work take four rounds.
532
559
  const answer = await this.connection.call({ op: 'list', owner: owner ?? this.owner }, 5_000);
@@ -121,8 +121,16 @@ export async function ensureElectronRuntime(deps = defaultDeps()) {
121
121
  return { status: 'failed', detail: 'the installed electron package has no install.js; reinstall the plugin in this profile' };
122
122
  }
123
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;
124
132
  const timeout = new Promise(resolve => {
125
- setTimeout(() => resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` }), deps.timeoutMs).unref?.();
133
+ timer = setTimeout(() => resolve({ code: null, detail: `gave up after ${Math.round(deps.timeoutMs / 1000)}s` }), deps.timeoutMs);
126
134
  });
127
135
  let outcome;
128
136
  try {
@@ -131,6 +139,10 @@ export async function ensureElectronRuntime(deps = defaultDeps()) {
131
139
  catch (error) {
132
140
  return { status: 'failed', detail: `the download failed: ${String(error)}` };
133
141
  }
142
+ finally {
143
+ if (timer !== undefined)
144
+ clearTimeout(timer);
145
+ }
134
146
  if (outcome.code !== 0) {
135
147
  return {
136
148
  status: 'failed',
@@ -246,7 +246,7 @@ export interface ElectronViewHandle {
246
246
  * @param params - CDP command parameters.
247
247
  * @returns the CDP `result` object.
248
248
  */
249
- sendCommand(method: string, params?: Record<string, unknown>): Promise<Record<string, unknown>>;
249
+ sendCommand(method: string, params?: Record<string, unknown>, options?: CommandOptions): Promise<Record<string, unknown>>;
250
250
  /**
251
251
  * Whether this view's CDP can encode JPEG and honour a quality setting.
252
252
  *
@@ -436,6 +436,23 @@ export declare function toCdpCookie(cookie: ExportedCookie): Record<string, unkn
436
436
  export interface PresentOptions {
437
437
  readonly quiet?: boolean;
438
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
+ }
439
456
  /** Native capture options the self-hosted view handle understands. */
440
457
  export interface ScreenshotOptions {
441
458
  readonly format?: 'png' | 'jpeg';
@@ -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');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-builtin-browser",
3
- "version": "0.5.3",
4
- "description": "Shared real browser plugin for DeepSeek Harness: install-and-use 鈥?a visible native browser the human can take over, driven by the agent over CDP. DOM-level interaction (React/Vue safe), per-task session isolation, cookie persistence (dsh_browser_auth), CAPTCHA detection, batch form fill (dsh_browser_fill), authenticated download, history/replay, action restriction",
3
+ "version": "0.5.5",
4
+ "description": "Shared real browser plugin for DeepSeek Harness: install-and-use 閳?a visible native browser the human can take over, driven by the agent over CDP. DOM-level interaction (React/Vue safe), per-task session isolation, cookie persistence (dsh_browser_auth), CAPTCHA detection, batch form fill (dsh_browser_fill), authenticated download, history/replay, action restriction",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
20
20
  import { join } from 'node:path'
21
+ import { fileURLToPath } from 'node:url'
21
22
 
22
23
  import { readDesktopIdentity } from './desktop-identity.js'
23
24
 
@@ -78,6 +79,28 @@ export interface BridgeStatus {
78
79
  readonly command?: string
79
80
  }
80
81
 
82
+ /**
83
+ * The installer script inside THIS plugin package.
84
+ *
85
+ * Reported as issue #40, fourth item: the panel told users to run
86
+ * `node desktop-bridge/install.mjs "<root>" --restart`, which assumes the reader is standing in a
87
+ * source checkout. Anyone who installed the plugin from npm or the market has no such relative path —
88
+ * the file lives inside the installed package, and there is nowhere sensible for them to run the
89
+ * command from. Resolving it from this module's own location is the difference between a hint and an
90
+ * instruction that works.
91
+ * @returns the absolute path, or undefined when the package layout is unexpected.
92
+ */
93
+ function installerScriptPath(): string | undefined {
94
+ try {
95
+ // lib/browser-electron/bridge-status.js → <package>/desktop-bridge/install.mjs
96
+ const url = new URL('../../desktop-bridge/install.mjs', import.meta.url)
97
+ const path = fileURLToPath(url)
98
+ return safeExists(path) ? path : undefined
99
+ } catch {
100
+ return undefined
101
+ }
102
+ }
103
+
81
104
  /**
82
105
  * The command a user should run for this state, quoted so it survives a path with spaces.
83
106
  * @param installRoot - the install directory, or undefined when none was found.
@@ -85,7 +108,11 @@ export interface BridgeStatus {
85
108
  */
86
109
  function repairCommand(installRoot: string | undefined): string | undefined {
87
110
  if (installRoot === undefined) return undefined
88
- return `node desktop-bridge/install.mjs "${installRoot}" --restart`
111
+ const script = installerScriptPath()
112
+ // No absolute path means the package is laid out in a way this module cannot navigate; the bare
113
+ // relative form is still better than nothing, but it is the fallback, not the default.
114
+ const runner = script === undefined ? 'desktop-bridge/install.mjs' : `"${script}"`
115
+ return `node ${runner} "${installRoot}" --restart`
89
116
  }
90
117
 
91
118
  /**