Skip to content

Commit

Permalink
fix(iframe): add empty srcdoc attribute to iframe elem if not exist (#36
Browse files Browse the repository at this point in the history
)

* fix(iframe): add empty srcdoc attribute to iframe elem if not exist

* style(dom): run npm run format
  • Loading branch information
magaldima authored Sep 23, 2024
1 parent 170604c commit b21a468
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/renderers/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b21a468

Please sign in to comment.