{"record":{"id":"971ec5a7c2fb0a71","repo":"gildas-lormeau/SingleFile","slug":"aborting-parsing-document-numtags-element","errorCode":null,"errorMessage":"Aborting parsing document; \" + numTags + \" elements found","messagePattern":"Aborting parsing document; \" \\+ numTags \\+ \" elements found","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/lib/readability/Readability.js","lineNumber":2752,"sourceCode":"\r\n  /**\r\n   * Runs readability.\r\n   *\r\n   * Workflow:\r\n   *  1. Prep the document by removing script tags, css, etc.\r\n   *  2. Build readability's DOM tree.\r\n   *  3. Grab the article content from the current dom tree.\r\n   *  4. Replace the current DOM tree with the new one.\r\n   *  5. Read peacefully.\r\n   *\r\n   * @return void\r\n   **/\r\n  parse() {\r\n    // Avoid parsing too large documents, as per configuration option\r\n    if (this._maxElemsToParse > 0) {\r\n      var numTags = this._doc.getElementsByTagName(\"*\").length;\r\n      if (numTags > this._maxElemsToParse) {\r\n        throw new Error(\r\n          \"Aborting parsing document; \" + numTags + \" elements found\"\r\n        );\r\n      }\r\n    }\r\n\r\n    // Unwrap image from noscript\r\n    this._unwrapNoscriptImages(this._doc);\r\n\r\n    // Extract JSON-LD metadata before removing scripts\r\n    var jsonLd = this._disableJSONLD ? {} : this._getJSONLD(this._doc);\r\n\r\n    // Remove script tags from the document.\r\n    this._removeScripts(this._doc);\r\n\r\n    this._prepDocument();\r\n\r\n    var metadata = this._getArticleMetadata(jsonLd);\r\n    this._metadata = metadata;\r","sourceCodeStart":2734,"sourceCodeEnd":2770,"githubUrl":"https://github.com/gildas-lormeau/SingleFile/blob/517fb7c5cf2096d89933b747e862d8ecf616a9f9/src/lib/readability/Readability.js#L2734-L2770","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst article = new Readability(doc).parse();\n// after\nconst article = new Readability(doc, { maxElemsToParse: 20000 }).parse();","handlingStrategy":"fallback","validationCode":"const numTags = doc.getElementsByTagName(\"*\").length;\nconst maxElems = options.maxElemsToParse ?? 1500;\nif (numTags > maxElems) {\n  doc = pruneDocument(doc); // strip nav/footer/script/comment nodes\n  if (doc.getElementsByTagName(\"*\").length > maxElems) options.maxElemsToParse = numTags + 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n  return new Readability(doc, { maxElemsToParse: 20000 }).parse();\n} catch (e) {\n  if (e.message.startsWith(\"Aborting parsing document\")) {\n    return new Readability(pruneDocument(doc), { maxElemsToParse: Infinity }).parse();\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["readability","performance","document-size"],"backgroundTag":"document-too-large","analyzedSha":"517fb7c5cf2096d89933b747e862d8ecf616a9f9","analyzedAt":"2026-09-01T10:05:25.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}