]> git.ardis.lu - ardislu.dev/commitdiff
Only highlight if CSS Custom Highlight API is supported
authorArdis Lu <ardisglu@gmail.com>
Tue, 27 Feb 2024 09:24:31 +0000 (01:24 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 27 Feb 2024 09:24:31 +0000 (01:24 -0800)
Firefox is still rolling out support: https://caniuse.com/mdn-api_highlight

script.js

index 5a1f46e07f13e2e507a7128e09c2dbf0590ab1b7..c2dd912a2914ebb02a14b8e0285c44228926e25c 100644 (file)
--- a/script.js
+++ b/script.js
@@ -214,8 +214,10 @@ function showSearch(query) {
     range.setEnd(node, start + query.length);
     ranges.push(range);
   }
-  const highlight = new Highlight(...ranges);
-  CSS.highlights.set('search', highlight);
+  if (CSS.highlights !== undefined) {
+    const highlight = new Highlight(...ranges);
+    CSS.highlights.set('search', highlight);
+  }
 
   document.querySelector('main').replaceWith(filteredHome);
 }
This page took 0.036169 seconds and 4 git commands to generate.