From 449ee64dac9426c55c36782628fcb20ebc277cc1 Mon Sep 17 00:00:00 2001 From: kuuuube Date: Sun, 29 Dec 2024 16:20:08 -0500 Subject: [PATCH] Catch sanitizer fails only when `new CSSStyleSheet()` is not available --- ext/js/core/utilities.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ext/js/core/utilities.js b/ext/js/core/utilities.js index 2e0386fee..3e50aa5b6 100644 --- a/ext/js/core/utilities.js +++ b/ext/js/core/utilities.js @@ -16,6 +16,9 @@ * along with this program. If not, see . */ +import {log} from './log.js'; + + /** * Converts any string into a form that can be passed into the RegExp constructor. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions @@ -268,7 +271,15 @@ export function promiseTimeout(delay) { * @returns {string} */ export function sanitizeCSS(css) { - const sanitizer = new CSSStyleSheet(); + let sanitizer; + // As of 2023/03/xx, all latest browser versions support this but some forks may lag behind + try { + sanitizer = new CSSStyleSheet(); + } catch (e) { + log.log("Failed to sanitize dictionary styles") + log.warn(e); + return css; + } sanitizer.replaceSync(css); return Array.from(sanitizer.cssRules).map(rule => rule.cssText || '').join('\n'); }