diff --git a/site/source/hooks/useIframeResizer.ts b/site/source/hooks/useIframeResizer.ts index c4ae5436c..c9686fa72 100644 --- a/site/source/hooks/useIframeResizer.ts +++ b/site/source/hooks/useIframeResizer.ts @@ -1,11 +1,23 @@ import { useEffect } from 'react' +function isIframe() { + try { + return window.self !== window.top + } catch (e) { + return true + } +} + export function useIframeResizer() { useEffect(() => { // The code below communicate with the iframe.js script on a host site // to automatically resize the iframe when its inner content height // change. + if (!isIframe()) { + return + } + const minHeight = 700 // Also used in iframe.js const observer = new ResizeObserver(([entry]) => { const value = Math.max(minHeight, entry.contentRect.height) diff --git a/site/source/pages/integration/Iframe.tsx b/site/source/pages/integration/Iframe.tsx index 24f8de9d1..b4416d0b7 100644 --- a/site/source/pages/integration/Iframe.tsx +++ b/site/source/pages/integration/Iframe.tsx @@ -65,11 +65,7 @@ function IntegrationCustomizer() { window.addEventListener( 'message', function (evt: MessageEvent<{ kind: string; value: string }>) { - if ( - iframeRef.current && - evt.data.kind === 'resize-height' && - iframeRef.current.contentDocument?.readyState === 'complete' - ) { + if (iframeRef.current && evt.data.kind === 'resize-height') { iframeRef.current.style.height = evt.data.value + 'px' } }