gildas-lormeau/SingleFile · warning · Error
Aborting parsing document; " + numTags + " elements found
Error message
Aborting parsing document; " + numTags + " elements found
What it means
Readability.parse() enforces the maxElemsToParse option (default 1500 in the upstream lib) to avoid pathological CPU/memory usage on enormous documents. Before parsing it counts all elements via getElementsByTagName("*") and throws if the count exceeds the limit.
Source
Thrown at src/lib/readability/Readability.js:2752
/**
* Runs readability.
*
* Workflow:
* 1. Prep the document by removing script tags, css, etc.
* 2. Build readability's DOM tree.
* 3. Grab the article content from the current dom tree.
* 4. Replace the current DOM tree with the new one.
* 5. Read peacefully.
*
* @return void
**/
parse() {
// Avoid parsing too large documents, as per configuration option
if (this._maxElemsToParse > 0) {
var numTags = this._doc.getElementsByTagName("*").length;
if (numTags > this._maxElemsToParse) {
throw new Error(
"Aborting parsing document; " + numTags + " elements found"
);
}
}
// Unwrap image from noscript
this._unwrapNoscriptImages(this._doc);
// Extract JSON-LD metadata before removing scripts
var jsonLd = this._disableJSONLD ? {} : this._getJSONLD(this._doc);
// Remove script tags from the document.
this._removeScripts(this._doc);
this._prepDocument();
var metadata = this._getArticleMetadata(jsonLd);
this._metadata = metadata;
View on GitHub (pinned to 517fb7c5cf)
Solutions
- Raise the limit: construct with { maxElemsToParse: N } sized for your documents (or 0/Infinity to disable the guard deliberately)
- Pre-strip irrelevant subtrees (nav, footer, scripts, comments) to reduce the element count before parsing
- Split the document and parse the main content region only instead of the whole body
- Confirm you didn't pass an unexpectedly small maxElemsToParse option by mistake
Example fix
// before
const article = new Readability(doc).parse();
// after
const article = new Readability(doc, { maxElemsToParse: 20000 }).parse(); Defensive patterns
Strategy: fallback
Validate before calling
const numTags = doc.getElementsByTagName("*").length;
const maxElems = options.maxElemsToParse ?? 1500;
if (numTags > maxElems) {
doc = pruneDocument(doc); // strip nav/footer/script/comment nodes
if (doc.getElementsByTagName("*").length > maxElems) options.maxElemsToParse = numTags + 1;
} Try / catch
try {
return new Readability(doc, { maxElemsToParse: 20000 }).parse();
} catch (e) {
if (e.message.startsWith("Aborting parsing document")) {
return new Readability(pruneDocument(doc), { maxElemsToParse: Infinity }).parse();
}
throw e;
} Prevention
- Count elements before parsing and pre-trim huge DOMs
- Set maxElemsToParse deliberately for your document profile
- Strip scripts/styles/noscript and repeated list items before extraction
- Never silently pass maxElemsToParse: 0 unless you accept the perf cost
When it happens
Trigger: Calling .parse() on a document with more elements than this._maxElemsToParse — e.g., a huge listing page, auto-infinite-scroll DOM snapshot, or a page with tens of thousands of DOM nodes.
Common situations: Scraping very large index/catalog pages; parsing an archived or serialized mega-page; constructing Readability with a low custom maxElemsToParse and feeding it a normal-sized page.
Related errors
AI-assisted analysis of gildas-lormeau/SingleFile@517fb7c5cf (2026-09-01).
Data as JSON: /api/errors/971ec5a7c2fb0a71.
Report an issue: GitHub.