Handle createPolicy gracefully (#2031)

This commit is contained in:
Shuchang Zheng
2025-03-27 01:03:25 -07:00
committed by GitHub
parent 0ed236f092
commit 6c7e96d93e

View File

@@ -1882,12 +1882,17 @@ function createHintMarkersForGroups(groups) {
} catch (e) { } catch (e) {
// Ensure trustedTypes is available // Ensure trustedTypes is available
if (typeof trustedTypes !== "undefined") { if (typeof trustedTypes !== "undefined") {
const escapeHTMLPolicy = trustedTypes.createPolicy("default", { try {
createHTML: (string) => string, const escapeHTMLPolicy = trustedTypes.createPolicy("hint-policy", {
}); createHTML: (string) => string,
hintMarker.element.innerHTML = escapeHTMLPolicy.createHTML( });
hintMarker.hintString.toUpperCase(), hintMarker.element.innerHTML = escapeHTMLPolicy.createHTML(
); hintMarker.hintString.toUpperCase(),
);
} catch (policyError) {
console.warn("Could not create trusted types policy:", policyError);
// Skip updating the hint marker if policy creation fails
}
} else { } else {
console.error("trustedTypes is not supported in this environment."); console.error("trustedTypes is not supported in this environment.");
} }