summary refs log tree commit diff
diff options
context:
space:
mode:
authorV <v@anomalous.eu>2020-08-14 23:53:11 +0200
committerV <v@anomalous.eu>2020-08-14 23:53:11 +0200
commite4f8bb2827340c49217a453b4f5e4d84d72e2518 (patch)
treedde068312f99244e659649e3e1971551d51b0cc7
parentc8066e03c67cab112f91b24e4416aefec33cf2bc (diff)
downloademail-protected-e4f8bb2827340c49217a453b4f5e4d84d72e2518.tar.zst
Fix crashing on empty/invalid hrefs
-rw-r--r--content.js10
1 files 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: <a href="/cdn-cgi/l/email-protection#{encrypted data}">...</a>
   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