@molecule/api-web-content-readability

Provider bond · web-content · API (Node) · v1.1.3 · Apache-2.0

Mozilla Readability web content provider for molecule.dev — fetch a page or extract readable content in this process

npm install @molecule/api-web-content-readability

npm · Source on GitHub · Implements @molecule/api-web-content

How it works

@molecule/api-web-content-readability is a provider bond on the API (Node) side: it implements the web-content core interface (@molecule/api-web-content) with a concrete vendor or library behind it.

Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.

Works with: @molecule/api-web-content

Reference

Mozilla Readability web content provider for molecule.dev — fetch a page or extract readable content in this process

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Type

provider

Installation

npm install @molecule/api-web-content-readability @molecule/api-web-content @mozilla/readability jsdom turndown turndown-plugin-gfm
npm install -D @types/jsdom @types/turndown

API

Interfaces

ExtractedContent

What extractReadable produces (everything but the fetch metadata).

interface ExtractedContent {
  title?: string
  description?: string
  content: string
  format: WebContentFormat
  links?: WebContentLink[]
  truncated: boolean
}

ReadabilityWebContentConfig

Options for createProvider().

interface ReadabilityWebContentConfig {
  /**
   * Per-fetch timeout in milliseconds (`fetch` only; `extract` never touches
   * the network). Defaults to `30_000`.
   */
  timeoutMs?: number

  /**
   * Largest response body a fetch reads, in bytes. Defaults to 3 MB — a
   * bigger body is refused rather than read into memory. `extract` is bounded
   * by the caller's own HTML size instead.
   */
  maxFetchBytes?: number

  /**
   * The `User-Agent` sent on fetches. Defaults to
   * `molecule-web-content/1.0 (+https://www.molecule.dev)` — an honest
   * product string, not a browser disguise.
   */
  userAgent?: string
}

Functions

extractReadable(html, options)

Extracts readable content from one HTML document.

The article (Readability) is preferred; when the page is not an article — an app shell, a fragments-only home page, a plain text dump — the whole document's squeezed text is the content instead, so the caller always gets the page's words rather than an empty result. about:blank (no baseUrl) is legal: relative links are simply dropped.

Readability is handed a CLONE of the document (parse mutates what it is given), so the fallback text and the links both still read the original.

function extractReadable(
  html: string,
  options?: {
    baseUrl?: string
    format?: WebContentFormat
    includeLinks?: boolean
    maxContentChars?: number
  },
): ExtractedContent
  • html — The HTML to read (a full document or a fragment).
  • options — Format, links, base URL, and the content cap (tests override it).

Returns: Title, description and the readable content.

createProvider(config)

Creates a Readability-backed web content provider.

function createProvider(config?: ReadabilityWebContentConfig): WebContentProvider
  • config — Optional provider configuration (timeout, byte cap, UA).

Returns: A WebContentProvider backed by Mozilla Readability in this process.

Constants

WEB_CONTENT_LIMITS

Extraction bounds — the same numbers every bond and the hosted handler document.

const WEB_CONTENT_LIMITS: {
  readonly maxContentChars: 500000
  readonly maxLinks: 200
  readonly maxLinkTextChars: 200
  readonly maxHtmlChars: 2000000
}

FETCH_LIMITS

Per-fetch limits, enforced before any network work.

const FETCH_LIMITS: {
  readonly maxUrlChars: 2048
  readonly maxFetchBytes: number
  readonly maxRedirects: 20
}

provider

The provider implementation, lazily initialized with default config.

const provider: WebContentProvider

Core Interface

Implements @molecule/api-web-content interface.

Bond Wiring

Setup function to register this provider with the core interface:

import { setProvider } from '@molecule/api-web-content'
import { provider } from '@molecule/api-web-content-readability'

export function setupWebContentReadability(): void {
  setProvider(provider)
}

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-web-content >=1.0.0

Runtime Dependencies

  • @molecule/api-web-content
  • @mozilla/readability
  • jsdom
  • turndown
  • turndown-plugin-gfm