Skip to content

Commit

Permalink
fix: error when trying to disable animation
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Dec 10, 2024
1 parent 769de00 commit ee931e2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/browser/client-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function disableFrameAnimationsUnsafe() {

var styleElements = [];

util.forEachRoot(function (root) {
function appendDisableAnimationStyleElement(root) {
var styleElement = document.createElement("style");
styleElement.innerHTML =
everythingSelector +
Expand All @@ -176,6 +176,30 @@ function disableFrameAnimationsUnsafe() {

root.appendChild(styleElement);
styleElements.push(styleElement);
}

function createDefaultTrustedTypesPolicy() {
if (window.trustedTypes && window.trustedTypes.createPolicy) {
window.trustedTypes.createPolicy("default", {
createHTML: function (string) {
return string;
}
});
}
}

util.forEachRoot(function (root) {
try {
appendDisableAnimationStyleElement(root);
} catch (err) {
if (err && err.message && err.message.includes("This document requires 'TrustedHTML' assignment")) {
createDefaultTrustedTypesPolicy();

appendDisableAnimationStyleElement(root);
} else {
throw err;
}
}
});

window.__cleanupAnimation = function () {
Expand Down

0 comments on commit ee931e2

Please sign in to comment.