brw
Browser automation and web scraping - Playwright/Puppeteer-style API for navigating pages, clicking, filling forms, waiting for elements, taking screenshots, evaluating JavaScript, handling events, managing cookies, emulating mobile devices, and running accessibility checks.
Load with: use brw
What this module does
brw provides a full browser automation API backed by host natives
(__brw_*) that wrap a headless browser engine. The ilusm layer gives
every operation a clean function name and sensible defaults for timeouts,
wait states, and options.
Use cases include end-to-end testing, web scraping, screenshot capture, PDF generation, request interception, and accessibility auditing.
Quick example
use brw
# Create a browser context and open a page
b = brwne({hdls: fls})
pg = brwp1(b, nil)
# Navigate to a URL
brwgt(pg, "https://example.com", nil)
# Get the page title
prn(brwtt(pg))
# Click a button and fill a form
brwc3(pg, "#submit-btn", nil)
brwf1(pg, "input[name=email]", "test@example.com", nil)
# Wait for a result element
brwwt(pg, ".result", nil)
# Take a screenshot
brwss(pg, "screenshot.png", nil)
# Close
brwpg(pg)
brwcl(b)
Functions
Browser context
brwne(opts)
Creates a browser context via __brw_ctx_new. opts.hdls enables/disables headless mode. Default timeout: 30000 ms.
brwcl(b)
Closes all open pages and then the browser context.
brwc2(b)
Opens a new incognito context within the browser.
brwct(ctx)
Closes an incognito context.
Pages
brwp1(b, url)
Opens a new page. url defaults to "about:blank" if nil. Returns a page object.
brwpg(pg)
Closes a page.
brwgt(pg, url, opts)
Navigates to a URL. Options: to (timeout ms, default 30000), wt (wait until, default "load").
brwrl(pg) / brwbc(pg) / brwfw(pg)
Reload, navigate back, or navigate forward.
brwr0(pg) / brwtt(pg)
Get the current URL or page title.
Interaction
brwc3(pg, selector, opts)
Clicks an element matching selector. Options: btn (button, default "left"), dbl (double-click, default fls), mod (modifier keys).
brwf1(pg, selector, text, opts)
Fills an input element. Options: clr (clear first, default tru), dly (delay between keystrokes).
brwty(pg, text, opts)
Types text into the currently focused element. Option: dly (delay ms between chars).
brwhv(pg, selector) / brwfc(pg, selector)
Hover over or focus an element.
Element selection and properties
brwsl(pg, selector)
Returns the first element matching the CSS selector.
brwll(pg, selector)
Returns all elements matching the CSS selector.
brwt2(el) / brwh1(el) / brwsr(el) / brwv1(el)
Get the text content, href, src, or value of an element.
brwt1(el, name) / brwpr(el, name) / brwst(el, name)
Get an attribute, property, or computed style value by name.
brwc1(el) / brwf0(el, v) / brwsc(el)
Click, fill, or scroll an element directly.
Waiting
brwwt(pg, selector, opts)
Waits for an element matching selector. Option st controls the wait state (default "visible").
brww0(pg, opts)
Waits for navigation to complete.
brww1(pg, fn, opts)
Waits for a custom JavaScript condition function to return truthy.
Screenshots and PDF
brwss(pg, path, opts)
Captures a screenshot. Options: tp (type, default "png"), full (full page, default fls), clip (clip region).
brws0(el, path)
Screenshot of a single element.
brwpd(pg, path, opts)
Saves the page as a PDF.
Content extraction
brwh2(pg) / brwtx(pg)
Gets the full HTML or plain-text content of the page.
brwtb(pg, selector)
Extracts a table as a list-of-lists by evaluating JavaScript on the matching element.
brwln(pg)
Returns all links as {t: text, h: href} objects.
brwmg(pg)
Returns all image src URLs on the page.
JavaScript, frames, events
brwv0(pg, script, args)
Evaluates a JavaScript expression and returns the result.
brwvl(pg, script, args)
Evaluates JavaScript and returns a handle.
brwfr(pg, selector)
Gets an iframe element by selector.
brnld(pg, fn) / brnnv(pg, fn) / brnrq(pg, fn) / brnrs(pg, fn)
Subscribe to page events: load, frame navigation, request, response.
brncn(pg, fn) / brndl(pg, fn)
Subscribe to console messages or dialog events.
Cookies, storage, auth
brwdd(pg, cookie) / brwc0(pg) / brwck(pg, url)
Add, clear, or get cookies.
brwl1(pg, key, val) / brwl0(pg, key) / brwls(pg, key)
Set, get, or delete localStorage values (JSON serialised).
brwht(pg, user, password)
Sets HTTP Basic Auth credentials.
Mobile, keyboard, mouse
brwmb(pg, device)
Emulates a mobile device by name.
brwgo(pg, lat, lon, acc)
Overrides geolocation.
brwk1(pg, key, opts) / brwky(pg, key) / brwk0(pg, key)
Press, keydown, or keyup a key.
brwmv(pg, x, y) / brwdw(pg, btn) / brwup(pg, btn)
Move the mouse, press a button down, or release it.
Testing, accessibility, performance
brwxp(el)
Returns an expect object for an element with matchers: tobev() (visible), tobeen() (enabled), tobechecked(), tohavetxt(t), tohaveval(v), tohaveattr(a,v), tohavecls(c).
brwsn(pg)
Takes an accessibility tree snapshot.
brw11(pg)
Runs an accessibility audit.
brwp0(pg) / brwmt(pg)
Get performance timing (JSON string) or page metrics.
brwcd(pg, method, params)
Send a raw Chrome DevTools Protocol command.
Notes
- All functions delegate to
__brw_*host natives - the runtime must provide a browser engine binding. - Default timeout is 30000 ms unless overridden in
opts.to. - Request interception uses
brnrt(pg, url_pattern, fn); unregister withbrwnr. - Requires
trl,txt, andjsn.