From e4f8bb2827340c49217a453b4f5e4d84d72e2518 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 14 Aug 2020 23:53:11 +0200 Subject: Fix crashing on empty/invalid hrefs --- content.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/content.js b/content.js index 72ddcc4..4c219b3 100644 --- a/content.js +++ b/content.js @@ -24,9 +24,13 @@ function process(root) { // mailto links // format: ... for (const node of root.querySelectorAll('a')) { - const url = new URL(node.href) - if (url.pathname === '/cdn-cgi/l/email-protection' && url.hash !== '') - node.href = `mailto:${decode(url.hash.slice(1))}` + try { + const url = new URL(node.href) + if (url.pathname === '/cdn-cgi/l/email-protection' && url.hash !== '') + node.href = `mailto:${decode(url.hash.slice(1))}` + } catch { + // either there wasn't an href, or it wasn't a valid URL + } } // everything else Cloudflare thinks is an email -- cgit 1.4.1