From 963e7689968b8a51a900cdb26bbc8235a563053b Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 30 Jan 2023 15:03:43 +0800 Subject: [PATCH] Fix not showing images in wechat articles --- packages/readabilityjs/Readability.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/readabilityjs/Readability.js b/packages/readabilityjs/Readability.js index f57dcb127..ff306ceff 100644 --- a/packages/readabilityjs/Readability.js +++ b/packages/readabilityjs/Readability.js @@ -526,7 +526,8 @@ Readability.prototype = { // replace all images' href source const images = articleContent.getElementsByTagName('img'); Array.from(images).forEach(image => { - const src = image.getAttribute("src"); + // for some reason, some images have no src attribute, so we need to use data-src + const src = image.getAttribute("data-src") || image.getAttribute("src"); // do not proxy data uri if (src && !dataUriRegex.test(src)) { @@ -545,6 +546,9 @@ Readability.prototype = { const proxySrc = this.createImageProxyUrl(absoluteSrc, width, height); image.setAttribute('src', proxySrc); } + + // remove crossorigin attribute to avoid CORS errors + image.removeAttribute('crossorigin'); }); // replace all srcset's