sema-browser 0.1.0

API reference · 84 exports

Source declarations and literal docstrings from this release. Package code was not executed.

browser/close!

(browser/close! b)
Close the browser and release its process.

Source: package.sema:108

browser/connect

(browser/connect url)
Attach to an already-running browser by its devtools address — see cdp/connect.

Source: package.sema:104

browser/context-page

(browser/context-page b context-id)
Open a new page inside a browser context from browser/new-context!. Pages in the same context share cookies and storage.

Source: package.sema:138

browser/devices

(browser/devices)
List the device preset names usable with page/emulate-device!.

Source: package.sema:1131

browser/dispose-context!

(browser/dispose-context! b context-id)
Dispose a browser context, closing its pages and discarding its state.

Source: package.sema:144

browser/incognito-page

(browser/incognito-page b)
Open a page in a fresh incognito browser context — isolated cookies and storage, discarded when the browser closes.

Source: package.sema:149

browser/launch

(browser/launch . opts-rest)
Launch a browser and return it. Options map: :headless (default #t), :chrome, :args, :user-data-dir — see cdp/launch.

Source: package.sema:100

browser/new-context!

(browser/new-context! b)
Create an isolated incognito browser context (own cookies and storage) and return its id. Open pages in it with browser/context-page.

Source: package.sema:134

browser/page

(browser/page b)
Open a new tab and return a page. The page doubles as a cdp session, so (cdp/send page ...) reaches the whole protocol.

Source: package.sema:112

browser/pages

(browser/pages b)
Attach to every already-open tab and return them as pages, in target order. Useful after browser/connect to drive an existing session.

Source: package.sema:129

browser/version

(browser/version b)
Return browser version info: :product, :userAgent, :protocolVersion, ...

Source: package.sema:153

browser/with-page

(browser/with-page f-or-opts . f-rest)
Launch a browser, open a page, call f with it, and always close the browser. (browser/with-page f) or (browser/with-page opts f). Returns f's result.

Source: package.sema:157

page/add-init-script!

(page/add-init-script! pg js)
Run js in every new document before any page script — polyfills, flags, stubs. Applies from the next navigation. Returns an identifier.

Source: package.sema:881

page/attr

(page/attr pg sel name . opts-rest)
Return an attribute value of the element matching sel (nil if absent), auto-waiting for the element. Options: :timeout ms.

Source: package.sema:415

page/authenticate!

(page/authenticate! pg username password)
Answer HTTP basic/proxy auth challenges with these credentials. Returns an interceptor id for page/stop-intercept!. Owns the Fetch domain like page/on-request! — the two are mutually exclusive until stopped. A challenge the credentials already failed once is cancelled rather than re-answered, so a wrong password fails instead of looping.

Source: package.sema:1281

page/back

(page/back pg)
Go back one entry in the page's history, waiting for the load.

Source: package.sema:802

page/block!

(page/block! pg patterns)
Block every request whose URL contains any of the given substrings; everything else continues. Returns an interceptor id for page/stop-intercept!.

Source: package.sema:1272

page/bounding-box

(page/bounding-box pg sel . opts-rest)
Return the element's bounding box in main-viewport coordinates: {:x :y :width :height}. Auto-waits for the element to be visible. Options: :timeout ms.

Source: package.sema:665

page/check

(page/check pg sel . opts-rest)
Ensure the checkbox/radio matching sel is checked (clicks only when needed). Options: :timeout ms.

Source: package.sema:607

page/clear-console!

(page/clear-console! pg)
Drop the recorded console messages and page errors.

Source: package.sema:910

page/clear-cookies!

(page/clear-cookies! pg)
Delete all browser cookies.

Source: package.sema:966

page/click

(page/click pg sel . opts-rest)
Click the element matching sel with a real mouse event, auto-waiting until it is visible and enabled. Options: :timeout ms, :button (:left default, :right, :middle), :click-count, :modifiers (["Shift" "Meta" ...]).

Source: package.sema:473

page/click-ref

(page/click-ref pg ref)
Click the element behind a [ref=eNNN] handle from page/snapshot.

Source: package.sema:1409

page/clipboard-read

(page/clipboard-read pg)
Read the clipboard's text (grants the permission). Requires a secure context — localhost or https, not data: URLs.

Source: package.sema:1110

page/clipboard-write!

(page/clipboard-write! pg text)
Write text to the clipboard (grants the permission). Requires a secure context — localhost or https, not data: URLs.

Source: package.sema:1103

page/close!

(page/close! pg)
Close the page's tab.

Source: package.sema:124

page/console

(page/console pg)
Return console messages and uncaught errors recorded since page/track-console!, as {:type :text}, oldest first.

Source: package.sema:905

page/cookies

(page/cookies pg)
Return the cookies visible to the page as maps with :name, :value, :domain, :path, :expires, :httpOnly, :secure.

Source: package.sema:951

page/count

(page/count pg sel)
Return how many elements match sel right now — does not wait.

Source: package.sema:407

page/dblclick

(page/dblclick pg sel . opts-rest)
Double-click the element matching sel. Options as page/click.

Source: package.sema:479

page/downloads-to!

(page/downloads-to! pg dir)
Send this browser's downloads to dir (created if missing) and enable download events for page/wait-for-download.

Source: package.sema:923

page/drag

(page/drag pg from-sel to-sel . opts-rest)
Drag from one element's center to another's with real mouse events (press, move in steps, release). Options: :steps (default 10), :timeout ms.

Source: package.sema:631

page/emulate-device!

(page/emulate-device! pg name)
Emulate a device preset by name — viewport, scale, mobile flag, and User-Agent. See browser/devices for the names.

Source: package.sema:1135

page/eval

(page/eval pg js)
Evaluate a JS expression in the page (promises awaited) and return its value as data. Raises if the page throws.

Source: package.sema:290

page/eval-in-frame

(page/eval-in-frame pg frame-id js)
Evaluate a JS expression inside a specific frame by id (see page/frames) and return its value. Runs in an isolated world, so it sees the frame's DOM but not its page-script variables.

Source: package.sema:1204

page/exists?

(page/exists? pg sel)
Return whether any element matches sel right now — does not wait.

Source: package.sema:411

page/fill

(page/fill pg sel text . opts-rest)
Focus the element matching sel and replace its contents with text (real text-input events). Works on inputs, textareas, and contenteditable. Options: :timeout ms.

Source: package.sema:519

page/fill-ref

(page/fill-ref pg ref text)
Fill the element behind a [ref=eNNN] handle from page/snapshot.

Source: package.sema:1413

page/focus

(page/focus pg sel . opts-rest)
Focus the element matching sel. Options: :timeout ms.

Source: package.sema:495

page/forward

(page/forward pg)
Go forward one entry in the page's history, waiting for the load.

Source: package.sema:806

page/frame

(page/frame pg spec)
Return a frame handle for the child frame whose id, name, or URL (substring) matches spec. The handle works like a page for selector actions, page/eval, page/text, page/click, page/fill, page/snapshot, refs, ... — all scoped to that frame. Cross-origin frames that Chrome isolates into their own process (OOPIFs) are not in this page's tree; adopt those via browser/pages.

Source: package.sema:1195

page/frames

(page/frames pg)
List the page's frames as maps with :id, :url, :name, :parent (nil for the main frame).

Source: package.sema:1186

page/goto

(page/goto pg url . opts-rest)
Navigate to url and wait for it. Options: :timeout ms (default 30000), :wait-until (:load default, :domcontentloaded, or :networkidle — no in-flight requests for 500ms).

Source: package.sema:772

page/hover

(page/hover pg sel . opts-rest)
Move the mouse over the element matching sel (fires mouseover/mouseenter). Options: :timeout ms.

Source: package.sema:485

page/html

(page/html pg)
Return the page's full HTML (document.documentElement.outerHTML).

Source: package.sema:393

page/on-dialog!

(page/on-dialog! pg action . prompt-rest)
Auto-respond to alert/confirm/prompt dialogs: action is :accept or :dismiss, with an optional prompt-text answer for prompt(). Registers a handler; returns its id (cdp/off! to remove). Without a handler an open dialog blocks the page's JS.

Source: package.sema:973

page/on-request!

(page/on-request! pg handler)
Intercept every request the page makes. The handler receives {:url :method :resource-type :headers :request-id} and returns :continue (or nil) to let it through, :abort to block it, {:fulfill {:status :headers :body}} to answer it without the network, or {:continue {:url :method :headers :post-data}} to rewrite it. Returns an interceptor id for page/stop-intercept!. One interceptor per page — stop the old one first.

Source: package.sema:1253

page/pdf

(page/pdf pg . opts-rest)
Print the page to PDF (headless only). Returns the bytes, or writes to :path and returns the path. Options: :path, :landscape #t, :scale (0.1-2), :page-ranges ("1-3").

Source: package.sema:1337

page/press

(page/press pg sel key . opts-rest)
Focus the element matching sel and press a key or chord: "Enter", "Tab", "Escape", arrows, any single character, or with modifiers ("Control+a", "Meta+Shift+r"). Options: :timeout ms.

Source: package.sema:584

page/reload

(page/reload pg . opts-rest)
Reload the page and wait for it. Options: :ignore-cache #t for a hard reload, :timeout ms, :wait-until (as page/goto).

Source: package.sema:810

page/requests

(page/requests pg)
Return the responses recorded since page/track-network! as maps with :url, :status, :mime-type, :type, :request-id — oldest first.

Source: package.sema:999

page/response-body

(page/response-body pg request-id)
Return the body of a recorded response by its :request-id (from page/requests or page/wait-for-response). Text bodies come back as a string, binary ones as a bytevector. Requires page/track-network!, and the body must still be held by the browser (it is dropped on navigation). Retries briefly while the response is still streaming.

Source: package.sema:1015

page/screenshot

(page/screenshot pg . opts-rest)
Capture a screenshot as PNG bytes. Options: :path (write to file and return the path instead), :format ("png" default, "jpeg", "webp"), :quality (0-100, jpeg/webp), :full-page (capture beyond the viewport), :selector (capture just that element).

Source: package.sema:1317

page/scroll

(page/scroll pg dx dy . opts-rest)
Scroll with a mouse-wheel event: positive dy scrolls down. Options: :selector (wheel over that element instead of the viewport center), :timeout ms.

Source: package.sema:615

page/select

(page/select pg sel value . opts-rest)
Set a <select> and fire input/change events. `value` is an option value string, a list of values (multi-select), or {:label "visible text"}. Non-select elements get their value assigned directly. Options: :timeout ms.

Source: package.sema:691

page/set-content

(page/set-content pg html)
Replace the page's document with the given HTML string.

Source: package.sema:823

page/set-cookie!

(page/set-cookie! pg cookie)
Set one cookie. Map keys: :name and :value (required), plus :url or :domain, :path, :expires (unix seconds), :httpOnly, :secure, :sameSite. Raises when the browser rejects it.

Source: package.sema:955

page/set-cpu-throttle!

(page/set-cpu-throttle! pg rate)
Slow the page's CPU by a factor (2 = half speed). 1 restores full speed.

Source: package.sema:1058

page/set-geolocation!

(page/set-geolocation! pg latitude longitude . opts-rest)
Override geolocation (and grant the permission). Options: :accuracy meters (default 1).

Source: package.sema:865

page/set-media!

(page/set-media! pg opts)
Emulate media features: {:color-scheme "dark"|"light"} for prefers-color-scheme, {:media "print"} for print styles, {:reduced-motion "reduce"}. Pass {} to reset.

Source: package.sema:844

page/set-offline!

(page/set-offline! pg offline)
Emulate being offline (#t) or restore connectivity (#f).

Source: package.sema:857

page/set-timezone!

(page/set-timezone! pg timezone-id)
Override the page's timezone, e.g. "Europe/Oslo" or "America/New_York".

Source: package.sema:874

page/set-user-agent!

(page/set-user-agent! pg ua)
Override the page's User-Agent string for subsequent requests.

Source: package.sema:839

page/set-viewport!

(page/set-viewport! pg width height . opts-rest)
Emulate a viewport of width x height CSS pixels. Options: :scale (deviceScaleFactor, default 1), :mobile #t.

Source: package.sema:830

page/snapshot

(page/snapshot pg)
Render the page's accessibility tree as compact text, one node per line with a [ref=eNNN] handle usable with page/click-ref and page/fill-ref. On a frame handle, renders that frame's tree.

Source: package.sema:1393

page/start-js-coverage!

(page/start-js-coverage! pg)
Start collecting JS coverage; navigate/run the code, then read it with page/stop-js-coverage.

Source: package.sema:1063

page/start-screencast!

(page/start-screencast! pg dir)
Record the page as numbered PNG frames into dir (created if missing) until page/stop-screencast!. Frames arrive while commands run — use (cdp/pump pg ms) to capture during idle stretches. Returns a handle for page/stop-screencast!.

Source: package.sema:1150

page/stop-intercept!

(page/stop-intercept! pg interceptor-id)
Remove an interceptor from page/on-request!, page/block!, or page/authenticate! (a single id or a list of ids) and stop intercepting.

Source: package.sema:1308

page/stop-js-coverage

(page/stop-js-coverage pg)
Stop coverage collection and return per-script {:url :used-bytes :total-bytes} (byte counts are an approximation from executed function ranges).

Source: package.sema:1089

page/stop-screencast!

(page/stop-screencast! pg handle)
Stop a screencast from page/start-screencast! and return the written frame paths, in order.

Source: package.sema:1166

page/text

(page/text pg sel . opts-rest)
Return the innerText of the element matching sel, auto-waiting for it to be attached. Options: :timeout ms.

Source: package.sema:397

page/texts

(page/texts pg sel)
Return the innerText of every element matching sel, in document order. Empty list when nothing matches — does not wait.

Source: package.sema:403

page/title

(page/title pg)
Return the page's document title.

Source: package.sema:389

page/track-console!

(page/track-console! pg)
Start recording console output and uncaught page errors; read them with page/console.

Source: package.sema:885

page/track-network!

(page/track-network! pg)
Start recording the page's network traffic (enables the Network domain). Events accumulate while commands run; read them with page/requests.

Source: package.sema:986

page/type

(page/type pg sel text . opts-rest)
Focus the element matching sel and type text character by character with real key events — for pages reacting to each keystroke (autocomplete, masked inputs). Appends; use page/fill to replace. Options: :timeout ms.

Source: package.sema:591

page/uncheck

(page/uncheck pg sel . opts-rest)
Ensure the checkbox matching sel is unchecked (clicks only when needed). Options: :timeout ms.

Source: package.sema:611

page/upload

(page/upload pg sel paths . opts-rest)
Set the files of an <input type=file> matching sel. `paths` is a list of absolute file paths (or one path). Options: :timeout ms.

Source: package.sema:678

page/url

(page/url pg)
Return the page's current URL.

Source: package.sema:385

page/wait-for

(page/wait-for pg sel . opts-rest)
Wait until the element matching sel reaches a state. Options: :state (:visible default, :attached, :hidden, :detached), :timeout ms (default 30000).

Source: package.sema:354

page/wait-for-download

(page/wait-for-download pg . opts-rest)
Wait for the next download to finish and return {:path :filename :url}. Call page/downloads-to! first, then trigger the download (a click, a goto). Options: :timeout ms.

Source: package.sema:931

page/wait-for-function

(page/wait-for-function pg js . opts-rest)
Poll a JS expression until it is truthy and return its value. Options: :timeout ms (default 30000), :interval ms (default 100).

Source: package.sema:359

page/wait-for-response

(page/wait-for-response pg url-part . opts-rest)
Wait for a response whose URL contains url-part and return it as a map (see page/requests). Requires page/track-network!. Options: :timeout ms.

Source: package.sema:1005

page/websocket-frames

(page/websocket-frames pg)
Return WebSocket frames recorded since page/track-network! as {:url :direction (:sent or :received) :opcode :payload}, oldest first.

Source: package.sema:1034