Kitsune

Write a plugin

Plugins extend a session with named hooks. This example uses a record hook to tag the output for downstream processing.

Writing one

Create packages/kitsune/stamp.ts:

import { definePlugin } from './src/index.ts'

export default definePlugin({
  name: 'example:stamp',
  record: (record) => ({
    ...record,
    meta: { ...record.meta, source: 'example' },
  }),
})

From the repository root:

bun run kitsune crawl https://example.com --selector a --plugin ./stamp.ts --json

Look for "source":"example" in the record’s meta. The CLI resolves ./stamp.ts from packages/kitsune. The example uses --selector to open Chrome because record hooks run on browser and site plugin results.

Loading one

Pass plugins to Kitsune.launch({ plugins: [plugin] }) from TypeScript. With the CLI, repeat --plugin for each module or set KITSUNE_PLUGINS to a comma-separated list. Each module default-exports a plugin or a factory.

Choose a hook

  • Use setup and close for session resources.
  • Use response to observe browser attempts and record to change the final browser or site plugin result.
  • Use site when matching URLs need a custom crawl flow.

The Plugin API lists each callback, its inputs, and when it runs.