From: Ardis Lu Date: Tue, 27 Feb 2024 09:24:31 +0000 (-0800) Subject: Only highlight if CSS Custom Highlight API is supported X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=665fd8c54fb5aa812bd7c64a98024c1419a7546e;p=ardislu.dev Only highlight if CSS Custom Highlight API is supported Firefox is still rolling out support: https://caniuse.com/mdn-api_highlight --- diff --git a/script.js b/script.js index 5a1f46e..c2dd912 100644 --- 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); }