Documentation

API reference

One result shape across server runtimes.

The root export provides preview, parseHTML, presets, URL validation helpers, and typed errors in ESM and CommonJS.

preview(url, options?)

Fetch an HTTP(S) URL, validate redirects, enforce timeout and byte limits, then extract preview metadata. Network failures propagate; invalid input and policy failures throw LinkpeekError.

Options

OptionDefaultPurpose
timeout8000Whole-request deadline in milliseconds
maxBytes30,000Maximum decoded response-body bytes retained
userAgentTwitterbot/1.0User-Agent sent to the target
followRedirectstrueValidate and follow HTTP redirects
maxRedirects10Redirect ceiling
headers{}Extra non-sensitive request headers
allowPrivateIPsfalseExplicit private-network opt-in
includeBodyContentfalseScan body JSON-LD and image fallback
followMetaRefreshfalseFollow one validated fast refresh declared in the head
signalCaller cancellation
fetchglobal fetchInject a compatible fetch implementation

Result fields

The stable result includes url, statusCode, title, description, image, siteName, favicon, canonicalUrl, author/date/language fields, video/audio URLs, Twitter fields, theme color, and an optional discovered oEmbed endpoint.

Extracted resource URLs are resolved against the document base and limited to HTTP(S).

parseHTML(html, baseUrl, options?)

Use the parser directly when HTML is already available. Default parsing stops tokenizing at the end of the head. Set includeBodyContent: true only when body JSON-LD or image fallback is worth the extra work.

Typed errors

try {
	await preview(url);
} catch (error) {
	if (error instanceof LinkpeekError) {
		console.log(error.code); // "TIMEOUT", "PRIVATE_NETWORK_BLOCKED", …
	}
}

Use code, never message matching, for program flow.