can1357/oh-my-pi · error
Aborting parsing document; ${count} elements found
Error message
Aborting parsing document; ${count} elements found What it means
Readability's parse() refuses to process documents whose element count exceeds the configured maxElemsToParse, as a safeguard against pathological/huge pages that would consume unbounded time and memory. The count includes all descendants of the document element plus one.
Source
Thrown at packages/utils/src/readability/readability.ts:299
readonly #document: ReadabilityDocument;
readonly #options: ReadabilityOptions<T>;
readonly #scores = new Map<ReadabilityElement, number>();
#byline: string | undefined;
#lang: string | null = null;
constructor(document: ReadabilityDocument, options: ReadabilityOptions<T> = {}) {
this.#document = document;
this.#options = options;
}
/** Runs extraction once; the supplied document is consumed and should not be reused. */
parse(): ReadabilityArticle<T> | null {
const documentElement = this.#document.documentElement;
if (!documentElement) return null;
const max = this.#options.maxElemsToParse ?? 0;
if (max > 0) {
const count = descendants(documentElement).length + 1;
if (count > max) throw new Error(`Aborting parsing document; ${count} elements found`);
}
const jsonLd = this.#options.disableJSONLD ? {} : jsonLdMetadata(this.#document);
const metadata = metadataFromDocument(this.#document, jsonLd);
removeAll(this.#document, ["script", "style"]);
const body = this.#document.body;
if (!body) return null;
const source = body.innerHTML;
const attempts: Attempt[] = [];
for (const mode of [0, 1, 2, 3]) {
if (mode) body.innerHTML = source;
this.#scores.clear();
this.#byline = undefined;
const attempt = this.#extract(body, documentElement, metadata.title ?? "", mode);
if (attempt) attempts.push(attempt);
if (attempt && attempt.length >= (this.#options.charThreshold || 500)) break;
}
attempts.sort((left, right) => right.length - left.length);
const best = attempts[0];View on GitHub (pinned to 9690622007)
Solutions
- Raise maxElemsToParse to a value above the expected document size.
- Pre-trim the document (strip nav/footer/ads, truncate tables) before parsing.
- Remove the maxElemsToParse option (0) to parse unbounded documents if memory allows.
- Catch the error and fall back to a simpler text extraction.
Example fix
// before
new Readability(doc, { maxElemsToParse: 1000 }).parse();
// after
new Readability(doc, { maxElemsToParse: 50000 }).parse(); Defensive patterns
Strategy: validation
Validate before calling
const count = doc.documentElement ? doc.getElementsByTagName('*').length + 1 : 0;
const max = opts.maxElemsToParse ?? 0;
if (max > 0 && count > max) {
// trim document or raise the limit before calling parse()
} Try / catch
try {
article = reader.parse();
} catch (err) {
if (String(err.message).startsWith('Aborting parsing document')) {
article = fallbackExtract(doc); // simple text extraction
} else throw err;
} Prevention
- Set maxElemsToParse generously relative to your largest expected pages.
- Pre-strip boilerplate (nav, footer, scripts) before parsing.
- Always provide a fallback extractor for huge/pathological pages.
When it happens
Trigger: Calling readability.parse() on a document when `options.maxElemsToParse` is set (default 0 = unlimited is bypassed once the option is provided) and the DOM contains more elements than that limit.
Common situations: Extracting article content from very large HTML pages (giant tables, generated markup), setting a low limit for memory safety and hitting it on legitimate pages.
Related errors
- Replacement text is not valid UTF-8: {err}
- V2 compaction stream parse failed: ${err instanceof Error ?
- ${source} response is missing credentials.
- auto-thinking: unparseable local classification: ${JSON.stri
- ${argv[0]} did not report a tunnel URL within ${READY_TIMEOU
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/58e3dbcead7aa991.
Report an issue: GitHub.