Skip to content

Commit

Permalink
fix(iframe): add empty srcdoc attribute to iframe elem if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
magaldima committed Sep 19, 2024
1 parent 170604c commit 5a7f781
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/renderers/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ 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,
Expand Down

0 comments on commit 5a7f781

Please sign in to comment.