From 250434893698e2d4156f89def84aae79bad4a78e Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 27 Jun 2022 11:09:38 +0800 Subject: [PATCH] Fix getting nodes from null document element --- packages/readabilityjs/Readability.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index 3f5dbd0e5..e71da9804 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -65,8 +65,8 @@ const extractPublishedDateFromAuthor = (author)=> { /** * Public constructor. - * @param {HTMLDocument} doc The document to parse. - * @param {Object} options The options object. + * @param {Document} doc The document to parse. + * @param {Object} options The options object. */ function Readability(doc, options) { // In some older versions, people passed a URI as the first argument. Cope: @@ -1517,9 +1517,9 @@ Readability.prototype = { // Checking for the figures inside of the
tags and appending them to the content if not there aleady, // b/c some articles contains first image nested into the
elemens that is not considered as an article content at all. // Example article: https://www.vanityfair.com/news/2020/12/trump-vaccine-summit-herd-immunity - const headerNodes = this._getAllNodesWithTag(this._doc.documentElement, ['HEADER']); + const headerNodes = this._doc.documentElement && this._getAllNodesWithTag(this._doc.documentElement, ['HEADER']); const alreadyExistingFigures = this._getAllNodesWithTag(articleContent, ['FIGURE']); - this._forEachNode(headerNodes, headerNode => { + headerNodes && this._forEachNode(headerNodes, headerNode => { if (!headerNode || !headerNode.readability || !headerNode.readability.contentScore) return;