Skip to content

Commit b670341

Browse files
committed
fix: resolve cross-origin iframe access error in Authoring MFE with GTM
Fixed a SecurityError that occurred when Google Tag Manager was enabled and the Authoring MFE embedded Studio content in an iframe. The bug was in cms/templates/container_chromeless.html where the resize script used `window.parent[0].offsetHeight` to get initial dimensions. When GTM is present, `window.parent[0]` references GTM's cross-origin iframe instead of the parent window, causing a cross-origin security error: "Failed to read a named property 'offsetHeight' from 'Window'". Changed to use `document.documentElement.scrollHeight` and `document.documentElement.scrollWidth` to get the current document's dimensions directly, avoiding cross-origin frame access entirely. This allows the Authoring MFE to function correctly with Google Tag Manager and other third-party scripts that inject iframes.
1 parent 480a445 commit b670341

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cms/templates/container_chromeless.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@
215215
// it will report the height of its contents to the parent window when the
216216
// document loads, window resizes, or DOM mutates.
217217
if (window !== window.parent) {
218-
var lastHeight = window.parent[0].offsetHeight;
219-
var lastWidth = window.parent[0].offsetWidth;
218+
var lastHeight = document.documentElement.scrollHeight;
219+
var lastWidth = document.documentElement.scrollWidth;
220220
var contentElement = document.getElementById('content');
221221

222222
function dispatchResizeMessage(event) {

0 commit comments

Comments
 (0)