# sema-cdp 0.1.1 — API reference

Source declarations extracted without executing package code. Signatures describe declarations, not inferred runtime behavior.

## cdp/attach!

```sema
(cdp/attach! conn target-id)
```

Attach to a target (flat protocol) and return a session map. Pass the session to cdp/send / cdp/wait-event to address commands to that target.

[Source line 281](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L281)

## cdp/browser-candidates

```sema
(cdp/browser-candidates)
```

Return the browser binary paths cdp/find-chrome probes on this machine, in priority order (Chrome, Chromium, Brave, Edge). Entries are candidates — most will not exist.

[Source line 62](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L62)

## cdp/clear-events!

```sema
(cdp/clear-events! target . method-rest)
```

Drop buffered events — all of them, or only a given method name. Scoped to the session when `target` is one.

[Source line 338](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L338)

## cdp/close!

```sema
(cdp/close! conn)
```

Close the browser: ask it to shut down via Browser.close, close the websocket, kill the spawned process if this connection launched it, and delete the temp profile dir if cdp/launch created it.

[Source line 161](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L161)

## cdp/connect

```sema
(cdp/connect url)
```

Connect to an already-running browser. Accepts a ws:// debugger URL, or an http:// devtools address (e.g. "http://localhost:9222") whose /json/version endpoint is used to discover it.

[Source line 151](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L151)

## cdp/detach!

```sema
(cdp/detach! session)
```

Detach a session created by cdp/attach!.

[Source line 287](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L287)

## cdp/events

```sema
(cdp/events target)
```

Return the buffered events for this connection (or, for a session, only that session's), oldest first.

[Source line 330](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L330)

## cdp/find-chrome

```sema
(cdp/find-chrome)
```

Return the path of a Chrome-compatible browser binary, or nil if none is found. Checks the SEMA_CHROME env var first, then well-known install locations on macOS, Linux, and Windows (see cdp/browser-candidates).

[Source line 76](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L76)

## cdp/launch

```sema
(cdp/launch . opts-rest)
```

Launch a Chrome-compatible browser with remote debugging and return a connection. Options map: :headless (default #t), :chrome (binary path), :args (extra CLI args), :user-data-dir (default: fresh dir under the system temp dir).

[Source line 116](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L116)

## cdp/new-target!

```sema
(cdp/new-target! conn url)
```

Create a new page target navigated to url and return its target id.

[Source line 277](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L277)

## cdp/off!

```sema
(cdp/off! target handler-id)
```

Remove an event handler registered by cdp/on!, by its returned id.

[Source line 311](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L311)

## cdp/on!

```sema
(cdp/on! target method handler)
```

Register a handler called with each matching event map as it arrives, and return a handler id for cdp/off!. Events are only received while a cdp/send, cdp/wait-event, or cdp/pump is pumping the connection. Scoped to the session when `target` is one, otherwise connection-wide. Handlers may call cdp/send themselves.

[Source line 300](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L300)

## cdp/pump

```sema
(cdp/pump target duration-ms)
```

Receive and dispatch events for up to duration-ms without sending anything — use it to let cdp/on! handlers run while otherwise idle.

[Source line 319](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L319)

## cdp/send

```sema
(cdp/send target method . extra)
```

Send a CDP command and return its result map. `target` is a connection or a session (from cdp/attach!). Optional: params map, then options map {:timeout ms}. Raises on a CDP error response, including the method, code, and message.

[Source line 248](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L248)

## cdp/targets

```sema
(cdp/targets conn)
```

List the browser's targets (pages, workers, extensions) as maps with :targetId, :type, :url, :title.

[Source line 273](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L273)

## cdp/version

```sema
(cdp/version conn)
```

Return browser version info: :product, :revision, :userAgent, :jsVersion, :protocolVersion.

[Source line 269](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L269)

## cdp/wait-event

```sema
(cdp/wait-event target method . opts-rest)
```

Wait for an event, consuming it from the buffer, and return the event map. Checks already-buffered events first. Options: :timeout ms (default 30000), :pred (event map -&gt; bool). Scoped to the session when `target` is one.

[Source line 358](https://pkg.sema-lang.com/packages/sema-cdp/0.1.1/source/package.sema#L358)

---

Parser: sema-reader 1.37.0

Archive SHA-256: `f7609ffe22d6a6ef869558c7bbf895e24680b74e897236a549efb0e69e0aff1e`
