diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index 3ae01525a80109..3720407fead1d4 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -133,6 +133,12 @@ function Iframe( { } function onLoad() { const { contentDocument, ownerDocument } = node; + // Ensure the iframe's contentDocument is available before proceeding. + // This prevents errors when the iframe content is not yet loaded or accessible. + // Once verified, initialize iFrameDocument and destructure documentElement. + if ( ! contentDocument ) { + return; + } const { documentElement } = contentDocument; iFrameDocument = contentDocument;