Skip to content

Commit

Permalink
Merge pull request #1040 from gemini-testing/TESTPLANE-358.TrustedHTML
Browse files Browse the repository at this point in the history
fix: error when trying to disable animation
  • Loading branch information
KuznetsovRoman authored Dec 10, 2024
2 parents 769de00 + ee931e2 commit 59a174d
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 59a174d

Please sign in to comment.