dsh-browser-plus 0.0.0-stage → 0.5.0
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 +166 -0
- package/LICENSE +22 -0
- package/NOTICE.md +7 -0
- package/README.en.md +100 -0
- package/README.md +99 -2
- package/assets/dsh-browser-plus-256.png +0 -0
- package/assets/dsh-browser-plus-512.png +0 -0
- package/assets/dsh-browser-plus-small.svg +9 -0
- package/assets/dsh-browser-plus.ico +0 -0
- package/assets/dsh-browser-plus.svg +11 -0
- package/assets/readme-workspace.png +0 -0
- package/cordis.patch.yml +17 -0
- package/docs/MIGRATION.md +48 -0
- package/docs/README.md +22 -0
- package/docs/SOAK-CHECKLIST.md +98 -0
- package/docs/architecture.md +88 -0
- package/docs/tool-reference.md +124 -0
- package/docs/user-guide.md +121 -0
- package/docs/why-browser.md +45 -0
- package/lib/browser/runtime.d.ts +225 -0
- package/lib/browser/runtime.js +302 -0
- package/lib/browser/types.d.ts +668 -0
- package/lib/browser/types.js +18 -0
- package/lib/browser-electron/auth-cookies.d.ts +54 -0
- package/lib/browser-electron/auth-cookies.js +83 -0
- package/lib/browser-electron/chrome-state.d.ts +187 -0
- package/lib/browser-electron/chrome-state.js +12 -0
- package/lib/browser-electron/entry.d.ts +66 -0
- package/lib/browser-electron/entry.js +62 -0
- package/lib/browser-electron/fingerprint.d.ts +29 -0
- package/lib/browser-electron/fingerprint.js +42 -0
- package/lib/browser-electron/host-main.d.ts +18 -0
- package/lib/browser-electron/host-main.js +2494 -0
- package/lib/browser-electron/icon.d.ts +11 -0
- package/lib/browser-electron/icon.js +23 -0
- package/lib/browser-electron/page-chrome.d.ts +21 -0
- package/lib/browser-electron/page-chrome.js +2034 -0
- package/lib/browser-electron/provider.d.ts +709 -0
- package/lib/browser-electron/provider.js +2575 -0
- package/lib/browser-electron/remote-host.d.ts +143 -0
- package/lib/browser-electron/remote-host.js +952 -0
- package/lib/browser-electron/task-summary.d.ts +2 -0
- package/lib/browser-electron/task-summary.js +12 -0
- package/lib/browser-electron/task-thumbnail.d.ts +11 -0
- package/lib/browser-electron/task-thumbnail.js +9 -0
- package/lib/browser-electron/write-guard.d.ts +41 -0
- package/lib/browser-electron/write-guard.js +123 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +14 -0
- package/lib/tool-browser/index.d.ts +31 -0
- package/lib/tool-browser/index.js +1931 -0
- package/package.json +95 -4
- package/screenshots.json +3 -0
- package/scripts/build-icons.mjs +80 -0
- package/scripts/capture-window.ps1 +79 -0
- package/scripts/crop-image.ps1 +20 -0
- package/scripts/smoke-browser-tools.mjs +1968 -0
- package/scripts/smoke-chrome-world.mjs +63 -0
- package/scripts/smoke-electron-host.mjs +50 -0
- package/src/browser/runtime.ts +470 -0
- package/src/browser/types.ts +649 -0
- package/src/browser-electron/auth-cookies.ts +125 -0
- package/src/browser-electron/chrome-state.ts +174 -0
- package/src/browser-electron/entry.ts +115 -0
- package/src/browser-electron/fingerprint.ts +45 -0
- package/src/browser-electron/host-main.ts +2330 -0
- package/src/browser-electron/icon.ts +26 -0
- package/src/browser-electron/page-chrome.ts +2046 -0
- package/src/browser-electron/provider.ts +3088 -0
- package/src/browser-electron/remote-host.ts +1004 -0
- package/src/browser-electron/task-summary.ts +10 -0
- package/src/browser-electron/task-thumbnail.ts +17 -0
- package/src/browser-electron/write-guard.ts +134 -0
- package/src/index.ts +52 -0
- package/src/tool-browser/index.ts +1974 -0
- package/src/types/electron-shim.d.ts +143 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-hosted Electron browser host (parent side): an
|
|
3
|
+
* {@link ElectronBrowserViewHost} implementation that spawns the plugin's own
|
|
4
|
+
* Electron child process (host-main.js) and drives it over line-delimited
|
|
5
|
+
* JSON-RPC on a loopback TCP socket. This is what makes the plugin work on
|
|
6
|
+
* surfaces without a desktop shell's electronViewHost (plain dsh web):
|
|
7
|
+
* installing the plugin is enough — the browser window appears on first use.
|
|
8
|
+
*
|
|
9
|
+
* Protocol (one JSON object per line, both directions):
|
|
10
|
+
* -> { id, op: 'createView' } | { id, op: 'destroyView', viewId } |
|
|
11
|
+
* { id, op: 'showView', viewId } | { id, op: 'command', viewId, method, params }
|
|
12
|
+
* <- { id, ok: true, result? } | { id, ok: false, err }
|
|
13
|
+
*
|
|
14
|
+
* The child is Electron's main process; host-main.js owns the BrowserWindow,
|
|
15
|
+
* WebContentsViews, and webContents.debugger (CDP).
|
|
16
|
+
* @module dsh-browser-plus/browser-electron/remote-host
|
|
17
|
+
*/
|
|
18
|
+
import type { ChromeHostEvent, ElectronBrowserViewHost, ElectronViewHandle } from './provider.ts';
|
|
19
|
+
import type { BrowserTaskInfo, BrowserTaskUpdate } from '../browser/types.ts';
|
|
20
|
+
/**
|
|
21
|
+
* Whether a usable Electron binary can be located right now. Cheap and local:
|
|
22
|
+
* it only probes package metadata and the filesystem (no spawn, no network).
|
|
23
|
+
* Exported with an injectable resolver so the failure branch stays testable
|
|
24
|
+
* without uninstalling Electron.
|
|
25
|
+
* @param resolve - the locator to probe; defaults to {@link resolveElectronPath}.
|
|
26
|
+
*/
|
|
27
|
+
export declare function probeElectronAvailability(resolve?: () => string): boolean;
|
|
28
|
+
/** Select the one Electron version this plugin supports; exported for behavior tests. */
|
|
29
|
+
export declare function selectSupportedElectronPath(candidates: ReadonlyArray<{
|
|
30
|
+
version: string;
|
|
31
|
+
path: string;
|
|
32
|
+
}>): string;
|
|
33
|
+
/**
|
|
34
|
+
* Stable `error.code` for every rejection caused by the Electron child being
|
|
35
|
+
* gone. DeferredRemoteView.withView retries on this code instead of
|
|
36
|
+
* pattern-matching message text: a child can die in several ways — spawn
|
|
37
|
+
* failure, exit, socket close, or a call made after it already died — and each
|
|
38
|
+
* produces a different message.
|
|
39
|
+
*/
|
|
40
|
+
export declare const BROWSER_HOST_DEAD_CODE = "BROWSER_HOST_DEAD";
|
|
41
|
+
/**
|
|
42
|
+
* True when an error means the child is gone and ONE self-heal retry is
|
|
43
|
+
* allowed. The stable code is authoritative; the message check is a legacy
|
|
44
|
+
* backstop for errors raised outside ElectronChildClient (an externally
|
|
45
|
+
* supplied host shim, or an older `Error` that only carries the old text), so
|
|
46
|
+
* the pre-existing "browser host is not running" retry contract keeps working.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isBrowserHostDead(error: unknown): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Self-hosted view host: spawns the plugin's Electron child on first use and
|
|
51
|
+
* keeps it alive until dispose(). Fallback when no desktop shell provides
|
|
52
|
+
* ctx.electronViewHost.
|
|
53
|
+
*/
|
|
54
|
+
export declare class RemoteElectronViewHost implements ElectronBrowserViewHost {
|
|
55
|
+
private readonly hostMainPath;
|
|
56
|
+
private readonly options;
|
|
57
|
+
private client;
|
|
58
|
+
private server;
|
|
59
|
+
private pendingSocket;
|
|
60
|
+
private readonly views;
|
|
61
|
+
private readyPromise;
|
|
62
|
+
private disposed;
|
|
63
|
+
/** Cached local-backend probe; locating Electron walks the filesystem. */
|
|
64
|
+
private availableProbe;
|
|
65
|
+
/** Chrome listener; re-attached to every child this host spawns. */
|
|
66
|
+
private chromeEventListener;
|
|
67
|
+
/**
|
|
68
|
+
* @param hostMainPath - the child entry script.
|
|
69
|
+
* @param options - `chromeWorld: 'isolated'` runs the injected chrome in its
|
|
70
|
+
* own JavaScript world, so visited pages cannot read its state or its
|
|
71
|
+
* binding token. `maskAutomation: false` leaves Electron's own User-Agent
|
|
72
|
+
* alone, and `userAgent` replaces it outright. Defaults to the proven
|
|
73
|
+
* main-world path with the automation fingerprint masked.
|
|
74
|
+
*/
|
|
75
|
+
constructor(hostMainPath: string, options?: {
|
|
76
|
+
readonly chromeWorld?: 'main' | 'isolated';
|
|
77
|
+
readonly userAgent?: string;
|
|
78
|
+
readonly maskAutomation?: boolean;
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Cheap local usability probe, consulted by the provider's `available()`.
|
|
82
|
+
* Without it the provider reports itself usable unconditionally, so a missing
|
|
83
|
+
* Electron binary would surface only on the first browser tool call instead of
|
|
84
|
+
* at provider-selection time.
|
|
85
|
+
*/
|
|
86
|
+
isAvailable(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Forward the child's chrome tab requests to the provider.
|
|
89
|
+
*
|
|
90
|
+
* The child is respawned after a crash, so the listener is kept here and
|
|
91
|
+
* re-attached to each new client rather than handed to one client instance.
|
|
92
|
+
*/
|
|
93
|
+
onChromeEvent(listener: (event: ChromeHostEvent) => void): void;
|
|
94
|
+
/**
|
|
95
|
+
* Validate one child-raised action before it reaches the provider.
|
|
96
|
+
*
|
|
97
|
+
* The child is trusted (it is our own process), but a malformed or truncated
|
|
98
|
+
* line must still not reach the tab model as a half-built request.
|
|
99
|
+
*/
|
|
100
|
+
private dispatchChromeEvent;
|
|
101
|
+
/** Ensure the child is up and ready (lazy on first use; restarts after a crash). */
|
|
102
|
+
private ready;
|
|
103
|
+
private start;
|
|
104
|
+
/** The child died: tear down so the next use starts a fresh child. */
|
|
105
|
+
private onChildExit;
|
|
106
|
+
createView(key?: string, label?: string): ElectronViewHandle;
|
|
107
|
+
private ensureView;
|
|
108
|
+
/**
|
|
109
|
+
* Send a CDP `Input.*` command to the host's chrome frame view.
|
|
110
|
+
*
|
|
111
|
+
* The frame is not a tab, so it has no view handle: this is a direct channel to
|
|
112
|
+
* it, used to drive the toolbar (the click tests, and anything that needs to
|
|
113
|
+
* exercise the chrome the way a human does).
|
|
114
|
+
*/
|
|
115
|
+
chromeInput(method: string, params?: Record<string, unknown>): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Evaluate an expression inside the chrome frame's document and return its value.
|
|
118
|
+
*
|
|
119
|
+
* The frame is not a tab, so nothing that targets the page can read it — without
|
|
120
|
+
* this, the toolbar's own animations could only be inferred from whatever the
|
|
121
|
+
* page's copy of the chrome logged. Used to assert the frame's motion directly.
|
|
122
|
+
*/
|
|
123
|
+
chromeEval(expression: string): Promise<unknown>;
|
|
124
|
+
showView(handle: ElectronViewHandle): void;
|
|
125
|
+
destroyView(handle: ElectronViewHandle): void;
|
|
126
|
+
/** Append one operation to the child's per-view trail. */
|
|
127
|
+
trace(viewId: string, entry: unknown): void;
|
|
128
|
+
/** List browser task keys with labels (legacy RPC name retained for compatibility). */
|
|
129
|
+
listWindows(): Promise<Array<{
|
|
130
|
+
key: string;
|
|
131
|
+
label: string;
|
|
132
|
+
}>>;
|
|
133
|
+
/** List task summaries from the self-hosted visible workspace. */
|
|
134
|
+
listTasks(): Promise<readonly BrowserTaskInfo[]>;
|
|
135
|
+
/** Read one task summary from the self-hosted visible workspace. */
|
|
136
|
+
getTask(key: string): Promise<BrowserTaskInfo | undefined>;
|
|
137
|
+
/** Update one task summary in the self-hosted visible workspace. */
|
|
138
|
+
updateTask(key: string, task: BrowserTaskUpdate): Promise<BrowserTaskInfo | undefined>;
|
|
139
|
+
/** Shut the child and the RPC server down. */
|
|
140
|
+
dispose(): void;
|
|
141
|
+
}
|
|
142
|
+
/** Default host-main path relative to this module's build output. */
|
|
143
|
+
export declare function defaultHostMainPath(): string;
|