Chrome DevTools Protocol (CDP) JSON-RPC target multiplexer, Page/DOM/Runtime/Network automation, request mocking, and WebSocket driver.
Pure-Veko Chrome DevTools Protocol (CDP) JSON-RPC session state machine, target flat-session multiplexing, ergonomic domain command builders, homoiconic E2E script runner, RFC 6455 net/websocket client adapter, and deterministic mock CDP loopback harness (browser_cdp).
browser_cdp provides zero-dependency browser automation, end-to-end UI verification, network request interception, and headless screenshot/PDF capture over the Chrome DevTools Protocol:
id envelopes against out-of-order responses while buffering asynchronous domain events (Page.loadEventFired, Network.responseReceived, Runtime.consoleAPICalled, Fetch.requestPaused) and multiplexing multiple browser tabs over a single WebSocket connection via flat sessionId routing.Page, DOM, Runtime, Input, Network, Fetch, and Target domains -- including Fetch.fulfillRequest network mocking with Base64 payload encoding.quote [...] blocks into executable E2eStep pipelines (compile-steps, run-steps) and validates DOM snapshots with unified line diffs (assert-snapshot).--remote-debugging-port (ws:// and wss://) over net/websocket, and ships an in-memory + loopback WebSocket mock CDP target (new-mock-browser, serve-mock-cdp-once) so E2E test suites run deterministically in CI without requiring a browser binary installed.veko pkg add browser_cdp@1.0.0Import the package in .vk source files:
use [cdp = browser_cdp]+-----------------------+ masked OP-TEXT JSON +-----------------------------+
| E2E Script / Caller | -----------------------------> | Chromium / MockCdpLoopback |
| compile-steps [...] | | Page / DOM / Runtime / Net |
+-----------+-----------+ <----------------------------- +-----------------------------+
| id responses + async events
v
+-----------------------+
| CdpSession |
| - monotonic next_id |
| - flat sessionId mux |
| - pending / responses |
| - FIFO domain events |
+-----------------------+When flat-session mode (Target.attachToTarget with flatten = true) is active, every command emitted with /session_id carries "sessionId": "<target-session>" at the top level of the CDP JSON envelope, and ingest-message preserves session_id on both CdpResponse and CdpEvent values.
| Symbol | Signature | Description |
|---|---|---|
new-session | fn [/session_id sid str = ''] CdpSession | Creates a fresh CDP JSON-RPC session state machine |
with-target-session | fn [sess CdpSession, session_id str] CdpSession | Returns a copy of sess pinned to session_id |
set-target-session | fn [mut sess CdpSession, session_id str] enum | Updates the default target sessionId in-place |
next-command | fn [mut sess CdpSession, method str, params map /session_id sid str = ''] CdpCommand | Allocates monotonic id and encodes a CDP JSON-RPC command |
ingest-message | fn [mut sess CdpSession, raw_json str] enum | Routes inbound JSON into .response (id) or .event (method) |
has-response? | fn [sess CdpSession, cmd_id i64] bool | Checks whether a response for cmd_id is buffered |
take-response | fn [mut sess CdpSession, cmd_id i64] CdpResponse | Removes and returns the correlated CdpResponse |
events-for-method | fn [sess CdpSession, method str /session_id sid str = ''] block[CdpEvent] | Returns buffered events matching method and optional session_id |
drain-events | fn [mut sess CdpSession /method filter_method str = '' /session_id sid str = ''] block[CdpEvent] | Drains matching events while preserving remaining events in FIFO order |
extract-eval-value | fn [resp CdpResponse] any | Extracts result.result.value or surfaces exceptionDetails as err |
extract-binary-data | fn [resp CdpResponse] bytes | Decodes Base64 result.data from screenshot or PDF responses |
page-enable | fn [mut sess CdpSession /session_id sid str = ''] CdpCommand | Builds Page.enable |
page-navigate | fn [mut sess CdpSession, target_url str /referrer ref str = '' /session_id sid str = ''] CdpCommand | Builds Page.navigate |
page-capture-screenshot | fn [mut sess CdpSession /format fmt str = 'png' /quality qual i64 = 0 /full_page full bool = false /session_id sid str = ''] CdpCommand | Builds Page.captureScreenshot |
page-print-to-pdf | fn [mut sess CdpSession /landscape land bool = false /print_background bg bool = true /scale sc f64 = 1.0 /session_id sid str = ''] CdpCommand | Builds Page.printToPDF |
dom-get-document | fn [mut sess CdpSession /depth d i64 = -1 /pierce p bool = false /session_id sid str = ''] CdpCommand | Builds DOM.getDocument |
dom-query-selector | fn [mut sess CdpSession, node_id i64, selector str /session_id sid str = ''] CdpCommand | Builds DOM.querySelector |
dom-get-outer-html | fn [mut sess CdpSession, node_id i64 /session_id sid str = ''] CdpCommand | Builds DOM.getOuterHTML |
runtime-evaluate | fn [mut sess CdpSession, expression str /await_promise aw bool = true /return_by_value by_val bool = true /session_id sid str = ''] CdpCommand | Builds Runtime.evaluate |
input-click | fn [mut sess CdpSession, x f64, y f64 /button btn str = 'left' /click_count cnt i64 = 1 /released rel bool = false /session_id sid str = ''] CdpCommand | Builds Input.dispatchMouseEvent |
input-type-text | fn [mut sess CdpSession, text str /session_id sid str = ''] CdpCommand | Builds Input.insertText |
network-enable | fn [mut sess CdpSession /max_total_buffer max_buf i64 = 0 /session_id sid str = ''] CdpCommand | Builds Network.enable |
network-set-extra-headers | fn [mut sess CdpSession, headers map[str] /session_id sid str = ''] CdpCommand | Builds Network.setExtraHTTPHeaders |
fetch-enable | fn [mut sess CdpSession, url_pattern str /session_id sid str = ''] CdpCommand | Builds Fetch.enable interception filter |
fetch-fulfill-request | fn [mut sess CdpSession, request_id str, response_code i64, response_headers map[str], body bytes /session_id sid str = ''] CdpCommand | Builds Fetch.fulfillRequest synthetic response |
target-attach | fn [mut sess CdpSession, target_id str /flatten flat bool = true] CdpCommand | Builds Target.attachToTarget |
compile-steps | fn [spec block] block[E2eStep] | Compiles homoiconic quote [...] automation directives |
assert-snapshot | fn [actual_html str, rules block] SnapshotReport | Validates DOM HTML against .contains, .not_contains, and .exact |
dial-cdp | fn [ws_url str /timeout deadline dur = 10s] CdpClient | Connects to a ws:// or wss:// CDP endpoint via net/websocket |
send-cdp | fn [mut client CdpClient, cmd CdpCommand /max_frames limit i64 = 128] CdpResponse | Sends a command and awaits its correlated id response |
call-cdp | fn [mut client CdpClient, method str, params map /session_id sid str = ''] CdpResponse | Encodes and sends a CDP method call directly on client |
wait-for-event | fn [mut client CdpClient, method str /session_id sid str = '' /max_frames limit i64 = 128] CdpEvent | Awaits a domain event matching method and optional session_id |
run-steps | fn [mut client CdpClient, steps block[E2eStep]] map | Executes compiled E2E steps over a live CdpClient |
close-cdp | fn [mut client CdpClient] enum | Sends WebSocket CLOSE and closes the underlying stream |
new-mock-browser | fn [] MockBrowser | Creates an in-memory mock CDP browser state |
dispatch-mock-cdp | fn [mut mb MockBrowser, raw_json str] block[str] | Processes a CDP JSON request against MockBrowser |
serve-mock-cdp-once | fn [ln any, max_commands i64] i64 | Serves mock CDP over a TCP RFC 6455 WebSocket listener |
use [cdp = browser_cdp]
mut client = cdp/dial-cdp 'ws://127.0.0.1:9222/devtools/page/MAIN'
defer [ _ = cdp/close-cdp mut client ]
enable_cmd = cdp/page-enable mut client.session
_ = cdp/send-cdp mut client enable_cmd
steps = cdp/compile-steps (quote [
.navigate 'https://veko-lang.org'
.wait_event 'Page.loadEventFired'
.expect_eval 'document.title' 'Veko Programming Language'
.screenshot 'png'
])
summary = cdp/run-steps mut client steps
os/write-bytes 'homepage.png' (map/get summary 'screenshot_bytes')https://veko-lang.org/pkg/browser_cdp/1.0.0.vkpc64a358e460db7024950e52c5d0b66598bb0d885928abc1077f95ed8695acdc1958e7d216d48f82cbe183fc3501a24ecc1ede23f6503daa45b2817b413cc1132ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70{"name":"browser_cdp","version":"1.0.0","tier":4.0,"tier_label":"Tier 4: FinTech, GraphQL, CDP & SSO","category":"Chrome DevTools & E2E Automation","description":"Chrome DevTools Protocol (CDP) JSON-RPC target multiplexer, Page/DOM/Runtime/Network automation, request mocking, and WebSocket driver.","modules":["browser_cdp"],"homepage":"https://veko-lang.org/packages/browser_cdp"}| Bundle Entry Path | Size | Leaf SHA-256 Digest |
|---|---|---|
| README.md | 8 KB | c786c8715572acd36bb39f12c09c64bbf1b245b12cfe0faa300d9eda7e011ad4 |
| examples/demo.vk | 7 KB | cb86c3464df01b129c9d919a2d2bb80c545487bb6843a73e4a87baa59a73b80d |
| mod.vk | 36 KB | b1d7e02079ecc3de0356685039bb69ccbc0c857ab086daac97f333ec43cc7811 |