From b21a46826fe3369ded96cbba6dfd44b955a87a34 Mon Sep 17 00:00:00 2001 From: Matthew Magaldi Date: Mon, 23 Sep 2024 11:36:12 -0400 Subject: [PATCH] fix(iframe): add empty srcdoc attribute to iframe elem if not exist (#36) * fix(iframe): add empty srcdoc attribute to iframe elem if not exist * style(dom): run npm run format --- src/renderers/dom.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/renderers/dom.js b/src/renderers/dom.js index ded181e..94a0909 100644 --- a/src/renderers/dom.js +++ b/src/renderers/dom.js @@ -118,6 +118,17 @@ function addProps(el: HTMLElement | Element, node) { if (el.tagName.toLowerCase() === ELEMENT_TAG.IFRAME && !props.id) { el.setAttribute(ELEMENT_PROP.ID, `jsx-iframe-${uniqueID()}`); } + + // If the element is an iframe and it has no srcdoc or src, set the srcdoc to an empty string. + // Content specified via srcdoc is treated as being from the same origin as the parent document. + // In some browsers (like Safari 17+), empty iframes without src or srcdoc may be treated as "anonymous," potentially blocking certain content. + if ( + el.tagName.toLowerCase() === ELEMENT_TAG.IFRAME && + !props.srcdoc && + !props.src + ) { + el.setAttribute("srcdoc", ""); + } } const ADD_CHILDREN: { [string]: (HTMLElement | Element, ElementNode, DomNodeRenderer) => void,