From b51edadc6d55a2785490307fe8fac6234a400bc7 Mon Sep 17 00:00:00 2001
From: Kushagra Gour <chinchang457@gmail.com>
Date: Wed, 8 May 2024 13:35:40 +0530
Subject: [PATCH] unblock iframe doc from accessing localstorage n cookies.
 fixes #558

---
 preview/detached-window.js     | 2 +-
 src/components/ContentWrap.jsx | 4 ++--
 src/detached-window.js         | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/preview/detached-window.js b/preview/detached-window.js
index c2d21f5..cd119fa 100644
--- a/preview/detached-window.js
+++ b/preview/detached-window.js
@@ -15,6 +15,6 @@ window.addEventListener('message', e => {
 
 	// Recieving from preview iframe
 	if (e.data && e.data.logs) {
-		window.opener.postMessage(e.data, '*');
+		(window.opener || window.top).postMessage(e.data, '*');
 	}
 });
diff --git a/src/components/ContentWrap.jsx b/src/components/ContentWrap.jsx
index 2dba652..b200131 100644
--- a/src/components/ContentWrap.jsx
+++ b/src/components/ContentWrap.jsx
@@ -955,11 +955,11 @@ export default class ContentWrap extends Component {
 						/>
 					) : (
 						<iframe
-							src={`./indexpm.html`}
+							src={`${PREVIEW_FRAME_HOST}/preview.html`}
 							ref={el => (this.frame = el)}
 							frameborder="0"
 							id="demo-frame"
-							sandbox="allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-scripts allow-top-navigation-by-user-activation"
+							sandbox="allow-same-origin allow-downloads allow-forms allow-modals allow-pointer-lock allow-popups allow-presentation allow-scripts allow-top-navigation-by-user-activation"
 							allow="accelerometer; camera; encrypted-media; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; web-share"
 							allowpaymentrequest="true"
 							allowfullscreen="true"
diff --git a/src/detached-window.js b/src/detached-window.js
index c2d21f5..cd119fa 100644
--- a/src/detached-window.js
+++ b/src/detached-window.js
@@ -15,6 +15,6 @@ window.addEventListener('message', e => {
 
 	// Recieving from preview iframe
 	if (e.data && e.data.logs) {
-		window.opener.postMessage(e.data, '*');
+		(window.opener || window.top).postMessage(e.data, '*');
 	}
 });