The configuration for freeze-dry.

The configuration is set by the options passed to freezeDry or FreezeDryer.

Hierarchy

  • FreezeDryConfig

Output options

addMetadata: boolean

Whether to note the snapshotting time and the document's URL in an extra meta and link tag.

Default Value

true

rememberOriginalUrls: boolean

Whether to preserve the value of an element attribute if its URLs are inlined, by noting it as a new data-original-... attribute. For example, <img src="bg.png"> would become <img src="data:..." data-original-src="bg.png">. Note this is an unstandardised workaround to keep URLs of subresources available; unfortunately URLs inside stylesheets are still lost.

now: Date

Override the snapshot time (only relevant when addMetadata is true). Mainly intended for testing purposes.

contentSecurityPolicy: null | ContentSecurityPolicy

Add a <meta> tag with the given content security policy to the snapshot. The default value only allows loading inline resources and data: URLs, no external resources.

charsetDeclaration: null | string

The value put into the <meta charset="…"> element of the snapshot.

If you will store/serve the returned string using an encoding other than UTF8, pass its name here; or pass null or an empty string to omit the declaration altogether.

Default Value

'utf-8'

Subresource options

timeout: number

Maximum time (in milliseconds) spent on fetching the page’s subresources. The resulting HTML will have only succesfully fetched subresources inlined.

Default Value

Infinity

signal?: AbortSignal

Signal to abort subresource fetching at any moment. As with timeout, the resulting HTML will have only succesfully fetched subresources inlined.

fetchResource?: Fetchy

Custom function for fetching resources; should be API-compatible with the global fetch(), but may also resolve to an object { blob, url } instead of a Response.

This option is ignored if a custom processSubresource is given.

For aborting to work (e.g. via the timeout or signal options), this callback must respect its signal parameter.

dryResource: DryResourceCallback

Transformations to apply on the document and each subresource.

To also perform the default transformations, make this callback run resource.dry().

This option is ignored if a custom processSubresource is given.

newUrlForResource: NewUrlForResourceCallback

Callback to determine the replacement URL for a (processed, dried) subresource; defaults to creating a data: URL.

This option is ignored if a custom processSubresource is given.

processSubresource: ProcessSubresourceCallback

Callback invoked for each of doc’s subresources.

The default behaviour is to recursively fetch and ‘dry’ subresources and turn each into a data: URL. Those individual steps can be customised by the other subresource handling options: fetchResource, dryResource, and newUrlForResource.

If those options are not flexible enough, a completely custom processResource might be a solution. Other subresource handling options are then ignored.

Example

This is a simplification of what the default freezeDry implementation does (assuming other options are kept at their defaults too):

async processSubresource(link, recurse) {
link.resource ||= await Resource.fromLink(link) // fetch the subresource
await link.resource.processSubresources(recurse) // recurse into its links
await link.resource.dry() // dry the subresource
link.target = blobToDataUrl(link.resource.blob) // inline its content in the link
}

Other options

docUrl?: `${string}:${string}`

URL to override doc.URL.

Its value will influence the expansion of relative URLs, and is useful for cases where the document was constructed dynamically (e.g. using DOMParser).

glob?: typeof globalThis

Overrides the object providing global DOM interfaces (instead of globalThis/window). Only relevant when freezeDry is not run ‘in’ but ‘on’ a DOM (e.g. in NodeJS on JSDOM).