Kitsune

Automate browser actions

Use the browser methods when a page needs input before it shows the data you want. This example works with a self-contained page.

Fill and submit a form

After setting up Kitsune, save this as browser.ts at the repository root:

import { Kitsune } from 'kitsune'

const page = `
  <form onsubmit="event.preventDefault(); document.querySelector('output').textContent = this.elements.name.value">
    <label>Name <input name="name"></label>
    <button type="submit">Show result</button>
  </form>
  <output></output>
`

const kit = await Kitsune.launch()

try {
  await kit.goto('data:text/html,' + encodeURIComponent(page))
  await kit.type('input[name="name"]', 'Kitsune')
  await kit.click('button[type="submit"]')

  if (!(await kit.waitForText('Kitsune', 5_000))) {
    throw new Error('The form did not show a result')
  }

  console.log(await kit.text('output'))
} finally {
  await kit.close()
}

Run bun run browser.ts. It prints Kitsune after the form updates.

Wait for a result

goto() waits for the page load event, then settles for two seconds by default. For content that appears after an action, use waitFor(selector) or waitForText(text). Both return false on timeout, so check the return value before reading.

The error

Before an action like click() or type(), Kitsune checks that the element can receive input. If it times out, the error gives the selector and the check that failed, such as visible, enabled, or unobscured. Inspect the matching element in Chrome and check for overlays or disabled controls.

See the Kitsune API for screenshots, files, frames, and other browser methods.