From 7f3835eff242283d78436740a6c4f9703aa22d39 Mon Sep 17 00:00:00 2001 From: Rick C <4494839+rickdoesdev@users.noreply.github.com> Date: Fri, 23 Aug 2024 19:04:09 +1000 Subject: [PATCH] fix: codeSource.firstChild is null Uncaught (in promise) TypeError: codeSource.firstChild is null make sure object reference is not null before we try to use it. --- src/background/background.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/background/background.js b/src/background/background.js index 32b7138..b419d1b 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -722,7 +722,7 @@ async function getArticleFromDom(domString) { dom.body.querySelectorAll('[class*=highlight-text],[class*=highlight-source]')?.forEach(codeSource => { const language = codeSource.className.match(/highlight-(?:text|source)-([a-z0-9]+)/)?.[1] - if (codeSource.firstChild.nodeName == "PRE") { + if (codeSource.firstChild && codeSource.firstChild.nodeName == "PRE") { codeSource.firstChild.id = `code-lang-${language}` } }); @@ -738,7 +738,7 @@ async function getArticleFromDom(domString) { }); dom.body.querySelectorAll('.codehilite > pre')?.forEach(codeSource => { - if (codeSource.firstChild.nodeName !== 'CODE' && !codeSource.className.includes('language')) { + if (codeSource.firstChild && codeSource.firstChild.nodeName !== 'CODE' && !codeSource.className.includes('language')) { codeSource.id = `code-lang-text`; } });