A ResourceLoader implementation for JSDOM that only allows for fetching JS files, and provides the ability to handle and modify the fetch return result.

This can be useful for various things, such as intercepting script requests to execute them in a different manner than letting the DOM use a script tag. The return result could then be an empty string rather than the full script.

The caller is responsible for maintaining script order based on call order.

A JS file request is identified by the regular expression: /^..js(?:?.)?/g

Hierarchy

  • ResourceLoader
    • ResourceLoader

Constructors

  • Create instance of the resource loader.

    Parameters

    • renderAPI: RenderAPI
    • Optional requestOptions: RequestOptions = Requests.DefaultRequestOptions

      Options that calibrate how requests are performed for this loader.

    • Optional handleFetchResult: ((result, url, options) => void | Promise<Buffer>)
        • (result, url, options): void | Promise<Buffer>
        • Parameters

          • result: void | Promise<Buffer>
          • url: string
          • options: FetchOptions

          Returns void | Promise<Buffer>

    Returns ResourceLoader

Properties

_active: boolean

Used to indicate if any pending requests are still needed so that we can report when an unused request is fulfilled.

_agents: {
    [protocol: string]: HttpAgent | HttpsAgent;
}

Type declaration

  • [protocol: string]: HttpAgent | HttpsAgent
_handleFetchResult: void | ((result, url, options) => void | Promise<Buffer>)

Type declaration

    • (result, url, options): void | Promise<Buffer>
    • Parameters

      • result: void | Promise<Buffer>
      • url: string
      • options: FetchOptions

      Returns void | Promise<Buffer>

_renderAPI: RenderAPI
_requestOptions: RequestOptions

Accessors

Methods

Generated using TypeDoc