diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cdp/errors.ts | 19 | ||||
| -rw-r--r-- | src/cdp/types.ts | 51 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/cdp/errors.ts b/src/cdp/errors.ts new file mode 100644 index 0000000..cf1dab7 --- /dev/null +++ b/src/cdp/errors.ts @@ -0,0 +1,19 @@ +export type CdpErrorKind = + | "transport_closed" + | "timeout" + | "session_not_found" + | "remote_error" + | "discovery_failed" + | "invalid_response"; + +export type CdpError = { + readonly kind: CdpErrorKind; + readonly message: string; + readonly method?: string; +}; + +export const cdpError = ( + kind: CdpErrorKind, + message: string, + method?: string, +): CdpError => ({ kind, message, ...(method !== undefined ? { method } : {}) }); diff --git a/src/cdp/types.ts b/src/cdp/types.ts new file mode 100644 index 0000000..cbcb2d5 --- /dev/null +++ b/src/cdp/types.ts @@ -0,0 +1,51 @@ +export type CdpEvent = { + readonly method: string; + readonly params: unknown; + readonly sessionId?: string; +}; + +export type CdpRawMessage = { + readonly id?: number; + readonly method?: string; + readonly params?: Record<string, unknown>; + readonly result?: unknown; + readonly error?: { readonly message: string; readonly code?: number }; + readonly sessionId?: string; +}; + +export type DialogInfo = { + readonly type: "alert" | "confirm" | "prompt" | "beforeunload"; + readonly message: string; + readonly defaultPrompt?: string; +}; + +export type TabInfo = { + readonly targetId: string; + readonly title: string; + readonly url: string; +}; + +export type PageInfo = { + readonly url: string; + readonly title: string; + readonly width: number; + readonly height: number; + readonly scrollX: number; + readonly scrollY: number; + readonly pageWidth: number; + readonly pageHeight: number; +}; + +export type DaemonStatus = { + readonly alive: boolean; + readonly sessionId: string | null; + readonly namespace: string; + readonly remoteBrowserId?: string; +}; + +const INTERNAL_PREFIXES: ReadonlyArray<string> = [ + "chrome://", "chrome-untrusted://", "devtools://", "chrome-extension://", "about:", +]; + +export const isInternalUrl = (url: string): boolean => + INTERNAL_PREFIXES.some((p) => url.startsWith(p)); |
