xk6-crawler
    Preparing search index...

    Interface Context

    Context provides a tiny layer for passing data between callbacks.

    For example, the Crawler.onHTML callback function puts data into the context.

    c.onHTML("a[href]", (e) => {
    // ...
    e.request.ctx.put("page_href", e.request.url);
    e.request.ctx.put("link_text", e.text);
    //...

    The Crawler.onResponse callback function reads the data previously put by the Crawler.onHTML callback from the context.

    c.onResponse((r) => {
    const page_href = r.request.ctx.get("page_href");
    // ...
    interface Context {
        get(key: string): string;
        getAny(key: string): unknown;
        put(key: string, value: unknown): void;
    }
    Index

    Methods

    Methods

    • Retrieves a string value from Context. Get returns an empty string if key not found.

      Parameters

      • key: string

        key to get

      Returns string

    • Retrieves a value from Context. GetAny returns null if key not found.

      Parameters

      • key: string

        key to get

      Returns unknown

    • Stores a value of any type in Context.

      Parameters

      • key: string

        key to store

      • value: unknown

        value to store

      Returns void