diff --git a/templates/macros/head.html b/templates/macros/head.html index 65f9851..c566f4c 100644 --- a/templates/macros/head.html +++ b/templates/macros/head.html @@ -49,6 +49,29 @@ }); } catch(e) {} } + + function installFramePolicy(methodName) { + const original = Element.prototype[methodName]; + Element.prototype[methodName] = function(...args) { + const result = original.apply(this, args); + const node = args[0]; + if (node && node.tagName === 'IFRAME') { + try { + const win = node.contentWindow; + if (win && win.trustedTypes && !win.trustedTypes.defaultPolicy) { + win.trustedTypes.createPolicy('default', { + createHTML: s => s, + createScript: s => s, + createScriptURL: s => s + }); + } + } catch (err) {} + } + return result; + }; + } + installFramePolicy('appendChild'); + installFramePolicy('insertBefore'); })();