@howaboua/pi-durable-browser 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/NOTICE +52 -0
- package/README.md +86 -2
- package/dist/activation.d.ts +9 -0
- package/dist/activation.js +3759 -0
- package/dist/browser/artifact-store.d.ts +16 -0
- package/dist/browser/artifacts.d.ts +20 -0
- package/dist/browser/bounds.d.ts +4 -0
- package/dist/browser/config-store.d.ts +11 -0
- package/dist/browser/config.d.ts +7 -0
- package/dist/browser/help.d.ts +1 -0
- package/dist/browser/launcher.d.ts +1 -0
- package/dist/browser/operation-executor.d.ts +12 -0
- package/dist/browser/operation-input.d.ts +10 -0
- package/dist/browser/operation.d.ts +115 -0
- package/dist/browser/parse-operation.d.ts +6 -0
- package/dist/browser/parse-tab-operation.d.ts +3 -0
- package/dist/browser/remote-helper.d.ts +3 -0
- package/dist/browser/remote-process.d.ts +6 -0
- package/dist/browser/remote.d.ts +4 -0
- package/dist/browser/request.d.ts +8 -0
- package/dist/browser/routes.d.ts +15 -0
- package/dist/browser/runtime.d.ts +35 -0
- package/dist/browser/voice-start.d.ts +17 -0
- package/dist/browser/worker-client.d.ts +1 -0
- package/dist/browser/worker-server.d.ts +1 -0
- package/dist/browser/worker-socket.d.ts +11 -0
- package/dist/cdp/accessibility-snapshot.d.ts +11 -0
- package/dist/cdp/actions/click.d.ts +6 -0
- package/dist/cdp/actions/element.d.ts +22 -0
- package/dist/cdp/actions/fill.d.ts +8 -0
- package/dist/cdp/actions/key.d.ts +20 -0
- package/dist/cdp/actions/page.d.ts +7 -0
- package/dist/cdp/actions/screenshot.d.ts +14 -0
- package/dist/cdp/actions/selector.d.ts +2 -0
- package/dist/cdp/actions/type.d.ts +3 -0
- package/dist/cdp/actions/wait.d.ts +9 -0
- package/dist/cdp/client.d.ts +20 -0
- package/dist/cdp/discovery.d.ts +7 -0
- package/dist/cdp/evaluate.d.ts +3 -0
- package/dist/cdp/pages.d.ts +4 -0
- package/dist/cdp/serial.d.ts +1 -0
- package/dist/cdp/session.d.ts +27 -0
- package/dist/cdp/snapshot-contract.d.ts +38 -0
- package/dist/cdp/snapshot.d.ts +3 -0
- package/dist/cdp/tab-bridge.d.ts +26 -0
- package/dist/cdp/tabs.d.ts +32 -0
- package/dist/cdp/types.d.ts +22 -0
- package/dist/cdp/url.d.ts +1 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.js +3951 -0
- package/dist/presentation.d.ts +43 -0
- package/dist/presentation.js +82 -0
- package/dist/remote-worker.d.ts +2 -0
- package/dist/remote-worker.js +3850 -0
- package/package.json +67 -5
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ExecutionEnv } from "@earendil-works/pi-durable/env";
|
|
3
|
+
/** Artifact names are generated internally, never caller-supplied paths. */
|
|
4
|
+
export interface BrowserArtifactStore {
|
|
5
|
+
path(name: string): string;
|
|
6
|
+
write(name: string, data: string | Uint8Array): Promise<void>;
|
|
7
|
+
read(name: string): Promise<string>;
|
|
8
|
+
remove(name: string): Promise<void>;
|
|
9
|
+
entries(): Promise<readonly {
|
|
10
|
+
name: string;
|
|
11
|
+
mtimeMs: number;
|
|
12
|
+
}[]>;
|
|
13
|
+
}
|
|
14
|
+
export declare function nodeArtifactStore(directory: string): BrowserArtifactStore;
|
|
15
|
+
/** The invoking environment owns every model-visible file. No Node fallback. */
|
|
16
|
+
export declare function environmentArtifactStore(env: ExecutionEnv, directory: string, context: Context): Promise<BrowserArtifactStore>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BrowserArtifactStore } from "./artifact-store.ts";
|
|
2
|
+
export declare class BrowserArtifacts {
|
|
3
|
+
readonly store: BrowserArtifactStore;
|
|
4
|
+
constructor(store: BrowserArtifactStore);
|
|
5
|
+
screenshotTarget(request: {
|
|
6
|
+
ref_id: string;
|
|
7
|
+
id?: number | undefined;
|
|
8
|
+
selector?: string | undefined;
|
|
9
|
+
}): {
|
|
10
|
+
file: string;
|
|
11
|
+
write: (data: Uint8Array) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
prune(now?: number): Promise<number>;
|
|
14
|
+
limitedText(base: Record<string, unknown>, field: string, value: string): Promise<Record<string, unknown>>;
|
|
15
|
+
readCachedResult(request: {
|
|
16
|
+
handle: string;
|
|
17
|
+
offset: number;
|
|
18
|
+
}): Promise<Record<string, unknown>>;
|
|
19
|
+
discardCachedResult(handle: string): Promise<Record<string, unknown>>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SnapshotResult } from "../cdp/snapshot-contract.ts";
|
|
2
|
+
import type { PageInfo } from "../cdp/types.ts";
|
|
3
|
+
export declare function boundTabs(pages: PageInfo[], query: string | undefined, offset: number, ownedOnly?: boolean): Record<string, unknown>;
|
|
4
|
+
export declare function boundSnapshot(page: SnapshotResult): Record<string, unknown>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type BrowserRouteConfig } from "./config.ts";
|
|
2
|
+
/** Host-selected persistence; writes must replace the complete value atomically. */
|
|
3
|
+
export interface BrowserRouteConfigStore {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
read(): Promise<string | undefined>;
|
|
6
|
+
write(text: string | undefined): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** A native path is used only when the host explicitly constructs this store. */
|
|
9
|
+
export declare function createBrowserRouteConfigFileStore(path: string): BrowserRouteConfigStore;
|
|
10
|
+
export declare function readBrowserRouteConfig(store: BrowserRouteConfigStore): Promise<BrowserRouteConfig>;
|
|
11
|
+
export declare function writeBrowserRouteConfig(store: BrowserRouteConfigStore, config: unknown): Promise<BrowserRouteConfig>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function browserHelp(hosts?: readonly string[]): Record<string, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startBrowser(signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BrowserCdpSession } from "../cdp/session.ts";
|
|
2
|
+
import { BrowserArtifacts } from "./artifacts.ts";
|
|
3
|
+
import { startBrowser } from "./launcher.ts";
|
|
4
|
+
import type { BrowserOperation } from "./operation.ts";
|
|
5
|
+
export declare class BrowserOperationExecutor {
|
|
6
|
+
private readonly cdp;
|
|
7
|
+
private readonly start;
|
|
8
|
+
constructor(cdp: BrowserCdpSession, start?: typeof startBrowser);
|
|
9
|
+
execute(operation: BrowserOperation, signal: AbortSignal | undefined, artifacts: BrowserArtifacts): Promise<Record<string, unknown>>;
|
|
10
|
+
private screenshot;
|
|
11
|
+
private tabResult;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SnapshotResponseLength } from "../cdp/snapshot-contract.ts";
|
|
2
|
+
import type { BrowserAction } from "./operation.ts";
|
|
3
|
+
export declare function isRecordValue(value: unknown): value is Record<string, unknown>;
|
|
4
|
+
export declare function requiredString(value: unknown, field: string): string;
|
|
5
|
+
export declare function optionalString(value: unknown, field: string): string | undefined;
|
|
6
|
+
export declare function requiredRef(value: unknown, action: BrowserAction): string;
|
|
7
|
+
export declare function offset(value: unknown, field?: string, fallback?: number): number;
|
|
8
|
+
export declare function line(value: unknown): number;
|
|
9
|
+
export declare function elementId(value: unknown): number | undefined;
|
|
10
|
+
export declare function responseLength(value: unknown): SnapshotResponseLength;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { WaitCondition } from "../cdp/actions/wait.ts";
|
|
2
|
+
import type { SnapshotResponseLength } from "../cdp/snapshot-contract.ts";
|
|
3
|
+
export declare const BROWSER_ACTIONS: readonly ["help", "start", "tabs", "open", "show", "close", "find", "click", "type", "fill", "press", "wait", "screenshot", "html", "navigate", "evaluate", "network", "load_all", "raw", "read_result", "discard_result", "stop"];
|
|
4
|
+
export declare const OPERATION_ORDER: ("click" | "close" | "discard_result" | "evaluate" | "fill" | "find" | "html" | "load_all" | "navigate" | "network" | "open" | "press" | "raw" | "read_result" | "screenshot" | "show" | "start" | "stop" | "tabs" | "type" | "wait")[];
|
|
5
|
+
export type BrowserAction = (typeof BROWSER_ACTIONS)[number];
|
|
6
|
+
export type BrowserOperation = {
|
|
7
|
+
action: "start";
|
|
8
|
+
} | {
|
|
9
|
+
action: "tabs";
|
|
10
|
+
query?: string | undefined;
|
|
11
|
+
offset: number;
|
|
12
|
+
owned_only?: boolean | undefined;
|
|
13
|
+
} | {
|
|
14
|
+
action: "open";
|
|
15
|
+
ref_id: string;
|
|
16
|
+
lineno: number;
|
|
17
|
+
response_length: SnapshotResponseLength;
|
|
18
|
+
} | {
|
|
19
|
+
action: "open";
|
|
20
|
+
url: string;
|
|
21
|
+
} | {
|
|
22
|
+
action: "show" | "close";
|
|
23
|
+
ref_id: string;
|
|
24
|
+
} | {
|
|
25
|
+
action: "find";
|
|
26
|
+
ref_id: string;
|
|
27
|
+
pattern: string;
|
|
28
|
+
lineno: number;
|
|
29
|
+
response_length: SnapshotResponseLength;
|
|
30
|
+
} | {
|
|
31
|
+
action: "click";
|
|
32
|
+
ref_id: string;
|
|
33
|
+
id: number;
|
|
34
|
+
selector?: never;
|
|
35
|
+
x?: never;
|
|
36
|
+
y?: never;
|
|
37
|
+
} | {
|
|
38
|
+
action: "click";
|
|
39
|
+
ref_id: string;
|
|
40
|
+
id?: never;
|
|
41
|
+
selector: string;
|
|
42
|
+
x?: never;
|
|
43
|
+
y?: never;
|
|
44
|
+
} | {
|
|
45
|
+
action: "click";
|
|
46
|
+
ref_id: string;
|
|
47
|
+
id?: never;
|
|
48
|
+
selector?: never;
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
} | {
|
|
52
|
+
action: "type";
|
|
53
|
+
ref_id: string;
|
|
54
|
+
id?: number | undefined;
|
|
55
|
+
text: string;
|
|
56
|
+
} | ({
|
|
57
|
+
action: "fill";
|
|
58
|
+
ref_id: string;
|
|
59
|
+
value: string | boolean;
|
|
60
|
+
} & ({
|
|
61
|
+
id: number;
|
|
62
|
+
selector?: never;
|
|
63
|
+
} | {
|
|
64
|
+
selector: string;
|
|
65
|
+
id?: never;
|
|
66
|
+
})) | {
|
|
67
|
+
action: "press";
|
|
68
|
+
ref_id: string;
|
|
69
|
+
key: string;
|
|
70
|
+
} | ({
|
|
71
|
+
action: "wait";
|
|
72
|
+
ref_id: string;
|
|
73
|
+
timeout_ms: number;
|
|
74
|
+
} & WaitCondition) | {
|
|
75
|
+
action: "screenshot";
|
|
76
|
+
ref_id: string;
|
|
77
|
+
id?: number | undefined;
|
|
78
|
+
selector?: string | undefined;
|
|
79
|
+
} | {
|
|
80
|
+
action: "html";
|
|
81
|
+
ref_id: string;
|
|
82
|
+
id?: number | undefined;
|
|
83
|
+
selector?: string | undefined;
|
|
84
|
+
} | {
|
|
85
|
+
action: "navigate";
|
|
86
|
+
ref_id: string;
|
|
87
|
+
url: string;
|
|
88
|
+
} | {
|
|
89
|
+
action: "evaluate";
|
|
90
|
+
ref_id: string;
|
|
91
|
+
expression: string;
|
|
92
|
+
} | {
|
|
93
|
+
action: "network";
|
|
94
|
+
ref_id: string;
|
|
95
|
+
} | {
|
|
96
|
+
action: "load_all";
|
|
97
|
+
ref_id: string;
|
|
98
|
+
selector: string;
|
|
99
|
+
interval_ms: number;
|
|
100
|
+
} | {
|
|
101
|
+
action: "raw";
|
|
102
|
+
ref_id: string;
|
|
103
|
+
method: string;
|
|
104
|
+
params: Record<string, unknown>;
|
|
105
|
+
} | {
|
|
106
|
+
action: "read_result";
|
|
107
|
+
handle: string;
|
|
108
|
+
offset: number;
|
|
109
|
+
} | {
|
|
110
|
+
action: "discard_result";
|
|
111
|
+
handle: string;
|
|
112
|
+
} | {
|
|
113
|
+
action: "stop";
|
|
114
|
+
ref_id?: string | undefined;
|
|
115
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BrowserAction, BrowserOperation } from "./operation.ts";
|
|
2
|
+
/** Validate tab effects after the envelope has rejected unknown fields and required a tab reference. */
|
|
3
|
+
export declare function parseTabOperation(action: BrowserAction, refId: string, value: Record<string, unknown>): BrowserOperation;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BrowserArtifacts } from "./artifacts.ts";
|
|
2
|
+
import type { BrowserOperation } from "./operation.ts";
|
|
3
|
+
import type { BrowserRoute } from "./routes.ts";
|
|
4
|
+
export declare function executeRemoteBrowser(route: BrowserRoute, operations: BrowserOperation[], ownerId: string, signal: AbortSignal | undefined, artifacts: BrowserArtifacts, stateDirectory: string): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface BrowserRemoteCommand {
|
|
2
|
+
nodePath: string;
|
|
3
|
+
}
|
|
4
|
+
export interface BrowserRoute {
|
|
5
|
+
local: boolean;
|
|
6
|
+
name: string;
|
|
7
|
+
remote?: BrowserRemoteCommand;
|
|
8
|
+
}
|
|
9
|
+
export declare class BrowserRoutes {
|
|
10
|
+
readonly names: readonly string[];
|
|
11
|
+
private readonly routes;
|
|
12
|
+
constructor(routes?: ReadonlyMap<string, BrowserRoute>);
|
|
13
|
+
resolve(name: string): BrowserRoute;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseBrowserRoutes(value: unknown, currentHostname?: string): BrowserRoutes;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BrowserArtifactStore } from "./artifact-store.ts";
|
|
2
|
+
import type { BrowserOperation } from "./operation.ts";
|
|
3
|
+
import type { BrowserRequest } from "./request.ts";
|
|
4
|
+
import { BrowserRoutes } from "./routes.ts";
|
|
5
|
+
export interface BrowserExecutionOptions {
|
|
6
|
+
ownerId?: string | undefined;
|
|
7
|
+
signal?: AbortSignal | undefined;
|
|
8
|
+
artifacts?: BrowserArtifactStore | undefined;
|
|
9
|
+
onOperation?(operation: BrowserOperation, index: number, total: number): void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface BrowserRuntimeConfig {
|
|
12
|
+
/** Explicit native private state. CDP ownership and SCP staging live here. */
|
|
13
|
+
stateDirectory: string;
|
|
14
|
+
artifacts: BrowserArtifactStore;
|
|
15
|
+
routes?: BrowserRoutes;
|
|
16
|
+
discover?: (signal?: AbortSignal) => Promise<string>;
|
|
17
|
+
start?: (signal?: AbortSignal) => Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
export declare class BrowserRuntime {
|
|
20
|
+
readonly hosts: readonly string[];
|
|
21
|
+
private readonly defaultOwnerId;
|
|
22
|
+
private readonly lifetime;
|
|
23
|
+
private closing;
|
|
24
|
+
private readonly localSessions;
|
|
25
|
+
private readonly routes;
|
|
26
|
+
private readonly active;
|
|
27
|
+
private readonly config;
|
|
28
|
+
constructor(config: BrowserRuntimeConfig);
|
|
29
|
+
execute(request: BrowserRequest, options?: BrowserExecutionOptions): Promise<Record<string, unknown>>;
|
|
30
|
+
private run;
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
private executeLocal;
|
|
33
|
+
private localSession;
|
|
34
|
+
private pruneLocalSessions;
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BrowserRuntimeConfig } from "./runtime.ts";
|
|
2
|
+
export interface BrowserVoiceStartOptions {
|
|
3
|
+
url: string;
|
|
4
|
+
host?: string;
|
|
5
|
+
provider: "codex" | "gippity" | "grok";
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface BrowserVoiceStartResult {
|
|
10
|
+
state: "listening" | "error" | "timeout";
|
|
11
|
+
url: string;
|
|
12
|
+
refId?: string;
|
|
13
|
+
status: string;
|
|
14
|
+
detail: string;
|
|
15
|
+
}
|
|
16
|
+
/** Start once in a new tab; disconnect automation without closing the tab. */
|
|
17
|
+
export declare function startBrowserVoice(options: BrowserVoiceStartOptions, config: BrowserRuntimeConfig): Promise<BrowserVoiceStartResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function requestBrowserWorker(input: string, entryPath: string, workerId: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function serveBrowserWorker(workerId: string): Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Socket } from "node:net";
|
|
2
|
+
export type WorkerResponse = {
|
|
3
|
+
ok: true;
|
|
4
|
+
result: Record<string, unknown>;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function workerSocketPath(workerId: string): string;
|
|
10
|
+
export declare function ensureWorkerSocketDirectory(workerId: string): Promise<void>;
|
|
11
|
+
export declare function readLine(socket: Socket): Promise<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SnapshotElement, SnapshotLine } from "./snapshot-contract.ts";
|
|
2
|
+
import { type ElementRefs } from "./types.ts";
|
|
3
|
+
type InternalLine = SnapshotLine & {
|
|
4
|
+
kind: string;
|
|
5
|
+
};
|
|
6
|
+
/** Replace a tab's reference map while rendering the full accessibility tree. IDs never repeat within that map. */
|
|
7
|
+
export declare function renderAccessibilityTree(values: unknown[], elementRefs: ElementRefs): {
|
|
8
|
+
lines: InternalLine[];
|
|
9
|
+
elements: SnapshotElement[];
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CdpConnection, ElementRefs } from "../types.ts";
|
|
2
|
+
import { type ElementPoint } from "./element.ts";
|
|
3
|
+
export declare function clickBackendNode(cdp: CdpConnection, sessionId: string, backendNodeId: number, signal?: AbortSignal): Promise<ElementPoint>;
|
|
4
|
+
export declare function clickSelector(cdp: CdpConnection, sessionId: string, selector: string, signal?: AbortSignal): Promise<string>;
|
|
5
|
+
export declare function clickRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, signal?: AbortSignal): Promise<string>;
|
|
6
|
+
export declare function clickCoordinates(cdp: CdpConnection, sessionId: string, x: number, y: number, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CdpConnection, ElementRefs } from "../types.ts";
|
|
2
|
+
export interface ElementPoint {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
tag: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ScreenshotClip {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
scale: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function requireElementRef(elementRefs: ElementRefs, id: number | string): {
|
|
16
|
+
id: number;
|
|
17
|
+
backendNodeId: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function withBackendObject<T>(cdp: CdpConnection, sessionId: string, backendNodeId: number, action: (objectId: string) => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
20
|
+
export declare function scrollBackendIntoView(cdp: CdpConnection, sessionId: string, backendNodeId: number, signal?: AbortSignal): Promise<void>;
|
|
21
|
+
export declare function backendCenter(cdp: CdpConnection, sessionId: string, backendNodeId: number, scroll?: boolean, signal?: AbortSignal): Promise<ElementPoint>;
|
|
22
|
+
export declare function visibleElementClip(cdp: CdpConnection, sessionId: string, quad: number[], padding?: number, signal?: AbortSignal): Promise<ScreenshotClip>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CdpConnection, ElementRefs } from "../types.ts";
|
|
2
|
+
export declare function fillElement(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, target: {
|
|
3
|
+
id: number;
|
|
4
|
+
selector?: never;
|
|
5
|
+
} | {
|
|
6
|
+
selector: string;
|
|
7
|
+
id?: never;
|
|
8
|
+
}, value: string | boolean, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CdpConnection } from "../types.ts";
|
|
2
|
+
declare const MODIFIERS: {
|
|
3
|
+
readonly Alt: 1;
|
|
4
|
+
readonly Control: 2;
|
|
5
|
+
readonly Meta: 4;
|
|
6
|
+
readonly Shift: 8;
|
|
7
|
+
};
|
|
8
|
+
type Modifier = keyof typeof MODIFIERS;
|
|
9
|
+
interface Key {
|
|
10
|
+
key: string;
|
|
11
|
+
code: string;
|
|
12
|
+
windowsVirtualKeyCode: number;
|
|
13
|
+
text?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseKeyChord(chord: string): {
|
|
16
|
+
modifiers: Modifier[];
|
|
17
|
+
key: Key;
|
|
18
|
+
};
|
|
19
|
+
export declare function pressKey(cdp: CdpConnection, sessionId: string, chord: string, signal?: AbortSignal): Promise<string>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CdpConnection, ElementRefs } from "../types.ts";
|
|
2
|
+
export declare function html(cdp: CdpConnection, sessionId: string, selector?: string, signal?: AbortSignal): Promise<string>;
|
|
3
|
+
export declare function htmlRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, signal?: AbortSignal): Promise<string>;
|
|
4
|
+
export declare function navigate(cdp: CdpConnection, sessionId: string, url: string, signal?: AbortSignal): Promise<string>;
|
|
5
|
+
export declare function networkEntries(cdp: CdpConnection, sessionId: string, signal?: AbortSignal): Promise<string>;
|
|
6
|
+
export declare function loadAll(cdp: CdpConnection, sessionId: string, selector: string, intervalMs?: number, signal?: AbortSignal): Promise<string>;
|
|
7
|
+
export declare function rawCommand(cdp: CdpConnection, sessionId: string, method: string, params: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CdpConnection, ElementRefs } from "../types.ts";
|
|
2
|
+
export interface ScreenshotTarget {
|
|
3
|
+
file: string;
|
|
4
|
+
write(data: Uint8Array): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface ScreenshotCapture {
|
|
7
|
+
file: string;
|
|
8
|
+
dpr: number;
|
|
9
|
+
width?: number | undefined;
|
|
10
|
+
height?: number | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare function captureViewport(cdp: CdpConnection, sessionId: string, target: ScreenshotTarget, signal?: AbortSignal): Promise<ScreenshotCapture>;
|
|
13
|
+
export declare function captureSelector(cdp: CdpConnection, sessionId: string, selector: string, target: ScreenshotTarget, signal?: AbortSignal): Promise<ScreenshotCapture>;
|
|
14
|
+
export declare function captureRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, target: ScreenshotTarget, signal?: AbortSignal): Promise<ScreenshotCapture>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CdpConnection, ElementRefs } from "../types.ts";
|
|
2
|
+
export declare function typeAtFocus(cdp: CdpConnection, sessionId: string, text: string, signal?: AbortSignal): Promise<string>;
|
|
3
|
+
export declare function typeRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, text: string, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CdpConnection } from "../types.ts";
|
|
2
|
+
export type WaitCondition = {
|
|
3
|
+
selector: string;
|
|
4
|
+
} | {
|
|
5
|
+
text: string;
|
|
6
|
+
} | {
|
|
7
|
+
url_includes: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function waitForCondition(cdp: CdpConnection, sessionId: string, condition: WaitCondition, timeoutMs: number, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CdpConnection, CdpEventWait, CdpParams } from "./types.ts";
|
|
2
|
+
type EventHandler = (params: unknown) => void;
|
|
3
|
+
export declare class CdpClient implements CdpConnection {
|
|
4
|
+
private socket;
|
|
5
|
+
private nextId;
|
|
6
|
+
private readonly pending;
|
|
7
|
+
private readonly eventHandlers;
|
|
8
|
+
private readonly closeHandlers;
|
|
9
|
+
connect(url: string, signal?: AbortSignal): Promise<void>;
|
|
10
|
+
send(method: string, params?: CdpParams, sessionId?: string, signal?: AbortSignal): Promise<unknown>;
|
|
11
|
+
onEvent(method: string, handler: EventHandler): () => void;
|
|
12
|
+
waitForEvent(method: string, timeout?: number, signal?: AbortSignal): CdpEventWait;
|
|
13
|
+
onClose(handler: () => void): () => void;
|
|
14
|
+
close(): void;
|
|
15
|
+
private sendOnce;
|
|
16
|
+
private handleMessage;
|
|
17
|
+
private finishPending;
|
|
18
|
+
private handleClose;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const CDP_TIMEOUT_MS = 15000;
|
|
2
|
+
export declare const NAVIGATION_TIMEOUT_MS = 30000;
|
|
3
|
+
export declare function probeDebugPort(port: string, host?: string, signal?: AbortSignal): Promise<string>;
|
|
4
|
+
export declare function getWebSocketUrl(signal?: AbortSignal, recovery?: string): Promise<string>;
|
|
5
|
+
export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
6
|
+
export declare function resolvePrefix(prefix: string, candidates: string[], noun?: string, missingHint?: string): string;
|
|
7
|
+
export declare function getDisplayPrefixLength(targetIds: string[]): number;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CdpConnection } from "./types.ts";
|
|
2
|
+
export declare function evaluate(cdp: CdpConnection, sessionId: string, expression: string, signal?: AbortSignal): Promise<unknown>;
|
|
3
|
+
export declare function evaluateText(cdp: CdpConnection, sessionId: string, expression: string, signal?: AbortSignal): Promise<string>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CdpConnection, PageInfo } from "./types.ts";
|
|
2
|
+
export declare function getPageTargets(cdp: CdpConnection, signal?: AbortSignal): Promise<PageInfo[]>;
|
|
3
|
+
export declare function getDisplayedPages(targets: PageInfo[]): PageInfo[];
|
|
4
|
+
export declare function waitForOpenedTarget(cdp: CdpConnection, targetId: string, requestedUrl: string, timeout?: number, signal?: AbortSignal): Promise<PageInfo>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function waitForTurn<T>(promise: Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getWebSocketUrl } from "./discovery.ts";
|
|
2
|
+
import { type ActiveTab } from "./tab-bridge.ts";
|
|
3
|
+
import type { PageInfo } from "./types.ts";
|
|
4
|
+
export declare class BrowserCdpSession {
|
|
5
|
+
private closing;
|
|
6
|
+
private root;
|
|
7
|
+
private rootPending;
|
|
8
|
+
private readonly ownerId;
|
|
9
|
+
private readonly ownershipDirectory;
|
|
10
|
+
private readonly tabs;
|
|
11
|
+
private readonly tabPromises;
|
|
12
|
+
private readonly discover;
|
|
13
|
+
constructor(ownerId: string, ownershipDirectory: string, discover?: typeof getWebSocketUrl);
|
|
14
|
+
pages(signal?: AbortSignal): Promise<PageInfo[]>;
|
|
15
|
+
open(url: string, signal?: AbortSignal): Promise<{
|
|
16
|
+
refId: string;
|
|
17
|
+
}>;
|
|
18
|
+
show(refId: string, signal?: AbortSignal): Promise<string>;
|
|
19
|
+
closeTab(refId: string, signal?: AbortSignal): Promise<string>;
|
|
20
|
+
withTab<T>(refId: string, signal: AbortSignal | undefined, action: (tab: ActiveTab) => Promise<T>, rendering?: "background" | "foreground"): Promise<T>;
|
|
21
|
+
stop(refId?: string): Promise<void>;
|
|
22
|
+
close(): Promise<void>;
|
|
23
|
+
private rootConnection;
|
|
24
|
+
private connectTab;
|
|
25
|
+
private stopPendingTab;
|
|
26
|
+
private connectRoot;
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type SnapshotResponseLength = "short" | "medium" | "long";
|
|
2
|
+
export declare const SNAPSHOT_LIMITS: Record<SnapshotResponseLength, number>;
|
|
3
|
+
export interface SnapshotLine {
|
|
4
|
+
line: number;
|
|
5
|
+
text: string;
|
|
6
|
+
element_id?: number | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface SnapshotElement {
|
|
9
|
+
id: number;
|
|
10
|
+
role: string;
|
|
11
|
+
name?: string | undefined;
|
|
12
|
+
href?: string | undefined;
|
|
13
|
+
href_omitted?: true | undefined;
|
|
14
|
+
value?: unknown;
|
|
15
|
+
checked?: boolean | "mixed" | undefined;
|
|
16
|
+
selected?: boolean | undefined;
|
|
17
|
+
expanded?: boolean | undefined;
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface SnapshotResult {
|
|
21
|
+
ref_id?: string | undefined;
|
|
22
|
+
title: string;
|
|
23
|
+
url: string;
|
|
24
|
+
lineno: number;
|
|
25
|
+
content: SnapshotLine[];
|
|
26
|
+
elements: SnapshotElement[];
|
|
27
|
+
pattern?: string | undefined;
|
|
28
|
+
next_lineno?: number | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface SnapshotOptions {
|
|
31
|
+
refId?: string | undefined;
|
|
32
|
+
pattern?: string | undefined;
|
|
33
|
+
lineno?: number | string | undefined;
|
|
34
|
+
responseLength?: SnapshotResponseLength | string | undefined;
|
|
35
|
+
signal?: AbortSignal | undefined;
|
|
36
|
+
}
|
|
37
|
+
export declare function positiveInteger(value: number | string, label: string): number;
|
|
38
|
+
export declare function snapshotResponseLength(value: string | undefined): SnapshotResponseLength;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type SnapshotOptions, type SnapshotResult } from "./snapshot-contract.ts";
|
|
2
|
+
import type { CdpConnection, ElementRefs } from "./types.ts";
|
|
3
|
+
export declare function snapshotData(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, options?: SnapshotOptions): Promise<SnapshotResult>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CdpClient } from "./client.ts";
|
|
2
|
+
import type { ElementRefs } from "./types.ts";
|
|
3
|
+
export interface ActiveTab {
|
|
4
|
+
cdp: CdpClient;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
elementRefs: ElementRefs;
|
|
7
|
+
refId: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class TabBridge {
|
|
10
|
+
readonly elementRefs: ElementRefs;
|
|
11
|
+
readonly targetId: string;
|
|
12
|
+
readonly cdp: CdpClient;
|
|
13
|
+
readonly sessionId: string;
|
|
14
|
+
private tail;
|
|
15
|
+
private idleTimer;
|
|
16
|
+
private closed;
|
|
17
|
+
private closing;
|
|
18
|
+
private backgroundRendering;
|
|
19
|
+
private readonly onClose;
|
|
20
|
+
private constructor();
|
|
21
|
+
static connect(targetId: string, onClose: () => void, signal: AbortSignal | undefined, discover: (signal?: AbortSignal) => Promise<string>): Promise<TabBridge>;
|
|
22
|
+
run<T>(refId: string, signal: AbortSignal | undefined, action: (tab: ActiveTab) => Promise<T>): Promise<T>;
|
|
23
|
+
setBackgroundRendering(enabled: boolean, signal?: AbortSignal): Promise<void>;
|
|
24
|
+
close(detach?: boolean): Promise<void>;
|
|
25
|
+
private resetIdle;
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CdpConnection, PageInfo } from "./types.ts";
|
|
2
|
+
export declare class BrowserTabs {
|
|
3
|
+
private readonly cdp;
|
|
4
|
+
private readonly directory;
|
|
5
|
+
private readonly ownershipDirectory;
|
|
6
|
+
private readonly scope;
|
|
7
|
+
private tail;
|
|
8
|
+
private closed;
|
|
9
|
+
private prepared;
|
|
10
|
+
constructor(cdp: CdpConnection, ownerId: string, directory: string, browserUrl: string);
|
|
11
|
+
list(signal?: AbortSignal): Promise<PageInfo[]>;
|
|
12
|
+
shutdown(): Promise<void>;
|
|
13
|
+
private enqueue;
|
|
14
|
+
private listNow;
|
|
15
|
+
resolve(refId: string, signal?: AbortSignal): Promise<{
|
|
16
|
+
page: PageInfo;
|
|
17
|
+
refId: string;
|
|
18
|
+
}>;
|
|
19
|
+
open(url: string, signal?: AbortSignal): Promise<{
|
|
20
|
+
refId: string;
|
|
21
|
+
}>;
|
|
22
|
+
show(refId: string, signal?: AbortSignal): Promise<string>;
|
|
23
|
+
close(refId: string, signal?: AbortSignal): Promise<{
|
|
24
|
+
targetId: string;
|
|
25
|
+
refId: string;
|
|
26
|
+
}>;
|
|
27
|
+
private targetPath;
|
|
28
|
+
private readOwned;
|
|
29
|
+
private touchDirectory;
|
|
30
|
+
private remember;
|
|
31
|
+
private forget;
|
|
32
|
+
}
|