diff --git a/src/gh_comments.rs b/src/gh_comments.rs index 35326f6d..84653312 100644 --- a/src/gh_comments.rs +++ b/src/gh_comments.rs @@ -194,7 +194,7 @@ pub async fn gh_comments( details.open = false; }}); }}); - document.getElementById('gh-comments-reverse-toc-order-btn').addEventListener('click', () => {{ + document.getElementById('gh-comments-reverse-toc-order-btn')?.addEventListener('click', () => {{ var tocList = document.getElementById('toc-list'); for (var i = 1; i < tocList.childNodes.length; i++) {{ tocList.insertBefore(tocList.childNodes[i], tocList.firstChild); diff --git a/src/gh_comments/self_contained.js b/src/gh_comments/self_contained.js index abf6bc2d..db6e8705 100644 --- a/src/gh_comments/self_contained.js +++ b/src/gh_comments/self_contained.js @@ -8,7 +8,11 @@ document.addEventListener('DOMContentLoaded', function() { triggerUserDownload(htmlContent, `gh-comments-${ISSUE_ID}-export-${new Date().toISOString().slice(0,10)}.html`); } catch (e) { console.log(e); - alert(`Error: ${e.message}`); + if (e instanceof Error) { + alert(`Unable to export the comments: ${e}`); + } else { + alert(`Unable to export the comments. See the console for more details.`); + } } }); }); @@ -83,7 +87,13 @@ async function inlineImages(doc) { canvas.getContext('2d').drawImage(tempImg, 0, 0, canvas.width, canvas.height); resolve(canvas.toDataURL('image/png')); }; - tempImg.onerror = reject; + tempImg.onerror = (event) => { + // We got an error, probably a CORS rejection (happens with user images on GitHub), but we + // can't be certain. We only get an event, not an error. + // + // Anyway, let's ignore this error and use the initial source. + resolve(src); + }; tempImg.src = src; }); }));