Skip to content

Documentation

JavaScript SDK: KeyValue: crawl state

ctx.state() stores a small crawl cursor, such as the next page number. Reads and writes are asynchronous; it is not a product database.

Each example is a separate fragment inside async function run(ctx). Use await only for methods whose signature returns a Promise.

Methods

get

ctx.state().get(key, fallback = null) → Promise<unknown>

Read a saved state value. If the key does not exist yet, the method returns fallback.

const result = await ctx.state().get('page', 1);

set

ctx.state().set(key, value) → Promise<void>

Save a state value to resume traversal later.

await ctx.state().set('page', 2);

incr

ctx.state().incr(key, by) → Promise<number>

Increase an integer state counter.

const result = await ctx.state().incr('page');