Kit API
Import Kitsune from kitsune. The tables show public TypeScript call signatures,
including inferred return types; optional arguments list their defaults in the notes.
Methods returning Promise<this> resolve to the session after the action.
import { Kitsune } from 'kitsune'
const kit = await Kitsune.launch({ headless: true })
try {
await kit.goto('https://example.com')
console.log(await kit.extract())
} finally {
await kit.close()
}Launch options
type LaunchOptions = {
proxy?: string | string[] | ProxyConfig | ProxyConfig[]
proxyPool?: ProxyPool
headless?: boolean
port?: number
profile?: string
paceMs?: number
plugins?: KitsunePlugin[]
solver?: KitsunePlugin
}
type ClickOptions = { timeoutMs?: number; force?: boolean }
type TypeOptions = { timeoutMs?: number; human?: boolean; clear?: boolean }| Option | Behavior |
|---|---|
proxy | One proxy or list, as provider strings or parsed configs. |
proxyPool | Prebuilt pool; takes precedence over proxy. One proxy is picked at launch. |
headless | Defaults to HEADLESS === '1'; otherwise headed Chrome. |
port | CDP port, default 9500. |
profile | Passed to the CDP launcher's Chrome profile option. |
paceMs | Session pacing base, default 800 ms. |
plugins | Session plugins; launch hooks run before Chrome starts, setup after launch. |
solver | Added first to the temporary launch-hook host. The live session host is built from plugins only: include this plugin there too, or call useSolver after launch. |
The session exposes readonly cdp: Cdp, readonly pace: Pace,
readonly plugins: PluginHost and readonly proxy?: ProxyConfig.
poolFrom(input?: LaunchOptions['proxy']): ProxyPool | undefined is exported
from src/kit.ts (not the package entrypoint).
Navigation
| Signature | Notes |
|---|---|
goto(url: string, opts?: { settleMs?: number }): Promise<this> | Settle defaults to 2000 ms; runs the navigate hook after navigation with status 200. |
back(): Promise<this> | Calls history.back(), then sleeps 500 ms. |
reload(settleMs?: number): Promise<this> | Navigates to the current URL; default 1500 ms. |
url(): Promise<string> | Current location.href. |
title(): Promise<string> | Document title. |
readyState(): Promise<string> | Document readiness string. |
Waiting
| Signature | Notes |
|---|---|
waitFor(selector: string, timeoutMs?: number): Promise<boolean> | CSS selector existence; default 15000 ms. |
waitForText(needle: string, timeoutMs?: number): Promise<boolean> | Body substring; default 15000 ms, polls every 250 ms. |
waitForExpression(expression: string, timeoutMs?: number): Promise<boolean> | In-page predicate; default 15000 ms. |
waitForNetworkIdle(quietMs?: number, timeoutMs?: number): Promise<boolean> | Defaults 800, 15000 ms; polls the resource timing entry count, not active network requests. |
waitForActionable(selector: string, opts?: ActionableOptions): Promise<ActionableResult> | Reports the failing gate rather than throwing an action timeout. |
The boolean waits return false on timeout. Evaluation errors can still reject.
Actionability types are defined in src/interact/actionable.ts:
type Gate = 'attached' | 'visible' | 'stable' | 'enabled' | 'editable' | 'unobscured'
type RequiredGate = Exclude<Gate, 'attached'>
type ActionableOptions = { timeoutMs?: number; require?: RequiredGate[]; pollMs?: number }
type Box = { x: number; y: number; width: number; height: number }
type ActionableResult =
| { ok: true; box: Box; elapsedMs: number }
| { ok: false; reason: string; gate: Gate; elapsedMs: number }waitForActionable defaults to timeoutMs: 30000, require: [], pollMs: 100.
Attached is always checked. Visible requires a nonempty box and visible styles;
stable compares rectangles across animation frames; enabled rejects disabled
and aria-disabled controls; editable also checks field/contenteditable and
readonly state; unobscured hit-tests the center.
Interaction
| Signature | Notes |
|---|---|
click(selector: string, opts?: ClickOptions): Promise<this> | Default timeout 10000 ms. |
hover(selector: string, timeoutMs?: number): Promise<this> | Default 10000 ms. |
type(selector: string, value: string, opts?: TypeOptions): Promise<this> | Defaults: timeout 10000 ms, human: true, clear: true. |
fill(fields: Record<string, string>, opts?: TypeOptions): Promise<this> | Sequentially calls type for each selector/value pair. |
focus(selector: string, timeoutMs?: number): Promise<this> | Default 10000 ms; clicks the center if available, otherwise calls DOM focus(). |
press(key: keyof typeof KEYS | string): Promise<this> | KEYS is the internal key map described below. |
select(selector: string, value: string, opts?: { timeoutMs?: number }): Promise<this> | Default 10000 ms; waits for enabled and, for native selects, the option value. |
check(selector: string, checked?: boolean, opts?: { timeoutMs?: number }): Promise<this> | Defaults true, 10000 ms; waits for enabled and the requested checked state. |
scroll(y: number, settleMs?: number): Promise<this> | Absolute vertical position; default settle 300 ms. |
scrollToBottom(step?: number): Promise<this> | Default step 600; uses the initial body height and scrolls in increments. |
Input uses real CDP mouse/key events. press recognizes Enter, Tab, Escape,
Backspace, ArrowDown and ArrowUp, and accepts other key strings.
select sets the value and dispatches input/change events. check uses a trusted
click for a visible, stable, unobscured input, with DOM click() as a fallback
for custom or hidden controls.
click, type, hover, fill, upload, select and check poll actionability
and re-resolve stale nodes during hydration, within the action's timeout:
| Action | Gates beyond attached |
|---|---|
click | visible, stable, enabled, unobscured |
hover | visible, stable, unobscured |
type, fill | visible, stable, editable (includes enabled), unobscured |
upload, select, check | enabled; hidden native controls are allowed |
click({ force: true }) skips stable/enabled/unobscured gates and the dispatch
hit test, but still requires attached and visible, verifies position, and silently
returns on failure. Other interaction options do not accept force.
Typing focuses the verified node before sending keys, then re-queries the live
input/textarea to verify its value. If the value differs, it uses the native value
setter and dispatches input/change events. This fallback writes exactly value,
even if clear: false initially allowed keys to append. select retries until
its option exists; check polls after clicking and retries until the desired
state holds or the action times out.
Primitives
| Signature | Notes |
|---|---|
drag(fromSel: string, toSel: string): Promise<this> | CDP mouse drag over 16 steps. |
upload(selector: string, paths: string[], opts?: { timeoutMs?: number }): Promise<this> | Default 10000 ms; resolves file paths from the process working directory. |
enableDownloads(dir: string): Promise<this> | Creates/resolves the directory and enables Chrome download events. |
waitForDownload(timeoutMs?: number): Promise<Download> | Default 30000 ms; rejects unless downloads were enabled, on cancellation, timeout or close. |
cookies(url?: string): Promise<StoredCookie[]> | Optional URL filter. |
setCookie(cookie: Cookie): Promise<this> | Throws if Chrome rejects the cookie. |
clearCookies(): Promise<this> | Deletes all cookies, including other origins/paths. |
frame(urlPart: string): Promise<Frame> | First frame whose URL contains the substring. |
withFrame<T>(urlPart: string, fn: (frame: Frame) => T | Promise<T>): Promise<T> | Runs the callback in the matching frame. |
inFrame(selector: string): Promise<Frame> | Finds a document containing the selector, including cross-origin frames. |
route(pattern: string, handler: RouteHandler): Promise<this> | CDP URL pattern with *, ? and backslash escaping. Last matching registration wins. |
unroute(pattern: string): Promise<this> | Removes a pattern. |
evaluate<T = any>(expression: string): Promise<T> | Arbitrary expression in the page. |
box(selector: string, timeoutMs?: number): Promise<{ x: number; y: number } | null> | Default 10000 ms; scrolls to the element and returns its center, or null. |
Upload delivers through DOM.setFileInputFiles to the verified node handle's
nodeId, then checks that the node remained attached. It retries replacement
races instead of re-querying a selector at delivery time.
The following support types live in src/interact and are not re-exported from
the package entrypoint:
type Download = {
guid: string; state: 'completed'; totalBytes: number
receivedBytes: number; filePath?: string
}
type Cookie = {
name: string; value: string; url?: string; domain?: string; path?: string
secure?: boolean; httpOnly?: boolean; sameSite?: 'Strict' | 'Lax' | 'None'
expires?: number; priority?: 'Low' | 'Medium' | 'High'; sameParty?: boolean
sourceScheme?: 'Unset' | 'NonSecure' | 'Secure'; sourcePort?: number
partitionKey?: { topLevelSite: string; hasCrossSiteAncestor: boolean }
}
type StoredCookie = Cookie & {
domain: string; path: string; expires: number; size: number; session: boolean
}
type FulfilOptions = { status?: number; body?: string; headers?: Record<string, string> }
type Route = {
request: { url: string; method: string; headers: Record<string, string>; postData?: string }
resourceType: string
continue(overrides?: {
url?: string; method?: string; postData?: string
headers?: { name: string; value: string }[]
}): Promise<void>
fulfil(options: FulfilOptions): Promise<void>
abort(reason?: string): Promise<void>
fail(reason?: string): Promise<void>
}
type RouteHandler = (route: Route) => void | Promise<void>Routes continue automatically if the handler does not handle them. Fulfil defaults
to status 200, empty body and headers; abort defaults to Aborted, fail to
Failed. Interception covers the page, not attached frame sessions.
Frame exposes readonly id, url, sessionId strings,
evaluate<T = any>(expression: string): Promise<T> and
click(selector: string): Promise<this>; its click does not use the kit's actionability loop.
Reading
| Signature | Notes |
|---|---|
html(): Promise<string> | Document outer HTML. |
bodyText(): Promise<string> | Body inner text, or empty string. |
text(selector: string): Promise<string> | Normalized text. Declared/inferred as string, but the page expression returns null when absent. |
texts(selector: string, limit?: number): Promise<string[]> | Normalized text list; default limit 200. |
attr(selector: string, name: string): Promise<string | null> | Attribute or null. |
href(selector: string): Promise<string | null> | Element's href property or null when absent. |
exists(selector: string): Promise<boolean> | Selector exists. |
query(spec: SelectorSpec): Promise<any> | Field map; object or rows when each is set. |
extract(): Promise<AutoExtract> | Automatic structured extraction. |
screenshot(file?: string): Promise<string> | Writes PNG and returns the path; default ${Bun.cwd}/kitsune-${Date.now()}.png. Does not create parent directories. |
type SelectorSpec = {
fields: Record<string, string>
each?: string
attr?: Record<string, 'text' | 'href' | 'src' | 'value'>
}
type AutoExtract = {
title: string
lang: string | null
canonical: string | null
description: string | null
og: Record<string, string>
headings: { tag: string; text: string }[]
text: string
links: { href: string; text: string }[]
tables: string[][][]
jsonLd: any[]
appState: Record<string, any>
forms: any[]
readyState: string
}Selector reads default to text; missing elements return null. :scope addresses
the repeating row itself. Auto extraction includes up to 200000 text characters,
2000 links, 20 tables (200 rows each), 60 headings and 10 forms.
Records
| Signature | Notes |
|---|---|
crawl(url: string, opts?: Partial<CrawlInput>): Promise<Record_> | HTTP → browser → extraction fallback, or site plugin takeover. Does not persist the result. |
verdict(): Promise<Detection> | Extracts and classifies the current page with status 200. |
type CrawlInput = {
url: string
value?: string
recipe?: Recipe
pace: Pace
allowHttp?: boolean
maxAttempts?: number
settleMs?: number
timeoutMs?: number
proxy?: string
plugins?: PluginHost
kit?: PluginApi
}
type Detection = { verdict: Verdict; reason: string; matched?: string }crawl supplies the session's URL, pace, proxy URL, host and plugin API before
spreading opts, so explicit options can override those defaults. Defaults are
HTTP allowed, 3 browser attempts, and 2500 ms settle plus 2000 ms per retry;
timeoutMs is passed to HTTP. Recipes can force browser use, fill/submit a query,
and select auto/selectors/js/json extraction. Empty selectors fall back to auto.
See Result records for the record schema and tiers.
Lifecycle
| Signature | Notes |
|---|---|
Kitsune.launch(opts?: LaunchOptions): Promise<Kitsune> | Starts Chrome and prepares plugins. |
context(): PluginContext | Live plugin context, including the launch proxy and logger. |
use(plugin: KitsunePlugin): Promise<this> | Registers a plugin and immediately runs its setup. Launch hooks cannot affect an already running browser. |
useSolver(plugin: KitsunePlugin): Promise<this> | Selects a solver and immediately runs its setup. |
close(): Promise<void> | Reverse plugin teardown, interception/download/frame/DOM cleanup, then CDP close. |
The Kitsune browser session, interaction methods, extraction and crawl options.