import type { Protocol } from "devtools-protocol";
/**
 * CDP transport & session multiplexer
 *
 * Owns the browser WebSocket and multiplexes flattened Target sessions.
 * Tracks inflight CDP calls, routes responses to the right session, and forwards events.
 *
 * This does not interpret Page/DOM/Runtime semantics — callers own that logic.
 */
export interface CDPSessionLike {
    send<R = unknown>(method: string, params?: object): Promise<R>;
    on<P = unknown>(event: string, handler: (params: P) => void): void;
    off<P = unknown>(event: string, handler: (params: P) => void): void;
    close(): Promise<void>;
    readonly id: string | null;
}
type EventHandler = (params: unknown) => void;
export declare class CdpConnection implements CDPSessionLike {
    private ws;
    private nextId;
    private inflight;
    private eventHandlers;
    private sessions;
    /** Maps sessionId -> targetId (1:1 mapping) */
    private sessionToTarget;
    readonly id: string | null;
    private transportCloseHandlers;
    /** Optional CDP logger - set this to receive all outgoing CDP method calls */
    cdpLogger?: (info: {
        method: string;
        params?: object;
        targetId?: string | null;
    }) => void;
    /** Optional CDP event logger - set this to receive all incoming CDP events */
    cdpEventLogger?: (info: {
        method: string;
        params?: unknown;
        targetId?: string | null;
    }) => void;
    onTransportClosed(handler: (why: string) => void): void;
    offTransportClosed(handler: (why: string) => void): void;
    private emitTransportClosed;
    private constructor();
    static connect(wsUrl: string): Promise<CdpConnection>;
    enableAutoAttach(): Promise<void>;
    send<R = unknown>(method: string, params?: object): Promise<R>;
    on<P = unknown>(event: string, handler: (params: P) => void): void;
    off<P = unknown>(event: string, handler: (params: P) => void): void;
    close(): Promise<void>;
    private rejectAllInflight;
    getSession(sessionId: string): CdpSession | undefined;
    attachToTarget(targetId: string): Promise<CdpSession>;
    getTargets(): Promise<Protocol.Target.TargetInfo[]>;
    private onMessage;
    _sendViaSession<R = unknown>(sessionId: string, method: string, params?: object): Promise<R>;
    _onSessionEvent(sessionId: string, event: string, handler: EventHandler): void;
    _offSessionEvent(sessionId: string, event: string, handler: EventHandler): void;
    _dispatchToSession(sessionId: string, event: string, params: unknown): void;
}
export declare class CdpSession implements CDPSessionLike {
    private readonly root;
    readonly id: string;
    constructor(root: CdpConnection, id: string);
    send<R = unknown>(method: string, params?: object): Promise<R>;
    on<P = unknown>(event: string, handler: (params: P) => void): void;
    off<P = unknown>(event: string, handler: (params: P) => void): void;
    close(): Promise<void>;
    dispatch(event: string, params: unknown): void;
}
export {};
