function insideIframe() { if (window !== window.parent && !window.iframe_listeners) { window.iframe_listeners = true document.documentElement.classList.add('page-in-iframe') window.addEventListener( 'wheel', function (e) { window.parent.postMessage({ up: e.deltaY < 0 }, '*') }, { passive: false } ) const notifyNavigation = () => { window.parent.postMessage({ url: window.location.href }, '*') } window.addEventListener('load', notifyNavigation) window.addEventListener('pageshow', notifyNavigation) window.addEventListener('popstate', notifyNavigation) const originalPushState = history.pushState const originalReplaceState = history.replaceState history.pushState = function (...args) { const result = originalPushState.apply(this, args) notifyNavigation() return result } history.replaceState = function (...args) { const result = originalReplaceState.apply(this, args) notifyNavigation() return result } document.addEventListener('click', function (event) { const anchor = event.target.closest('a') if ( anchor && anchor.href && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.defaultPrevented && anchor.target !== '_blank' && !anchor.download && anchor.protocol.startsWith('http') ) { window.parent.postMessage({ url: anchor.href }, '*') } }) } } insideIframe()