@jackwener/browsermcp 0.0.42-embedded.0 → 0.0.43
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 +3 -60
- package/README.md +0 -91
- package/dist/docs/api-use.md +2 -0
- package/dist/src/api/api.js +3 -1
- package/dist/src/api/api.js.map +1 -1
- package/dist/src/api/tab.js +70 -0
- package/dist/src/api/tab.js.map +1 -1
- package/dist/src/docs/manifest.js +3 -6
- package/dist/src/docs/manifest.js.map +1 -1
- package/dist/src/mcp/server.js +3 -2
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/runtime/runtime.js +28 -2
- package/dist/src/runtime/runtime.js.map +1 -1
- package/docs/api-use.md +2 -0
- package/package.json +2 -11
- package/dist/src/api/action-input.d.ts +0 -87
- package/dist/src/api/agent.d.ts +0 -10
- package/dist/src/api/api.d.ts +0 -54
- package/dist/src/api/browser.d.ts +0 -93
- package/dist/src/api/commands.d.ts +0 -514
- package/dist/src/api/content-wait.d.ts +0 -18
- package/dist/src/api/context.d.ts +0 -7
- package/dist/src/api/diff.d.ts +0 -8
- package/dist/src/api/errors.d.ts +0 -14
- package/dist/src/api/network.d.ts +0 -10
- package/dist/src/api/observation.d.ts +0 -4
- package/dist/src/api/streams.d.ts +0 -13
- package/dist/src/api/tab.d.ts +0 -352
- package/dist/src/api/webmcp.d.ts +0 -19
- package/dist/src/backends/backend.d.ts +0 -14
- package/dist/src/backends/browser-helpers.d.ts +0 -17
- package/dist/src/backends/extension-page.d.ts +0 -5
- package/dist/src/backends/managed-page.d.ts +0 -50
- package/dist/src/backends/page-transport.d.ts +0 -10
- package/dist/src/backends/page-types.d.ts +0 -82
- package/dist/src/docs/embedded.d.ts +0 -2
- package/dist/src/docs/embedded.js +0 -40
- package/dist/src/docs/embedded.js.map +0 -1
- package/dist/src/docs/manifest.d.ts +0 -23
- package/dist/src/docs/surface.d.ts +0 -12
- package/dist/src/electron/backend.d.ts +0 -50
- package/dist/src/electron/backend.js +0 -377
- package/dist/src/electron/backend.js.map +0 -1
- package/dist/src/electron/chrome.d.ts +0 -24
- package/dist/src/electron/chrome.js +0 -133
- package/dist/src/electron/chrome.js.map +0 -1
- package/dist/src/electron/driver.d.ts +0 -70
- package/dist/src/electron/driver.js +0 -316
- package/dist/src/electron/driver.js.map +0 -1
- package/dist/src/electron/event-buffer.d.ts +0 -16
- package/dist/src/electron/event-buffer.js +0 -59
- package/dist/src/electron/event-buffer.js.map +0 -1
- package/dist/src/electron/page.js +0 -1030
- package/dist/src/electron/registry.d.ts +0 -104
- package/dist/src/electron/registry.js +0 -316
- package/dist/src/electron/registry.js.map +0 -1
- package/dist/src/electron/streams.d.ts +0 -16
- package/dist/src/electron/streams.js +0 -48
- package/dist/src/electron/streams.js.map +0 -1
- package/dist/src/embedded/index.d.ts +0 -49
- package/dist/src/embedded/index.js +0 -85
- package/dist/src/embedded/index.js.map +0 -1
- package/dist/src/host/bridge.d.ts +0 -50
- package/dist/src/host/doctor.d.ts +0 -34
- package/dist/src/host/extension.d.ts +0 -3
- package/dist/src/host/host.d.ts +0 -3
- package/dist/src/host/ipc.d.ts +0 -14
- package/dist/src/host/jsonc-config.d.ts +0 -1
- package/dist/src/host/launch.d.ts +0 -11
- package/dist/src/host/native-messaging.d.ts +0 -28
- package/dist/src/host/opencode.d.ts +0 -6
- package/dist/src/host/pi.d.ts +0 -6
- package/dist/src/host/registration.d.ts +0 -24
- package/dist/src/host/setup.d.ts +0 -7
- package/dist/src/host/socket.d.ts +0 -25
- package/dist/src/host/state.d.ts +0 -39
- package/dist/src/launcher/stdio.d.ts +0 -3
- package/dist/src/lib/paths.d.ts +0 -1
- package/dist/src/lib/sources.d.ts +0 -5
- package/dist/src/main.d.ts +0 -2
- package/dist/src/mcp/catalog.d.ts +0 -202
- package/dist/src/mcp/js-session.d.ts +0 -64
- package/dist/src/mcp/server.d.ts +0 -15
- package/dist/src/protocol.d.ts +0 -340
- package/dist/src/recon/analyzer.d.ts +0 -43
- package/dist/src/recon/discover.d.ts +0 -48
- package/dist/src/runtime/runtime.d.ts +0 -230
- package/dist/src/shared/api-contract.d.ts +0 -86
- package/dist/src/shared/aria-tree.d.ts +0 -2
- package/dist/src/shared/closed-shadow.d.ts +0 -10
- package/dist/src/shared/element-ref.d.ts +0 -4
- package/dist/src/shared/engine.d.ts +0 -62
- package/dist/src/shared/inflight.d.ts +0 -14
- package/dist/src/shared/injected-source.d.ts +0 -2
- package/dist/src/shared/page-contract.d.ts +0 -278
- package/dist/src/sites/define.d.ts +0 -28
- package/dist/src/sites/drafts.d.ts +0 -39
- package/dist/src/sites/executor.d.ts +0 -34
- package/dist/src/sites/loader.d.ts +0 -101
- package/dist/src/sites/manifest.d.ts +0 -5
- package/dist/src/sites/schema.d.ts +0 -11
- package/dist/src/version.d.ts +0 -2
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { WebContents } from 'electron';
|
|
2
|
-
import type { ActSpec, FrameStep, DialogInfo } from '../protocol.js';
|
|
3
|
-
/**
|
|
4
|
-
* CDP stays on the application's registered target; no remote-debugging port is opened.
|
|
5
|
-
*
|
|
6
|
-
* The Runtime domain is never enabled (rebrowser-patches', Patchright's): with it on, a page can
|
|
7
|
-
* tell a debugger is attached (console.debug of an Error whose `stack` getter runs when the
|
|
8
|
-
* inspector serializes it — the most common CDP check). Nothing here needs its events: the
|
|
9
|
-
* engine runs in an isolated world made with Page.createIsolatedWorld (its context id comes back
|
|
10
|
-
* with it, invalidated by Page navigation events and recreated once on a stale-context error),
|
|
11
|
-
* the top frame's main world is Runtime.evaluate's default context, and a child frame's main
|
|
12
|
-
* world is reached through its own target session or, same-process, through its document: read
|
|
13
|
-
* in the engine's world, resolved again by node in the page's own world, and the expression
|
|
14
|
-
* called on that object (rebrowser-patches' default lookup: nothing added to the page).
|
|
15
|
-
*/
|
|
16
|
-
export declare class ElectronDriver {
|
|
17
|
-
readonly contents: WebContents;
|
|
18
|
-
private readonly pageModule;
|
|
19
|
-
private attached;
|
|
20
|
-
private contexts;
|
|
21
|
-
private targets;
|
|
22
|
-
private disposed;
|
|
23
|
-
private readonly network;
|
|
24
|
-
/** Requests an action started, for its settle; the page's own session only (not child targets). */
|
|
25
|
-
private readonly inflight;
|
|
26
|
-
private readonly bodies;
|
|
27
|
-
private capturePattern;
|
|
28
|
-
private initialization?;
|
|
29
|
-
dialogInfo: DialogInfo | null;
|
|
30
|
-
private readonly onMessage;
|
|
31
|
-
private readonly onDetach;
|
|
32
|
-
private readonly debuggerApi;
|
|
33
|
-
constructor(contents: WebContents, pageModule?: string);
|
|
34
|
-
ready(): Promise<void>;
|
|
35
|
-
private initialize;
|
|
36
|
-
send(method: string, params?: Record<string, unknown>, sessionId?: string, timeoutMs?: number): Promise<any>;
|
|
37
|
-
private sessionFor;
|
|
38
|
-
evaluate(expression: string, contextId?: number, frameId?: string, timeoutMs?: number, byValue?: boolean): Promise<unknown>;
|
|
39
|
-
rootFrame(): Promise<string>;
|
|
40
|
-
engineContext(frameId: string): Promise<number>;
|
|
41
|
-
callIn(frameId: string, fn: string, args?: unknown, timeoutMs?: number): Promise<unknown>;
|
|
42
|
-
/**
|
|
43
|
-
* Run in the frame's engine world; a world gone with its document since (no Runtime events
|
|
44
|
-
* to say so: a navigation the Page events haven't reported yet) is made again, once.
|
|
45
|
-
*/
|
|
46
|
-
private inEngine;
|
|
47
|
-
route(frame?: FrameStep | FrameStep[], scroll?: boolean): Promise<{
|
|
48
|
-
frameId: string;
|
|
49
|
-
offset: {
|
|
50
|
-
x: number;
|
|
51
|
-
y: number;
|
|
52
|
-
};
|
|
53
|
-
}>;
|
|
54
|
-
/** Hand the frame's closed shadow roots to its engine world (see src/shared/closed-shadow.ts). */
|
|
55
|
-
exposeClosedShadowRoots(frameId: string): Promise<number>;
|
|
56
|
-
pageCall(fn: string, args?: unknown, timeoutMs?: number, frame?: FrameStep | FrameStep[]): Promise<unknown>;
|
|
57
|
-
/**
|
|
58
|
-
* The page's own world (its globals): the top frame's is Runtime.evaluate's default; a frame
|
|
59
|
-
* in a process of its own, its session's default. A same-process child frame's has no id
|
|
60
|
-
* without Runtime's events, so it is reached through an object living in it: the frame's
|
|
61
|
-
* document, read in the engine's world, resolved by node in the page's world (DOM.resolveNode
|
|
62
|
-
* resolves there by default), and the expression run with Runtime.callFunctionOn on it.
|
|
63
|
-
*/
|
|
64
|
-
evaluateMain(expression: string, frame?: FrameStep | FrameStep[], timeoutMs?: number): Promise<unknown>;
|
|
65
|
-
startCapture(pattern?: string): Promise<void>;
|
|
66
|
-
readCapture(): Promise<unknown[]>;
|
|
67
|
-
frames(): Promise<any>;
|
|
68
|
-
act(spec: ActSpec): Promise<import("../protocol.js").ActResult>;
|
|
69
|
-
dispose(detach?: boolean): void;
|
|
70
|
-
}
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { INJECTED_SOURCE } from '../shared/injected-source.js';
|
|
3
|
-
import { installEngineJs, pageCallJs, unwrapPageResult, PAGE_GLOBAL, frameSteps, performAct } from '../shared/engine.js';
|
|
4
|
-
import { ActionError } from '../api/errors.js';
|
|
5
|
-
import { InflightRequests } from '../shared/inflight.js';
|
|
6
|
-
import { adoptClosedShadowRoots } from '../shared/closed-shadow.js';
|
|
7
|
-
/**
|
|
8
|
-
* CDP stays on the application's registered target; no remote-debugging port is opened.
|
|
9
|
-
*
|
|
10
|
-
* The Runtime domain is never enabled (rebrowser-patches', Patchright's): with it on, a page can
|
|
11
|
-
* tell a debugger is attached (console.debug of an Error whose `stack` getter runs when the
|
|
12
|
-
* inspector serializes it — the most common CDP check). Nothing here needs its events: the
|
|
13
|
-
* engine runs in an isolated world made with Page.createIsolatedWorld (its context id comes back
|
|
14
|
-
* with it, invalidated by Page navigation events and recreated once on a stale-context error),
|
|
15
|
-
* the top frame's main world is Runtime.evaluate's default context, and a child frame's main
|
|
16
|
-
* world is reached through its own target session or, same-process, through its document: read
|
|
17
|
-
* in the engine's world, resolved again by node in the page's own world, and the expression
|
|
18
|
-
* called on that object (rebrowser-patches' default lookup: nothing added to the page).
|
|
19
|
-
*/
|
|
20
|
-
export class ElectronDriver {
|
|
21
|
-
contents;
|
|
22
|
-
pageModule;
|
|
23
|
-
attached = false;
|
|
24
|
-
contexts = new Map();
|
|
25
|
-
targets = new Map();
|
|
26
|
-
disposed = false;
|
|
27
|
-
network = new Map();
|
|
28
|
-
/** Requests an action started, for its settle; the page's own session only (not child targets). */
|
|
29
|
-
inflight = new InflightRequests();
|
|
30
|
-
bodies = new Set();
|
|
31
|
-
capturePattern = '';
|
|
32
|
-
initialization;
|
|
33
|
-
dialogInfo = null;
|
|
34
|
-
onMessage = (_event, method, params, sessionId) => {
|
|
35
|
-
// A new document (or a frame gone) takes its isolated worlds with it.
|
|
36
|
-
if (method === 'Page.frameNavigated' || method === 'Page.frameDetached')
|
|
37
|
-
this.contexts.clear();
|
|
38
|
-
if (method === 'Target.attachedToTarget') {
|
|
39
|
-
this.targets.set(params.targetInfo.targetId, params.sessionId);
|
|
40
|
-
// Its Page events say when its documents change; Runtime stays off there too.
|
|
41
|
-
void this.send('Page.enable', {}, params.sessionId).catch(() => { });
|
|
42
|
-
void this.send('Runtime.runIfWaitingForDebugger', {}, params.sessionId).catch(() => { });
|
|
43
|
-
}
|
|
44
|
-
if (method === 'Target.detachedFromTarget') {
|
|
45
|
-
for (const [id, session] of this.targets)
|
|
46
|
-
if (session === params.sessionId)
|
|
47
|
-
this.targets.delete(id);
|
|
48
|
-
this.contexts.clear();
|
|
49
|
-
}
|
|
50
|
-
if (method.startsWith('Network.') && !sessionId)
|
|
51
|
-
this.inflight.note(method, params);
|
|
52
|
-
if (method === 'Network.requestWillBeSent') {
|
|
53
|
-
const request = params.request;
|
|
54
|
-
if (!this.capturePattern || request.url.includes(this.capturePattern)) {
|
|
55
|
-
this.network.set(params.requestId, { requestId: params.requestId, url: request.url, method: request.method, type: params.type, timestamp: params.timestamp, requestBodyPreview: request.postData?.slice(0, 16000), requestBodyFullSize: request.postData?.length, requestBodyTruncated: Boolean(request.postData && request.postData.length > 16000) });
|
|
56
|
-
while (this.network.size > 500)
|
|
57
|
-
this.network.delete(this.network.keys().next().value);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (method === 'Network.responseReceived') {
|
|
61
|
-
const entry = this.network.get(params.requestId);
|
|
62
|
-
if (entry)
|
|
63
|
-
Object.assign(entry, { status: params.response.status, mimeType: params.response.mimeType });
|
|
64
|
-
}
|
|
65
|
-
if (method === 'Network.loadingFailed') {
|
|
66
|
-
const entry = this.network.get(params.requestId);
|
|
67
|
-
if (entry)
|
|
68
|
-
Object.assign(entry, { finished: true, error: params.errorText });
|
|
69
|
-
}
|
|
70
|
-
if (method === 'Network.loadingFinished') {
|
|
71
|
-
const entry = this.network.get(params.requestId);
|
|
72
|
-
if (entry) {
|
|
73
|
-
const body = (async () => {
|
|
74
|
-
try {
|
|
75
|
-
if (/json|text|javascript|xml/.test(String(entry.mimeType ?? ''))) {
|
|
76
|
-
const result = await this.send('Network.getResponseBody', { requestId: params.requestId }, sessionId);
|
|
77
|
-
const value = result.base64Encoded ? Buffer.from(result.body, 'base64').toString('utf8') : String(result.body);
|
|
78
|
-
Object.assign(entry, { responsePreview: value.slice(0, 64000), responseBodyFullSize: value.length, responseBodyTruncated: value.length > 64000 });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
entry.responseBodyError = String(error);
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
entry.finished = true;
|
|
86
|
-
}
|
|
87
|
-
})();
|
|
88
|
-
this.bodies.add(body);
|
|
89
|
-
void body.finally(() => this.bodies.delete(body));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (method === 'Page.javascriptDialogOpening')
|
|
93
|
-
this.dialogInfo = { type: params.type, message: params.message, defaultPrompt: params.defaultPrompt, url: params.url, openedAt: Date.now() };
|
|
94
|
-
if (method === 'Page.javascriptDialogClosed')
|
|
95
|
-
this.dialogInfo = null;
|
|
96
|
-
};
|
|
97
|
-
onDetach = () => { this.debuggerApi.removeListener('message', this.onMessage); this.debuggerApi.removeListener('detach', this.onDetach); this.attached = false; this.initialization = undefined; this.contexts.clear(); this.targets.clear(); };
|
|
98
|
-
debuggerApi;
|
|
99
|
-
constructor(contents, pageModule = readFileSync(new URL('./page.js', import.meta.url), 'utf8')) {
|
|
100
|
-
this.contents = contents;
|
|
101
|
-
this.pageModule = pageModule;
|
|
102
|
-
// Keep the emitter: accessing contents.debugger after WebContents destruction throws.
|
|
103
|
-
this.debuggerApi = contents.debugger;
|
|
104
|
-
}
|
|
105
|
-
async ready() {
|
|
106
|
-
if (this.disposed || this.contents.isDestroyed())
|
|
107
|
-
throw new ActionError('stale_page', 'Page is no longer available');
|
|
108
|
-
if (!this.initialization)
|
|
109
|
-
this.initialization = this.initialize().catch(error => { this.initialization = undefined; throw error; });
|
|
110
|
-
return this.initialization;
|
|
111
|
-
}
|
|
112
|
-
async initialize() {
|
|
113
|
-
const debuggerApi = this.debuggerApi;
|
|
114
|
-
if (debuggerApi.isAttached())
|
|
115
|
-
throw new ActionError('debugger_in_use', 'The page debugger is already owned by another client');
|
|
116
|
-
debuggerApi.attach('1.3');
|
|
117
|
-
this.attached = true;
|
|
118
|
-
debuggerApi.on('message', this.onMessage);
|
|
119
|
-
debuggerApi.on('detach', this.onDetach);
|
|
120
|
-
try {
|
|
121
|
-
await this.send('Page.enable');
|
|
122
|
-
await this.send('Network.enable');
|
|
123
|
-
await this.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: false, flatten: true });
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
this.dispose();
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async send(method, params = {}, sessionId, timeoutMs = 15000) {
|
|
131
|
-
if (this.disposed || this.contents.isDestroyed() || !this.attached)
|
|
132
|
-
throw new ActionError('stale_page', 'Debugger target is unavailable');
|
|
133
|
-
let timer;
|
|
134
|
-
return Promise.race([
|
|
135
|
-
this.debuggerApi.sendCommand(method, params, sessionId || undefined),
|
|
136
|
-
new Promise((_, reject) => { timer = setTimeout(() => reject(new ActionError('command_outcome_unknown', `${method} timed out; it may have executed`)), timeoutMs); }),
|
|
137
|
-
]).finally(() => clearTimeout(timer));
|
|
138
|
-
}
|
|
139
|
-
sessionFor(frameId) { return this.targets.get(frameId); }
|
|
140
|
-
async evaluate(expression, contextId, frameId, timeoutMs = 15000, byValue = true) {
|
|
141
|
-
await this.ready();
|
|
142
|
-
const result = await this.send('Runtime.evaluate', { expression, ...(contextId !== undefined && { contextId }), awaitPromise: true, returnByValue: byValue, userGesture: true }, frameId ? this.sessionFor(frameId) : undefined, timeoutMs);
|
|
143
|
-
if (result.exceptionDetails)
|
|
144
|
-
throw new ActionError('page_error', result.exceptionDetails.exception?.description ?? result.exceptionDetails.text ?? 'Page evaluation failed');
|
|
145
|
-
return byValue ? result.result.value : result.result.objectId;
|
|
146
|
-
}
|
|
147
|
-
async rootFrame() { await this.ready(); return (await this.send('Page.getFrameTree')).frameTree.frame.id; }
|
|
148
|
-
async engineContext(frameId) {
|
|
149
|
-
const existing = this.contexts.get(frameId);
|
|
150
|
-
if (existing !== undefined)
|
|
151
|
-
return existing;
|
|
152
|
-
const { executionContextId } = await this.send('Page.createIsolatedWorld', { frameId, worldName: 'browsermcp-engine' }, this.sessionFor(frameId));
|
|
153
|
-
await this.evaluate(installEngineJs(INJECTED_SOURCE, this.pageModule), executionContextId, frameId);
|
|
154
|
-
this.contexts.set(frameId, executionContextId);
|
|
155
|
-
return executionContextId;
|
|
156
|
-
}
|
|
157
|
-
async callIn(frameId, fn, args, timeoutMs) {
|
|
158
|
-
return unwrapPageResult(await this.inEngine(frameId, context => this.evaluate(pageCallJs(fn, args), context, frameId, timeoutMs)));
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Run in the frame's engine world; a world gone with its document since (no Runtime events
|
|
162
|
-
* to say so: a navigation the Page events haven't reported yet) is made again, once.
|
|
163
|
-
*/
|
|
164
|
-
async inEngine(frameId, run) {
|
|
165
|
-
try {
|
|
166
|
-
return await run(await this.engineContext(frameId));
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
if (!isStaleContext(error))
|
|
170
|
-
throw error;
|
|
171
|
-
this.contexts.delete(frameId);
|
|
172
|
-
return run(await this.engineContext(frameId));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
async route(frame, scroll = false) {
|
|
176
|
-
let frameId = await this.rootFrame();
|
|
177
|
-
const offset = { x: 0, y: 0 };
|
|
178
|
-
for (const step of frameSteps(frame)) {
|
|
179
|
-
const probe = await this.callIn(frameId, 'frameProbe', { step, scroll });
|
|
180
|
-
if (!probe.found)
|
|
181
|
-
throw new ActionError('frame_not_found', `No iframe matches ${JSON.stringify(step)}`);
|
|
182
|
-
const objectId = await this.inEngine(frameId, context => this.evaluate(`globalThis.${PAGE_GLOBAL}.frameElement()`, context, frameId, 5000, false));
|
|
183
|
-
if (typeof objectId !== 'string')
|
|
184
|
-
throw new ActionError('frame_unreachable', 'Frame owner disappeared');
|
|
185
|
-
const parentSession = this.sessionFor(frameId);
|
|
186
|
-
try {
|
|
187
|
-
const { node } = await this.send('DOM.describeNode', { objectId }, this.sessionFor(frameId));
|
|
188
|
-
if (!node.frameId)
|
|
189
|
-
throw new ActionError('frame_unreachable', 'Frame is not ready');
|
|
190
|
-
offset.x += probe.x;
|
|
191
|
-
offset.y += probe.y;
|
|
192
|
-
frameId = node.frameId;
|
|
193
|
-
}
|
|
194
|
-
finally {
|
|
195
|
-
await this.send('Runtime.releaseObject', { objectId }, parentSession).catch(() => { });
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return { frameId, offset };
|
|
199
|
-
}
|
|
200
|
-
/** Hand the frame's closed shadow roots to its engine world (see src/shared/closed-shadow.ts). */
|
|
201
|
-
exposeClosedShadowRoots(frameId) {
|
|
202
|
-
return adoptClosedShadowRoots({
|
|
203
|
-
evaluateHandle: async (expression) => await this.inEngine(frameId, context => this.evaluate(expression, context, frameId, 5000, false)),
|
|
204
|
-
cdp: (method, params) => this.send(method, params, this.sessionFor(frameId), 5000),
|
|
205
|
-
engineContextId: () => this.engineContext(frameId),
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
async pageCall(fn, args, timeoutMs, frame) {
|
|
209
|
-
const { frameId } = await this.route(frame);
|
|
210
|
-
// Page-module reads (observe, find, read, expect) see controls inside closed shadow roots once they are adopted.
|
|
211
|
-
await this.exposeClosedShadowRoots(frameId);
|
|
212
|
-
return this.callIn(frameId, fn, args, timeoutMs);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* The page's own world (its globals): the top frame's is Runtime.evaluate's default; a frame
|
|
216
|
-
* in a process of its own, its session's default. A same-process child frame's has no id
|
|
217
|
-
* without Runtime's events, so it is reached through an object living in it: the frame's
|
|
218
|
-
* document, read in the engine's world, resolved by node in the page's world (DOM.resolveNode
|
|
219
|
-
* resolves there by default), and the expression run with Runtime.callFunctionOn on it.
|
|
220
|
-
*/
|
|
221
|
-
async evaluateMain(expression, frame, timeoutMs = 15000) {
|
|
222
|
-
if (!frameSteps(frame).length)
|
|
223
|
-
return this.evaluate(expression, undefined, undefined, timeoutMs);
|
|
224
|
-
const { frameId } = await this.route(frame);
|
|
225
|
-
const session = this.sessionFor(frameId);
|
|
226
|
-
if (session)
|
|
227
|
-
return this.evaluate(expression, undefined, frameId, timeoutMs);
|
|
228
|
-
const isolated = await this.inEngine(frameId, context => this.evaluate('document', context, frameId, 5000, false));
|
|
229
|
-
if (typeof isolated !== 'string')
|
|
230
|
-
throw new ActionError('frame_unreachable', 'Frame document is not ready');
|
|
231
|
-
let main;
|
|
232
|
-
try {
|
|
233
|
-
const { node } = await this.send('DOM.describeNode', { objectId: isolated });
|
|
234
|
-
main = (await this.send('DOM.resolveNode', { backendNodeId: node.backendNodeId })).object?.objectId;
|
|
235
|
-
if (!main)
|
|
236
|
-
throw new ActionError('frame_unreachable', 'Frame main world is not ready');
|
|
237
|
-
const result = await this.send('Runtime.callFunctionOn', {
|
|
238
|
-
objectId: main,
|
|
239
|
-
functionDeclaration: `function () { return (0, eval)(${JSON.stringify(expression)}); }`,
|
|
240
|
-
awaitPromise: true, returnByValue: true, userGesture: true,
|
|
241
|
-
}, undefined, timeoutMs);
|
|
242
|
-
if (result.exceptionDetails)
|
|
243
|
-
throw new ActionError('page_error', result.exceptionDetails.exception?.description ?? result.exceptionDetails.text ?? 'Page evaluation failed');
|
|
244
|
-
return result.result.value;
|
|
245
|
-
}
|
|
246
|
-
finally {
|
|
247
|
-
await this.send('Runtime.releaseObject', { objectId: isolated }).catch(() => { });
|
|
248
|
-
if (main)
|
|
249
|
-
await this.send('Runtime.releaseObject', { objectId: main }).catch(() => { });
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
async startCapture(pattern = '') { await this.ready(); this.capturePattern = pattern; }
|
|
253
|
-
async readCapture() {
|
|
254
|
-
await Promise.all([...this.bodies]);
|
|
255
|
-
const entries = [];
|
|
256
|
-
for (const [id, entry] of this.network)
|
|
257
|
-
if (entry.finished) {
|
|
258
|
-
entries.push(entry);
|
|
259
|
-
this.network.delete(id);
|
|
260
|
-
}
|
|
261
|
-
return entries;
|
|
262
|
-
}
|
|
263
|
-
async frames() {
|
|
264
|
-
await this.ready();
|
|
265
|
-
const { frameTree } = await this.send('Page.getFrameTree');
|
|
266
|
-
return (frameTree.childFrames ?? []).map((child, index) => ({ index, frameId: child.frame.id, name: child.frame.name ?? '', url: child.frame.url }));
|
|
267
|
-
}
|
|
268
|
-
async act(spec) {
|
|
269
|
-
const { frameId, offset } = await this.route(spec.target.frame, true);
|
|
270
|
-
await this.exposeClosedShadowRoots(frameId);
|
|
271
|
-
const root = await this.rootFrame();
|
|
272
|
-
return performAct({
|
|
273
|
-
call: (fn, args, timeout) => this.callIn(frameId, fn, args, timeout),
|
|
274
|
-
cdp: (method, params) => this.send(method, params),
|
|
275
|
-
pointOffset: offset,
|
|
276
|
-
network: since => this.inflight.activity(since),
|
|
277
|
-
// A click in a frame often changes the page around it (closes the dialog that holds the frame).
|
|
278
|
-
...(frameId !== root && { callTop: (fn, args, timeout) => this.callIn(root, fn, args, timeout) }),
|
|
279
|
-
setFiles: async (files) => {
|
|
280
|
-
const objectId = await this.inEngine(frameId, context => this.evaluate(`globalThis.${PAGE_GLOBAL}.actionTarget()`, context, frameId, 5000, false));
|
|
281
|
-
try {
|
|
282
|
-
await this.send('DOM.setFileInputFiles', { objectId, files }, this.sessionFor(frameId));
|
|
283
|
-
}
|
|
284
|
-
finally {
|
|
285
|
-
await this.send('Runtime.releaseObject', { objectId }, this.sessionFor(frameId)).catch(() => { });
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
waitForNavigation: async (classifyMs, timeoutMs) => {
|
|
289
|
-
const before = this.contents.getURL();
|
|
290
|
-
await new Promise(resolve => setTimeout(resolve, classifyMs));
|
|
291
|
-
const navigated = this.contents.isLoadingMainFrame() || this.contents.getURL() !== before;
|
|
292
|
-
const deadline = Date.now() + timeoutMs;
|
|
293
|
-
while (!this.contents.isDestroyed() && this.contents.isLoadingMainFrame() && Date.now() < deadline)
|
|
294
|
-
await new Promise(resolve => setTimeout(resolve, 25));
|
|
295
|
-
return { navigated, url: this.contents.isDestroyed() ? undefined : this.contents.getURL() };
|
|
296
|
-
},
|
|
297
|
-
}, spec);
|
|
298
|
-
}
|
|
299
|
-
dispose(detach = true) {
|
|
300
|
-
if (this.disposed)
|
|
301
|
-
return;
|
|
302
|
-
this.disposed = true;
|
|
303
|
-
this.debuggerApi.removeListener('message', this.onMessage);
|
|
304
|
-
this.debuggerApi.removeListener('detach', this.onDetach);
|
|
305
|
-
if (detach && this.attached && !this.contents.isDestroyed() && this.debuggerApi.isAttached())
|
|
306
|
-
this.debuggerApi.detach();
|
|
307
|
-
this.attached = false;
|
|
308
|
-
this.contexts.clear();
|
|
309
|
-
this.targets.clear();
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
/** A context id that no longer names a context (its document went). */
|
|
313
|
-
function isStaleContext(error) {
|
|
314
|
-
return /Cannot find context with specified id|Execution context was destroyed|Cannot find default execution context/i.test(String(error?.message ?? error));
|
|
315
|
-
}
|
|
316
|
-
//# sourceMappingURL=driver.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/electron/driver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAIpE;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,cAAc;IA4DJ;IAAwC;IA3DrD,QAAQ,GAAG,KAAK,CAAC;IACjB,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IACrC,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IACpC,QAAQ,GAAG,KAAK,CAAC;IACR,OAAO,GAAG,IAAI,GAAG,EAAmC,CAAC;IACtE,mGAAmG;IAClF,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAClC,MAAM,GAAG,IAAI,GAAG,EAAiB,CAAC;IAC3C,cAAc,GAAG,EAAE,CAAC;IACpB,cAAc,CAAiB;IACvC,UAAU,GAAsB,IAAI,CAAC;IACpB,SAAS,GAAG,CAAC,MAAe,EAAE,MAAc,EAAE,MAAW,EAAE,SAAkB,EAAE,E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,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;YAC9F,CAAC;SACF,EAAE,IAAI,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,MAAM,GAAG,IAAI;QACnB,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,MAAM,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;YAAE,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACxH,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACrE,CAAC;CACF;AAED,uEAAuE;AACvE,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,8GAA8G,CAAC,IAAI,CAAC,MAAM,CAAE,KAAe,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;AACzK,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { StreamBatch, StreamEntry, StreamReadOptions } from '../protocol.js';
|
|
2
|
-
/** Bounded by both entry count and serialized size, never silently drops history. */
|
|
3
|
-
export declare class EventBuffer {
|
|
4
|
-
private readonly capacity;
|
|
5
|
-
readonly generation: `${string}-${string}-${string}-${string}-${string}`;
|
|
6
|
-
private seq;
|
|
7
|
-
private listeners;
|
|
8
|
-
subscribe(listener: (entry: StreamEntry) => void): () => void;
|
|
9
|
-
private entries;
|
|
10
|
-
private bytes;
|
|
11
|
-
private sizes;
|
|
12
|
-
constructor(capacity?: number);
|
|
13
|
-
cursor(): string;
|
|
14
|
-
push(value: Omit<StreamEntry, 'seq' | 'timestamp'>): void;
|
|
15
|
-
read(opts?: StreamReadOptions): StreamBatch;
|
|
16
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/** Bounded by both entry count and serialized size, never silently drops history. */
|
|
2
|
-
export class EventBuffer {
|
|
3
|
-
capacity;
|
|
4
|
-
generation = crypto.randomUUID();
|
|
5
|
-
seq = 0;
|
|
6
|
-
listeners = new Set();
|
|
7
|
-
subscribe(listener) {
|
|
8
|
-
this.listeners.add(listener);
|
|
9
|
-
return () => { this.listeners.delete(listener); };
|
|
10
|
-
}
|
|
11
|
-
entries = [];
|
|
12
|
-
bytes = 0;
|
|
13
|
-
sizes = [];
|
|
14
|
-
constructor(capacity = 500) {
|
|
15
|
-
this.capacity = capacity;
|
|
16
|
-
}
|
|
17
|
-
cursor() { return `${this.generation}:${this.seq}`; }
|
|
18
|
-
push(value) {
|
|
19
|
-
let entry = { ...value, seq: ++this.seq, timestamp: new Date().toISOString() };
|
|
20
|
-
let size = JSON.stringify(entry).length;
|
|
21
|
-
if (size > 16_000) {
|
|
22
|
-
entry = { seq: entry.seq, timestamp: entry.timestamp, event: entry.event, level: entry.level,
|
|
23
|
-
message: JSON.stringify(value).slice(0, 12_000), truncated: true };
|
|
24
|
-
size = JSON.stringify(entry).length;
|
|
25
|
-
}
|
|
26
|
-
for (const listener of this.listeners)
|
|
27
|
-
listener(entry);
|
|
28
|
-
this.entries.push(entry);
|
|
29
|
-
this.sizes.push(size);
|
|
30
|
-
this.bytes += size;
|
|
31
|
-
while (this.entries.length > this.capacity || this.bytes > 200_000) {
|
|
32
|
-
this.entries.shift();
|
|
33
|
-
this.bytes -= this.sizes.shift();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
read(opts = {}) {
|
|
37
|
-
const match = opts.cursor?.match(/^(.+):(\d+)$/);
|
|
38
|
-
if (opts.cursor && !match)
|
|
39
|
-
throw Object.assign(new Error('Invalid stream cursor'), { code: 'invalid_cursor' });
|
|
40
|
-
const reset = Boolean(match && match[1] !== this.generation);
|
|
41
|
-
const after = match && !reset ? Number(match[2]) : 0;
|
|
42
|
-
if (after > this.seq)
|
|
43
|
-
throw Object.assign(new Error('Stream cursor is ahead of this buffer'), { code: 'invalid_cursor' });
|
|
44
|
-
const first = this.entries[0]?.seq ?? this.seq + 1;
|
|
45
|
-
const dropped = Math.max(0, first - after - 1);
|
|
46
|
-
const limit = opts.limit ?? 100;
|
|
47
|
-
if (!Number.isInteger(limit) || limit < 1 || limit > 500)
|
|
48
|
-
throw Object.assign(new Error('limit must be an integer from 1 to 500'), { code: 'invalid_args' });
|
|
49
|
-
const matching = this.entries.filter(e => e.seq > after &&
|
|
50
|
-
(!opts.levels?.length || opts.levels.includes(e.level ?? '')) &&
|
|
51
|
-
(!opts.filter || JSON.stringify(e).includes(opts.filter)));
|
|
52
|
-
const entries = matching.slice(0, limit);
|
|
53
|
-
const hasMore = matching.length > limit;
|
|
54
|
-
// Advance over filtered-out entries too, so an empty poll still makes progress.
|
|
55
|
-
const sequence = hasMore ? entries.at(-1).seq : this.seq;
|
|
56
|
-
return { entries, cursor: `${this.generation}:${sequence}`, hasMore, dropped, reset };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=event-buffer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-buffer.js","sourceRoot":"","sources":["../../../src/electron/event-buffer.ts"],"names":[],"mappings":"AAEA,qFAAqF;AACrF,MAAM,OAAO,WAAW;IAWO;IAVpB,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,GAAG,GAAG,CAAC,CAAC;IACR,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC5D,SAAS,CA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