//#region src/browser/cdp-connection.d.ts
interface DebugEntry {
  at: string;
  type: string;
  [key: string]: unknown;
}
interface CdpSendOptions {
  timeoutMs?: number;
  sessionId?: string;
}
interface CdpAttachOptions {
  timeoutMs?: number;
}
/** Construction options for {@link CdpConnection}. */
interface CdpConnectionOptions {
  /** Default per-command timeout. Defaults to 10 seconds. */
  timeoutMs?: number;
  /**
   * Invoked exactly once when the session reaches a terminal state — an
   * explicit `close()`, peer closure, or a socket error.
   */
  onClose?: () => void;
  /** Browser Run session id, when connected to a session-scoped browser. */
  sessionId?: string;
  /** Invoked on every CDP command sent — an activity signal for idle tracking. */
  onActivity?: () => void;
}
/**
 * One Chrome DevTools Protocol connection over an open WebSocket. Manages
 * command correlation, timeouts, per-tab CDP sessions, and a debug event
 * ring buffer.
 *
 * Used host-side (not in the sandbox) — the sandbox calls into this
 * via DynamicWorkerExecutor's ToolDispatcher RPC.
 */
declare class CdpConnection {
  #private;
  readonly sessionId?: string;
  constructor(socket: WebSocket, options?: CdpConnectionOptions);
  /**
   * @deprecated Pass a {@link CdpConnectionOptions} object instead —
   * `new CdpConnection(socket, { timeoutMs, onClose, sessionId })`. The
   * positional form will be removed.
   */
  constructor(
    socket: WebSocket,
    timeoutMs?: number,
    onClose?: () => void,
    sessionId?: string
  );
  send(
    method: string,
    params?: unknown,
    options?: CdpSendOptions
  ): Promise<unknown>;
  attachToTarget(targetId: string, options?: CdpAttachOptions): Promise<string>;
  getDebugLog(limit?: number): DebugEntry[];
  clearDebugLog(): void;
  disconnect(): void;
  close(): void;
}
/**
 * Connect to a browser via a CDP base URL (e.g. http://localhost:9222).
 * Discovers the WebSocket debugger URL via /json/version,
 * rewrites localhost URLs to the base URL host, and opens the WebSocket.
 *
 * Useful for local development with `chrome --remote-debugging-port=9222`
 * or when connecting through a tunnel.
 */
declare function connectUrl(
  baseUrl: string,
  options?: {
    timeoutMs?: number;
    headers?: Record<string, string>;
  }
): Promise<CdpConnection>;
/** @deprecated Renamed to {@link CdpConnection}. */
declare const CdpSession: typeof CdpConnection;
/** @deprecated Renamed to {@link CdpConnection}. */
type CdpSession = CdpConnection;
//#endregion
//#region src/browser/browser-run.d.ts
/**
 * A Browser Rendering binding. Structural so it accepts both the classic
 * `Fetcher`-typed binding and the newer `BrowserRun` type generated by
 * `wrangler types`.
 *
 * `fetch` is always used. `acquire` and `closeSession` are Browser Run's
 * typed binding methods; {@link acquireBrowserSession} and
 * {@link closeBrowserSession} use them when the binding has them.
 */
interface BrowserBinding {
  fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
  acquire?(options?: {
    keepAlive?: number;
    recording?: boolean;
    guardrails?: BrowserSessionGuardrails;
    outboundByHost?: Record<string, Fetcher>;
  }): Promise<{
    sessionId: string;
  }>;
  closeSession?(sessionId: string): Promise<unknown>;
}
/**
 * Browser Run [hostname guardrails](https://developers.cloudflare.com/browser-run/features/guardrails/):
 * restrict which hostnames the session's HTTP/HTTPS requests may reach. Fixed
 * at session launch for every connection to the session, including Live View.
 * Omitted entirely, the platform default applies: all hostnames are allowed.
 * Not supported by Kitesurf.
 */
interface BrowserSessionGuardrails {
  /**
   * Hostname patterns the browser may request — bare hostnames only (no
   * protocol, port, or path). `*.example.com` matches subdomains; add
   * `example.com` separately to allow the apex.
   */
  allowedDomains?: string[];
  /** Named Cloudflare-maintained domain sets, e.g. `"common-cdns"`. */
  allowedDomainSets?: string[];
}
interface BrowserTargetInfo {
  id: string;
  type?: string;
  url?: string;
  title?: string;
  description?: string;
  devtoolsFrontendUrl?: string;
  webSocketDebuggerUrl?: string;
}
interface BrowserSessionInfo {
  sessionId: string;
  targets?: BrowserTargetInfo[];
  webSocketDebuggerUrl?: string;
}
/** {@link connectBrowser} options for the default Chromium engine. */
interface ConnectChromiumBrowserOptions {
  /** Select the browser engine. Defaults to Chromium. */
  browser?: "chromium";
  timeoutMs?: number;
  keepAliveMs?: number;
  includeTargets?: boolean;
  /**
   * Opt into Browser Run [session recording](https://developers.cloudflare.com/browser-run/features/session-recording/):
   * an rrweb capture of DOM changes, input, and navigation, finalized when the
   * session closes. Set at session-launch time. Retrieve later with
   * {@link getBrowserRecording}.
   */
  recording?: boolean;
}
/**
 * {@link connectBrowser} options for Kitesurf, Cloudflare's connection-scoped,
 * agent-first browser engine. A Kitesurf browser lives and dies with its
 * WebSocket, so the Chromium-only options (`keepAliveMs`, `includeTargets`,
 * `recording`) do not exist on this arm.
 */
interface ConnectKitesurfBrowserOptions {
  browser: "kitesurf";
  timeoutMs?: number;
}
/**
 * Engine-discriminated {@link connectBrowser} options: selecting
 * `browser: "kitesurf"` removes the Chromium-only options at the type level.
 */
type ConnectBrowserOptions =
  | ConnectChromiumBrowserOptions
  | ConnectKitesurfBrowserOptions;
/** An rrweb session recording for a closed Browser Run session. */
interface BrowserRecording {
  sessionId: string;
  /** Recording length in milliseconds. */
  duration: number;
  /**
   * rrweb event arrays keyed by CDP target id (one per tab). Each value can be
   * passed directly to `rrweb-player` to replay that tab.
   */
  events: Record<string, unknown[]>;
}
declare class BrowserRenderingError extends Error {
  readonly status: number;
  constructor(message: string, status: number);
}
declare function createBrowserSession(
  browser: BrowserBinding,
  options?: {
    keepAliveMs?: number;
    includeTargets?: boolean;
    recording?: boolean;
    guardrails?: BrowserSessionGuardrails;
  }
): Promise<BrowserSessionInfo>;
declare function listBrowserTargets(
  browser: BrowserBinding,
  sessionId: string
): Promise<BrowserTargetInfo[]>;
declare function deleteBrowserSession(
  browser: BrowserBinding,
  sessionId: string
): Promise<void>;
/**
 * Connect to a Browser Rendering session and delete it when closed.
 */
declare function connectBrowser(
  browser: BrowserBinding,
  options?: number | ConnectBrowserOptions
): Promise<CdpConnection>;
/**
 * Fetch a Browser Run [session recording](https://developers.cloudflare.com/browser-run/features/session-recording/)
 * by session id, via the Browser Rendering REST API.
 *
 * A recording is only available **after** the session closes (explicit
 * `closeSession()`, idle `keep_alive` expiry, or sweep) and is retained for 30
 * days. Capture the session id while the session is alive — e.g. from
 * `connector.liveView()`/`sessionInfo()` — then call this once it has ended.
 *
 * Unlike the binding-based helpers, this hits `api.cloudflare.com` directly, so
 * it needs an account id and an API token with `Browser Rendering` read access
 * (the Workers Browser Run binding cannot read recordings).
 */
declare function getBrowserRecording(options: {
  accountId: string;
  apiToken: string;
  sessionId: string /** Override for testing; defaults to the global `fetch`. */;
  fetchImpl?: typeof fetch;
}): Promise<BrowserRecording>;
interface ConnectBrowserSessionOptions {
  timeoutMs?: number;
  /**
   * Invoked once when the returned {@link CdpConnection} reaches a terminal
   * state — an explicit `close()`, peer closure, or a socket error. The
   * session itself is never deleted on close — pass an `onClose` that
   * deletes it for one-shot (create-and-close) semantics.
   */
  onClose?: () => void;
  /**
   * Invoked on every CDP command sent over the returned {@link CdpConnection} —
   * an activity signal for idle tracking. Keep it cheap and synchronous;
   * throttle any I/O it triggers.
   */
  onActivity?: () => void;
}
/**
 * Connect to an existing Browser Rendering session without deleting it on close.
 */
declare function connectBrowserSession(
  browser: BrowserBinding,
  sessionId: string,
  options?: ConnectBrowserSessionOptions
): Promise<CdpConnection>;
/**
 * @deprecated Pass `{ timeoutMs }` instead of a bare number — the numeric
 * form will be removed.
 */
declare function connectBrowserSession(
  browser: BrowserBinding,
  sessionId: string,
  timeoutMs?: number
): Promise<CdpConnection>;
//#endregion
//#region src/browser/live-view.d.ts
/**
 * Live View rendering mode (the `mode` query param the hosted UI at
 * `live.browser.run` understands):
 *
 * - `"tab"` — a standalone, interactive page view (best for handing control
 *   to a human).
 * - `"devtools"` — the full DevTools inspector panel (Elements, Console,
 *   Network, …).
 *
 * Omit it to use whatever mode the binding's `devtoolsFrontendUrl` defaults
 * to.
 */
type LiveViewMode = "tab" | "devtools";
/** A single tab's Live View URL. */
interface BrowserLiveViewUrl {
  /** Open this in a browser to watch/control the tab in real time. */
  url: string;
  /** CDP target (tab) id the URL points at. */
  targetId: string;
  /** Milliseconds the URL stays valid from when it was generated (~5 min). */
  expiresInMs: number;
}
interface BrowserLiveViewTarget {
  targetId: string;
  /** Embeddable Live View URL (the `devtoolsFrontendUrl`) for this tab. */
  url: string;
  /** The page the tab is currently showing (e.g. `https://example.com`). */
  pageUrl?: string;
  title?: string;
  type?: string;
}
/** Live View URLs for every tab in a session. */
interface BrowserLiveView {
  sessionId: string;
  targets: BrowserLiveViewTarget[];
  /** Milliseconds the URLs stay valid from when they were generated (~5 min). */
  expiresInMs: number;
}
//#endregion
//#region src/browser/session-store.d.ts
type MaybePromise<T> = T | Promise<T>;
interface StoredBrowserSession {
  sessionId: string;
  createdAt: number;
  updatedAt: number;
  /**
   * Set when a sweep closed this entry's Browser Run session but kept the
   * entry as a tombstone, so a later resume of the owning execution fails
   * loudly instead of silently continuing in a fresh browser.
   */
  closedAt?: number;
  /**
   * Browser scope records only: the tab (CDP `targetId`) the scope last
   * worked in, so `sessionId: "active"` in a later execution lands on the
   * same page. CDP session ids die with each connection; target ids live as
   * long as the tab.
   */
  activeTargetId?: string;
  /**
   * Named browser records only: the internal hostnames the session was
   * started with (see `internalHostsSignature`). Routes are fixed at launch,
   * so a record made with different hostnames is replaced.
   */
  internalHosts?: string;
}
interface BrowserSessionLock {
  release(): MaybePromise<void>;
}
interface BrowserSessionStore {
  /**
   * Acquire an exclusive lock for this session key. The lock must serialize
   * all holders using the same key. Held only around storage reads/writes —
   * never across Browser Rendering network calls.
   */
  acquireLock(key: string): MaybePromise<BrowserSessionLock>;
  get(key: string): MaybePromise<StoredBrowserSession | undefined>;
  set(key: string, session: StoredBrowserSession): MaybePromise<void>;
  delete(key: string): MaybePromise<void>;
  /**
   * List stored sessions by key prefix. Optional — used by sweeps to find
   * orphaned per-execution sessions; without it only the shared session key
   * is swept.
   */
  list?(prefix: string): MaybePromise<Map<string, StoredBrowserSession>>;
}
/**
 * A {@link BrowserSessionStore} that can list by prefix, as `Browser` needs:
 * it lists a browser's scope records to cap them and to see which tabs
 * other scopes are working in.
 */
type ListableBrowserSessionStore = BrowserSessionStore &
  Required<Pick<BrowserSessionStore, "list">>;
declare class DurableBrowserSessionStore implements BrowserSessionStore {
  #private;
  private readonly storage;
  constructor(storage: DurableObjectStorage);
  acquireLock(key: string): Promise<BrowserSessionLock>;
  get(key: string): Promise<StoredBrowserSession | undefined>;
  set(key: string, session: StoredBrowserSession): Promise<void>;
  delete(key: string): Promise<void>;
  list(prefix: string): Promise<Map<string, StoredBrowserSession>>;
}
/**
 * Default idle window used by {@link BrowserConnector.sweep} for the shared
 * (reuse/promoted) session entry.
 */
declare const DEFAULT_SWEEP_IDLE_MS: number;
//#endregion
export {
  CdpSendOptions as A,
  createBrowserSession as C,
  CdpAttachOptions as D,
  listBrowserTargets as E,
  connectUrl as M,
  CdpConnection as O,
  connectBrowserSession as S,
  getBrowserRecording as T,
  ConnectBrowserOptions as _,
  ListableBrowserSessionStore as a,
  ConnectKitesurfBrowserOptions as b,
  BrowserLiveViewTarget as c,
  BrowserBinding as d,
  BrowserRecording as f,
  BrowserTargetInfo as g,
  BrowserSessionInfo as h,
  DurableBrowserSessionStore as i,
  CdpSession as j,
  CdpConnectionOptions as k,
  BrowserLiveViewUrl as l,
  BrowserSessionGuardrails as m,
  BrowserSessionStore as n,
  StoredBrowserSession as o,
  BrowserRenderingError as p,
  DEFAULT_SWEEP_IDLE_MS as r,
  BrowserLiveView as s,
  BrowserSessionLock as t,
  LiveViewMode as u,
  ConnectBrowserSessionOptions as v,
  deleteBrowserSession as w,
  connectBrowser as x,
  ConnectChromiumBrowserOptions as y
};
//# sourceMappingURL=session-store-B7Ca-u1t.d.ts.map
