@linxin666/dsh-client-ui-browser-view 0.4.15 → 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.i18n.yaml +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/index.js +80 -29
- package/lib/types/core/cdp.d.ts +29 -5
- package/lib/types/host/service.d.ts +48 -2
- package/package.json +1 -1
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: d8996bcd1fb7dd16b00592b909fc9806c353a70e
|
|
6
|
+
README.zh.md: a0ef21137f0ab8e7afd799cfac7c412083f2e05c
|
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ Sign in to the sites the agent should see inside that profile once; the plugin d
|
|
|
84
84
|
- **Your sign-ins stay in your browser**: the plugin reads pages, not the cookie jar; nothing is copied out of the attached profile into the plugin, the isolated profile or disk.
|
|
85
85
|
- **Every DSH session sees every tab**: while CDP mode is on, every session on this host can enumerate, read, navigate, click and type in every tab of the attached browser, including tabs opened after it attached. The mode grants that to the host, not to one session.
|
|
86
86
|
- **Headless by default**: in isolated mode nothing pops up on the desktop; the tab is the only view.
|
|
87
|
-
- **Process lifetime**: a Chromium the plugin launched is killed when the plugin disposes; disposing or changing configuration only detaches from an external browser and closes neither the browser nor any of its tabs.
|
|
87
|
+
- **Process lifetime**: a Chromium the plugin launched is killed when the plugin disposes; disposing or changing configuration only detaches from an external browser and closes neither the browser nor any of its tabs. A session whose CDP socket has closed is dropped on its next call and detached the same way — it never closes an external browser or its tabs — then reconnected to the configured endpoint; a reconnect that fails is reported as the connection error, and the configured source is never swapped for another one.
|
|
88
88
|
- **Failure is an error, not a downgrade**: an endpoint that does not answer fails the tool call with the connection error, and the plugin never falls back to the isolated browser, so the panel cannot show a browser other than the configured one.
|
|
89
89
|
- **Token handling**: the launch token is minted per navigation, held in memory, and never written to disk; the retry only happens on a loopback target whose document is DSH's own challenge, so no other local service is ever handed the token.
|
|
90
90
|
|
|
@@ -93,7 +93,7 @@ Sign in to the sites the agent should see inside that profile once; the plugin d
|
|
|
93
93
|
- The tab is a **view**. Input comes from the agent through the tools; it does not forward your mouse or keyboard.
|
|
94
94
|
- CDP mode lists every tab the browser has, including tabs that have nothing to do with this workspace; the panel does not filter or hide them.
|
|
95
95
|
- Chrome 136 and later ignore `--remote-debugging-port` for the default data directory, so the default Chrome profile cannot be attached this way: use a profile explicitly started with a non-default `--user-data-dir` ([Changes to remote debugging switches](https://developer.chrome.com/blog/remote-debugging-port)).
|
|
96
|
-
- A browser that was launched without the debug port, or that has since exited, produces a connection error on the tool call; the plugin starts
|
|
96
|
+
- A browser that was launched without the debug port, or that has since exited, produces a connection error on the tool call. The retry on the next call reconnects only to the configured endpoint; the plugin never starts a real browser in its place.
|
|
97
97
|
- The tab lives inside the right sidebar, so it needs that column; a layout that hides the column hides the tab.
|
|
98
98
|
- Frames are produced when the page changes, so a static page holds the last frame instead of streaming duplicates.
|
|
99
99
|
- Switching chips keeps the body mounted (`keepMounted`), so the socket survives; the frame still waits for the next change.
|
package/README.zh.md
CHANGED
|
@@ -84,7 +84,7 @@ agent 工具调用 ──► 宿主半区 ──► CDP ──► 它自己的 C
|
|
|
84
84
|
- **登录态留在你自己的浏览器里**:插件读的是页面,不是 cookie 罐;被接管 profile 里的任何东西都不会被复制进插件、隔离 profile 或磁盘。
|
|
85
85
|
- **每个 DSH 会话都能看到每个标签页**:接管模式开着的时候,本机每个会话都能枚举、读取、导航、点击与输入被接管浏览器的每个标签页,包括接管之后新开的那些。这份权力是给这台主机的,不是给某一个会话的。
|
|
86
86
|
- **默认无头**:隔离模式下桌面上不会弹出窗口,标签页是唯一的可见视图。
|
|
87
|
-
- **进程寿命**:插件自己拉起的 Chromium 在插件卸载时被杀掉;插件卸载或配置变更只从外部浏览器分离,不关闭浏览器,也不关闭它的任何标签页。
|
|
87
|
+
- **进程寿命**:插件自己拉起的 Chromium 在插件卸载时被杀掉;插件卸载或配置变更只从外部浏览器分离,不关闭浏览器,也不关闭它的任何标签页。CDP socket 已关闭的会话在下一次调用时被丢弃、按同样方式分离——绝不关闭外部浏览器或其标签页——再重新连接到所配置的端点;重连失败按连接错误上报,所配置的来源绝不会被换成另一个。
|
|
88
88
|
- **失败是报错,不是降级**:端点没有应答时工具调用以连接错误失败,插件绝不回退到隔离浏览器,因此面板不会显示出所配置之外的那个浏览器。
|
|
89
89
|
- **令牌处理**:启动令牌每次导航现取、只在内存里,从不落盘;补票只发生在 loopback 目标且文档确实是 DSH 自己的鉴权页时,因此令牌不会被交给别的本地服务。
|
|
90
90
|
|
|
@@ -93,7 +93,7 @@ agent 工具调用 ──► 宿主半区 ──► CDP ──► 它自己的 C
|
|
|
93
93
|
- 标签页只是**视图**。输入来自 agent 的工具调用,不转发你的鼠标与键盘。
|
|
94
94
|
- 接管模式列出浏览器现有的每一个标签页,包括与当前工作区毫无关系的那些;面板不过滤也不隐藏它们。
|
|
95
95
|
- Chrome 136 及以后对默认数据目录忽略 `--remote-debugging-port`,因此默认 Chrome profile 无法这样接管:要使用显式以非默认 `--user-data-dir` 启动的 profile([Changes to remote debugging switches](https://developer.chrome.com/blog/remote-debugging-port))。
|
|
96
|
-
-
|
|
96
|
+
- 没有用调试端口启动的浏览器,或已经退出的浏览器,会在工具调用上报连接错误。下一次调用的重试只重新连接所配置的端点;插件绝不替它启动真实浏览器。
|
|
97
97
|
- 标签页住在右侧栏里,因此需要那一栏存在;布局把栏收起来时它也一起不可见。
|
|
98
98
|
- 帧在页面变化时才产生,静态页面停留在最后一帧,而不是重复推流。
|
|
99
99
|
- 切换 chip 时内容保持挂载(`keepMounted`),socket 不会断;画面仍等下一次变化。
|
package/lib/index.js
CHANGED
|
@@ -46,14 +46,14 @@ var CdpError = class extends Error {
|
|
|
46
46
|
*/
|
|
47
47
|
var CdpClient = class CdpClient {
|
|
48
48
|
socket;
|
|
49
|
-
|
|
49
|
+
commandTimeoutMs;
|
|
50
50
|
pending = /* @__PURE__ */ new Map();
|
|
51
51
|
listeners = /* @__PURE__ */ new Map();
|
|
52
52
|
nextId = 1;
|
|
53
53
|
closedReason;
|
|
54
|
-
constructor(socket,
|
|
54
|
+
constructor(socket, commandTimeoutMs) {
|
|
55
55
|
this.socket = socket;
|
|
56
|
-
this.
|
|
56
|
+
this.commandTimeoutMs = commandTimeoutMs;
|
|
57
57
|
socket.on("message", (data) => {
|
|
58
58
|
this.handleMessage(data);
|
|
59
59
|
});
|
|
@@ -67,13 +67,13 @@ var CdpClient = class CdpClient {
|
|
|
67
67
|
/**
|
|
68
68
|
* Open a client against an already-discovered DevTools endpoint.
|
|
69
69
|
* @param url - `webSocketDebuggerUrl` from `/json/version`.
|
|
70
|
-
* @param options - command
|
|
70
|
+
* @param options - handshake and per-command deadlines, independently.
|
|
71
71
|
* @returns a connected client.
|
|
72
72
|
* @throws CdpError when the socket cannot be established in time.
|
|
73
73
|
*/
|
|
74
74
|
static async connect(url, options = {}) {
|
|
75
|
-
const
|
|
76
|
-
const socket = new WebSocket$1(url, { handshakeTimeout:
|
|
75
|
+
const commandTimeoutMs = options.commandTimeoutMs ?? 3e4;
|
|
76
|
+
const socket = new WebSocket$1(url, { handshakeTimeout: options.handshakeTimeoutMs ?? 3e4 });
|
|
77
77
|
await new Promise((resolve, reject) => {
|
|
78
78
|
const cleanup = () => {
|
|
79
79
|
socket.off("open", onOpen);
|
|
@@ -90,7 +90,11 @@ var CdpClient = class CdpClient {
|
|
|
90
90
|
socket.once("open", onOpen);
|
|
91
91
|
socket.once("error", onError);
|
|
92
92
|
});
|
|
93
|
-
return new CdpClient(socket,
|
|
93
|
+
return new CdpClient(socket, commandTimeoutMs);
|
|
94
|
+
}
|
|
95
|
+
/** Whether the socket is gone and every later command will be refused. */
|
|
96
|
+
get closed() {
|
|
97
|
+
return this.closedReason !== void 0;
|
|
94
98
|
}
|
|
95
99
|
/**
|
|
96
100
|
* Address one protocol command.
|
|
@@ -111,8 +115,8 @@ var CdpClient = class CdpClient {
|
|
|
111
115
|
return new Promise((resolve, reject) => {
|
|
112
116
|
const timer = setTimeout(() => {
|
|
113
117
|
this.pending.delete(id);
|
|
114
|
-
reject(new CdpError(method, -1, `timed out after ${this.
|
|
115
|
-
}, this.
|
|
118
|
+
reject(new CdpError(method, -1, `timed out after ${this.commandTimeoutMs} ms`));
|
|
119
|
+
}, this.commandTimeoutMs);
|
|
116
120
|
this.pending.set(id, {
|
|
117
121
|
method,
|
|
118
122
|
timer,
|
|
@@ -2096,14 +2100,21 @@ async function openIsolatedSession(options) {
|
|
|
2096
2100
|
}
|
|
2097
2101
|
};
|
|
2098
2102
|
}
|
|
2103
|
+
/**
|
|
2104
|
+
* Handshake deadline for an external browser. Its debugger port is already
|
|
2105
|
+
* listening, so an endpoint that does not complete the upgrade within this
|
|
2106
|
+
* window is wedged; the per-command budget is a separate setting and is left at
|
|
2107
|
+
* `CDP_COMMAND_TIMEOUT_MS`, exactly as in the isolated mode.
|
|
2108
|
+
*/
|
|
2109
|
+
const REAL_BROWSER_HANDSHAKE_TIMEOUT_MS = 5e3;
|
|
2099
2110
|
/** Connect to an existing real browser without owning its process or tabs. */
|
|
2100
|
-
async function openExternalSession(options) {
|
|
2111
|
+
async function openExternalSession(options, seams = {}) {
|
|
2101
2112
|
const endpoint = parseCdpEndpoint(options.cdpEndpoint ?? "");
|
|
2113
|
+
const connect = seams.connect ?? CdpClient.connect;
|
|
2102
2114
|
let cdp;
|
|
2103
2115
|
let tabs;
|
|
2104
2116
|
try {
|
|
2105
|
-
|
|
2106
|
-
cdp = await CdpClient.connect(version.webSocketDebuggerUrl, { timeoutMs: 5e3 });
|
|
2117
|
+
cdp = await connect((await fetchCdpVersion(endpoint)).webSocketDebuggerUrl, { handshakeTimeoutMs: REAL_BROWSER_HANDSHAKE_TIMEOUT_MS });
|
|
2107
2118
|
tabs = new TabManager({
|
|
2108
2119
|
transport: cdp,
|
|
2109
2120
|
jpegQuality: options.jpegQuality,
|
|
@@ -2308,7 +2319,7 @@ var BrowserViewService = class {
|
|
|
2308
2319
|
*/
|
|
2309
2320
|
async closeOwnTabs(sessionId, tabId) {
|
|
2310
2321
|
if (sessionId === void 0) throw new Error("browser_close needs the calling session: with no session there is no tab this call may close");
|
|
2311
|
-
if (this.session === void 0) {
|
|
2322
|
+
if (this.session === void 0 || this.session.transport.closed) {
|
|
2312
2323
|
if (tabId === void 0 || tabId === "" || this.resolveConfig().mode !== "cdp") return [];
|
|
2313
2324
|
await this.requireSession();
|
|
2314
2325
|
}
|
|
@@ -2653,7 +2664,7 @@ var BrowserViewService = class {
|
|
|
2653
2664
|
}
|
|
2654
2665
|
/** Open tabs, for `browser_tabs`. */
|
|
2655
2666
|
async listTabs() {
|
|
2656
|
-
if (this.session === void 0) {
|
|
2667
|
+
if (this.session === void 0 || this.session.transport.closed) {
|
|
2657
2668
|
if (this.resolveConfig().mode !== "cdp") return {
|
|
2658
2669
|
tabs: [],
|
|
2659
2670
|
activeTabId: null
|
|
@@ -2682,13 +2693,8 @@ var BrowserViewService = class {
|
|
|
2682
2693
|
async reconfigure() {
|
|
2683
2694
|
if (this.disposed) return;
|
|
2684
2695
|
this.generation += 1;
|
|
2685
|
-
const session = this.session;
|
|
2686
|
-
this.session = void 0;
|
|
2687
2696
|
this.opening = void 0;
|
|
2688
|
-
this.
|
|
2689
|
-
this.authTopUpSpent.clear();
|
|
2690
|
-
this.displayedTabId = null;
|
|
2691
|
-
this.selectionPinned = false;
|
|
2697
|
+
const session = this.forgetSession();
|
|
2692
2698
|
this.lastError = void 0;
|
|
2693
2699
|
if (session !== void 0) await session.dispose();
|
|
2694
2700
|
this.broadcast({
|
|
@@ -2713,11 +2719,7 @@ var BrowserViewService = class {
|
|
|
2713
2719
|
for (const sink of sinks) try {
|
|
2714
2720
|
sink.close();
|
|
2715
2721
|
} catch {}
|
|
2716
|
-
const session = this.
|
|
2717
|
-
this.session = void 0;
|
|
2718
|
-
this.bindings.clear();
|
|
2719
|
-
this.displayedTabId = null;
|
|
2720
|
-
this.selectionPinned = false;
|
|
2722
|
+
const session = this.forgetSession();
|
|
2721
2723
|
if (session !== void 0) await session.dispose();
|
|
2722
2724
|
}
|
|
2723
2725
|
/** The action helpers' collaborator view: one transport, one tab manager. */
|
|
@@ -2737,11 +2739,37 @@ var BrowserViewService = class {
|
|
|
2737
2739
|
async requireTabs() {
|
|
2738
2740
|
return (await this.requireSession()).tabs;
|
|
2739
2741
|
}
|
|
2740
|
-
/**
|
|
2742
|
+
/**
|
|
2743
|
+
* Forget everything bound to the current session without disposing it: the
|
|
2744
|
+
* per-session tab bindings, the watched tab, the pinned selection and the
|
|
2745
|
+
* spent auth tickets all describe a browser that is going away.
|
|
2746
|
+
* @returns the session that was dropped, if any.
|
|
2747
|
+
*/
|
|
2748
|
+
forgetSession() {
|
|
2749
|
+
const session = this.session;
|
|
2750
|
+
this.session = void 0;
|
|
2751
|
+
this.bindings.clear();
|
|
2752
|
+
this.authTopUpSpent.clear();
|
|
2753
|
+
this.displayedTabId = null;
|
|
2754
|
+
this.selectionPinned = false;
|
|
2755
|
+
return session;
|
|
2756
|
+
}
|
|
2757
|
+
/**
|
|
2758
|
+
* Resolve the live session, starting the browser on first use.
|
|
2759
|
+
*
|
|
2760
|
+
* A session whose transport has closed is dead even though its record still
|
|
2761
|
+
* exists: the external browser restarted, crashed, or dropped the socket, and
|
|
2762
|
+
* every command would reject with that one stale reason for the rest of the
|
|
2763
|
+
* host's life. The next call therefore drops it exactly the way a settings
|
|
2764
|
+
* change does and opens a replacement, so the caller recovers instead of
|
|
2765
|
+
* needing a reconfigure or a restart. The replacement goes through `opening`,
|
|
2766
|
+
* so concurrent callers share one session instead of opening two.
|
|
2767
|
+
*/
|
|
2741
2768
|
async requireSession() {
|
|
2742
2769
|
if (this.disposed) throw new Error("the browser view service is disposed");
|
|
2743
|
-
|
|
2744
|
-
if (
|
|
2770
|
+
const current = this.session;
|
|
2771
|
+
if (current !== void 0 && !current.transport.closed) return current;
|
|
2772
|
+
if (this.opening === void 0) this.opening = this.replaceSession(current);
|
|
2745
2773
|
const opening = this.opening;
|
|
2746
2774
|
try {
|
|
2747
2775
|
return await opening;
|
|
@@ -2749,6 +2777,29 @@ var BrowserViewService = class {
|
|
|
2749
2777
|
if (this.opening === opening) this.opening = void 0;
|
|
2750
2778
|
}
|
|
2751
2779
|
}
|
|
2780
|
+
/**
|
|
2781
|
+
* Drop a closed session and open its replacement.
|
|
2782
|
+
*
|
|
2783
|
+
* The cleanup is the settings-change cleanup: an external browser is only
|
|
2784
|
+
* detached, never closed, and its tabs stay open. A teardown that throws is
|
|
2785
|
+
* swallowed because the dead session has nothing left to deliver — its
|
|
2786
|
+
* failure must not be the reason no replacement starts.
|
|
2787
|
+
* @param stale - the dead session, or undefined for an ordinary first start.
|
|
2788
|
+
* @returns the live session.
|
|
2789
|
+
*/
|
|
2790
|
+
async replaceSession(stale) {
|
|
2791
|
+
if (stale === void 0) return await this.startSession();
|
|
2792
|
+
if (this.session === stale) this.forgetSession();
|
|
2793
|
+
await stale.dispose().catch(() => void 0);
|
|
2794
|
+
this.broadcast({
|
|
2795
|
+
v: 1,
|
|
2796
|
+
kind: "state",
|
|
2797
|
+
state: this.state()
|
|
2798
|
+
});
|
|
2799
|
+
const session = await this.startSession();
|
|
2800
|
+
if (this.sinks.size > 0) this.startStreaming().catch(() => void 0);
|
|
2801
|
+
return session;
|
|
2802
|
+
}
|
|
2752
2803
|
/** Start the browser once, recording failures for the panel. */
|
|
2753
2804
|
async startSession() {
|
|
2754
2805
|
const generation = this.generation;
|
|
@@ -2800,7 +2851,7 @@ var BrowserViewService = class {
|
|
|
2800
2851
|
}
|
|
2801
2852
|
/** Start the screencast for the tab the panel watches. */
|
|
2802
2853
|
async startStreaming() {
|
|
2803
|
-
const session = this.session ?? (this.resolveConfig().mode === "cdp" && this.sinks.size > 0 ? await this.requireSession() : void 0);
|
|
2854
|
+
const session = (this.session !== void 0 && !this.session.transport.closed ? this.session : void 0) ?? (this.resolveConfig().mode === "cdp" && this.sinks.size > 0 ? await this.requireSession() : void 0);
|
|
2804
2855
|
if (session === void 0 || this.sinks.size === 0) return;
|
|
2805
2856
|
const tabId = this.displayedOrDefault();
|
|
2806
2857
|
if (tabId === null) return;
|
package/lib/types/core/cdp.d.ts
CHANGED
|
@@ -43,19 +43,43 @@ export interface CdpTransport {
|
|
|
43
43
|
* @returns the unsubscribe function.
|
|
44
44
|
*/
|
|
45
45
|
on(method: string, handler: CdpEventListener): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the transport can still carry commands. False once the socket is
|
|
48
|
+
* gone — a peer that closed, a failed write, or {@link close} — because every
|
|
49
|
+
* later command would reject with the same stale reason.
|
|
50
|
+
*/
|
|
51
|
+
readonly closed: boolean;
|
|
46
52
|
/** Drop the socket; every pending round-trip rejects. */
|
|
47
53
|
close(): void;
|
|
48
54
|
}
|
|
49
55
|
/** One protocol event delivery. */
|
|
50
56
|
export type CdpEventListener = (params: Record<string, unknown>, sessionId: string | undefined) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Default deadline for opening the DevTools socket. A freshly launched browser
|
|
59
|
+
* answers at once, so this only bounds a wedged endpoint; an external browser
|
|
60
|
+
* is reached over a network path the caller controls and sets its own.
|
|
61
|
+
*/
|
|
62
|
+
export declare const CDP_HANDSHAKE_TIMEOUT_MS = 30000;
|
|
51
63
|
/** Default per-command deadline; long enough for a navigation, short enough to fail a wedged tab. */
|
|
52
64
|
export declare const CDP_COMMAND_TIMEOUT_MS = 30000;
|
|
65
|
+
/**
|
|
66
|
+
* Deadlines for one connection. They bound different phases and are therefore
|
|
67
|
+
* separate knobs: opening the socket is bounded once, while every command gets
|
|
68
|
+
* the command budget, so a caller may wait seconds for a browser to answer
|
|
69
|
+
* without shortening the time a navigation is allowed to take.
|
|
70
|
+
*/
|
|
71
|
+
export interface CdpConnectOptions {
|
|
72
|
+
/** Deadline for the WebSocket handshake. @default CDP_HANDSHAKE_TIMEOUT_MS */
|
|
73
|
+
handshakeTimeoutMs?: number;
|
|
74
|
+
/** Deadline for each protocol command. @default CDP_COMMAND_TIMEOUT_MS */
|
|
75
|
+
commandTimeoutMs?: number;
|
|
76
|
+
}
|
|
53
77
|
/**
|
|
54
78
|
* A single WebSocket carrying browser-level and flat-session protocol traffic.
|
|
55
79
|
*/
|
|
56
80
|
export declare class CdpClient implements CdpTransport {
|
|
57
81
|
private readonly socket;
|
|
58
|
-
private readonly
|
|
82
|
+
private readonly commandTimeoutMs;
|
|
59
83
|
private readonly pending;
|
|
60
84
|
private readonly listeners;
|
|
61
85
|
private nextId;
|
|
@@ -64,13 +88,13 @@ export declare class CdpClient implements CdpTransport {
|
|
|
64
88
|
/**
|
|
65
89
|
* Open a client against an already-discovered DevTools endpoint.
|
|
66
90
|
* @param url - `webSocketDebuggerUrl` from `/json/version`.
|
|
67
|
-
* @param options - command
|
|
91
|
+
* @param options - handshake and per-command deadlines, independently.
|
|
68
92
|
* @returns a connected client.
|
|
69
93
|
* @throws CdpError when the socket cannot be established in time.
|
|
70
94
|
*/
|
|
71
|
-
static connect(url: string, options?:
|
|
72
|
-
|
|
73
|
-
|
|
95
|
+
static connect(url: string, options?: CdpConnectOptions): Promise<CdpClient>;
|
|
96
|
+
/** Whether the socket is gone and every later command will be refused. */
|
|
97
|
+
get closed(): boolean;
|
|
74
98
|
/**
|
|
75
99
|
* Address one protocol command.
|
|
76
100
|
* @param method - CDP method.
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*
|
|
20
20
|
* @module @linxin666/dsh-client-ui-browser-view/host/service
|
|
21
21
|
*/
|
|
22
|
-
import type { CdpTransport } from '../core/cdp.ts';
|
|
22
|
+
import type { CdpConnectOptions, CdpTransport } from '../core/cdp.ts';
|
|
23
23
|
import { ChromeProcess } from '../core/chrome.ts';
|
|
24
24
|
import { TabManager, type ScreencastFrame } from '../core/tabs.ts';
|
|
25
25
|
import { type ScreenshotPlan, type ScreenshotRequest } from '../core/screenshot.ts';
|
|
@@ -100,6 +100,24 @@ export interface BrowserViewServiceOptions {
|
|
|
100
100
|
/** Browser factory, replaced by tests. */
|
|
101
101
|
openSession?: (options: OpenSessionOptions) => Promise<BrowserSession>;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Handshake deadline for an external browser. Its debugger port is already
|
|
105
|
+
* listening, so an endpoint that does not complete the upgrade within this
|
|
106
|
+
* window is wedged; the per-command budget is a separate setting and is left at
|
|
107
|
+
* `CDP_COMMAND_TIMEOUT_MS`, exactly as in the isolated mode.
|
|
108
|
+
*/
|
|
109
|
+
export declare const REAL_BROWSER_HANDSHAKE_TIMEOUT_MS = 5000;
|
|
110
|
+
/**
|
|
111
|
+
* Seams the external session factory resolves when it connects. The defaults
|
|
112
|
+
* are the production transport; a test injects one to observe what a
|
|
113
|
+
* real-browser attach asks for without starting a browser.
|
|
114
|
+
*/
|
|
115
|
+
export interface ExternalSessionSeams {
|
|
116
|
+
/** Open the DevTools transport. @default CdpClient.connect */
|
|
117
|
+
connect?: (url: string, timeouts: CdpConnectOptions) => Promise<CdpTransport>;
|
|
118
|
+
}
|
|
119
|
+
/** Connect to an existing real browser without owning its process or tabs. */
|
|
120
|
+
export declare function openExternalSession(options: OpenSessionOptions, seams?: ExternalSessionSeams): Promise<BrowserSession>;
|
|
103
121
|
/**
|
|
104
122
|
* The plugin's single browser service.
|
|
105
123
|
*/
|
|
@@ -384,8 +402,36 @@ export declare class BrowserViewService implements BrowserViewBackend {
|
|
|
384
402
|
private transport;
|
|
385
403
|
/** Resolve the live session or start one. */
|
|
386
404
|
private requireTabs;
|
|
387
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* Forget everything bound to the current session without disposing it: the
|
|
407
|
+
* per-session tab bindings, the watched tab, the pinned selection and the
|
|
408
|
+
* spent auth tickets all describe a browser that is going away.
|
|
409
|
+
* @returns the session that was dropped, if any.
|
|
410
|
+
*/
|
|
411
|
+
private forgetSession;
|
|
412
|
+
/**
|
|
413
|
+
* Resolve the live session, starting the browser on first use.
|
|
414
|
+
*
|
|
415
|
+
* A session whose transport has closed is dead even though its record still
|
|
416
|
+
* exists: the external browser restarted, crashed, or dropped the socket, and
|
|
417
|
+
* every command would reject with that one stale reason for the rest of the
|
|
418
|
+
* host's life. The next call therefore drops it exactly the way a settings
|
|
419
|
+
* change does and opens a replacement, so the caller recovers instead of
|
|
420
|
+
* needing a reconfigure or a restart. The replacement goes through `opening`,
|
|
421
|
+
* so concurrent callers share one session instead of opening two.
|
|
422
|
+
*/
|
|
388
423
|
private requireSession;
|
|
424
|
+
/**
|
|
425
|
+
* Drop a closed session and open its replacement.
|
|
426
|
+
*
|
|
427
|
+
* The cleanup is the settings-change cleanup: an external browser is only
|
|
428
|
+
* detached, never closed, and its tabs stay open. A teardown that throws is
|
|
429
|
+
* swallowed because the dead session has nothing left to deliver — its
|
|
430
|
+
* failure must not be the reason no replacement starts.
|
|
431
|
+
* @param stale - the dead session, or undefined for an ordinary first start.
|
|
432
|
+
* @returns the live session.
|
|
433
|
+
*/
|
|
434
|
+
private replaceSession;
|
|
389
435
|
/** Start the browser once, recording failures for the panel. */
|
|
390
436
|
private startSession;
|
|
391
437
|
/** Start the screencast for the tab the panel watches. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-client-ui-browser-view",
|
|
3
3
|
"description": "Right-docked live browser view for the DSH Web GUI: a CDP-driven Chromium the agent operates, a screencast panel the user watches, and screenshots attached to every tool result.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.16",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|