aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.ts
blob: 1b8bf405c3d329d16fe53f2a4fe742630127d39e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * Protocol types for pi-browser-harness.
 *
 * Defines the shape of CDP communication and browser state.
 * No socket transport — the daemon talks CDP directly over WebSocket.
 */

// ── CDP Event ────────────────────────────────────────────────────────────────

export interface CDPEvent {
  method: string;
  params: unknown;
  session_id?: string;
}

// ── Dialog ───────────────────────────────────────────────────────────────────

export interface DialogInfo {
  type: "alert" | "confirm" | "prompt" | "beforeunload";
  message: string;
  defaultPrompt?: string;
}

// ── Tab ──────────────────────────────────────────────────────────────────────

export interface TabInfo {
  targetId: string;
  title: string;
  url: string;
}

// ── Page State ───────────────────────────────────────────────────────────────

export interface PageInfo {
  url: string;
  title: string;
  width: number;
  height: number;
  scrollX: number;
  scrollY: number;
  pageWidth: number;
  pageHeight: number;
}

export type PageInfoResult = PageInfo | { dialog: DialogInfo };

// ── Daemon Status ────────────────────────────────────────────────────────────

export interface DaemonStatus {
  alive: boolean;
  sessionId: string | null;
  pid: number | null; // deprecated — always null (no subprocess)
  namespace: string;
  socketPath: string; // deprecated — always "" (no socket)
  remoteBrowserId?: string;
}

// ── Remote Config ────────────────────────────────────────────────────────────

export interface RemoteConfig {
  cdpUrl: string;
  browserId: string;
}

// ── Internal URL prefixes to filter ──────────────────────────────────────────

const INTERNAL_PREFIXES = [
  "chrome://",
  "chrome-untrusted://",
  "devtools://",
  "chrome-extension://",
  "about:",
];

export function isInternalUrl(url: string): boolean {
  return INTERNAL_PREFIXES.some((p) => url.startsWith(p));
}