1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-29 17:50:09 +02:00

fix sandbox null issue

This commit is contained in:
Kushagra Gour
2024-04-28 21:54:37 +05:30
parent a35291b360
commit 4d45e85b90
2 changed files with 11 additions and 7 deletions

View File

@@ -25,6 +25,8 @@ const PREVIEW_FRAME_HOST = window.DEBUG
? 'http://localhost:7888' ? 'http://localhost:7888'
: `https://wbmakr.com`; : `https://wbmakr.com`;
let cachedSandboxAttribute = '';
export default class ContentWrap extends Component { export default class ContentWrap extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -182,9 +184,11 @@ export default class ContentWrap extends Component {
this.frame.src = this.frame.src; this.frame.src = this.frame.src;
}; };
const writeInsideIframe = () => { const writeInsideIframe = () => {
const sandbox = this.frame.getAttribute('sweet'); if (!cachedSandboxAttribute && window.DEBUG) {
console.log('setting back sandbox attr', sandbox); alert('sandbox empty');
this.frame.setAttribute('sandbox', sandbox); }
// console.log('setting back sandbox attr', sandbox);
this.frame.setAttribute('sandbox', cachedSandboxAttribute);
this.frame.removeAttribute('sweet'); this.frame.removeAttribute('sweet');
// console.log('sending postmessage'); // console.log('sending postmessage');
this.frame.contentWindow.postMessage({ contents }, '*'); this.frame.contentWindow.postMessage({ contents }, '*');
@@ -193,9 +197,9 @@ export default class ContentWrap extends Component {
// this.frame.contentDocument.close(); // this.frame.contentDocument.close();
}; };
refreshAndDo(() => { refreshAndDo(() => {
const sandbox = this.frame.getAttribute('sandbox'); cachedSandboxAttribute = this.frame.getAttribute('sandbox');
console.log('removing sandbox', sandbox); // console.log('removing sandbox', sandbox);
this.frame.setAttribute('sweet', sandbox); // this.frame.setAttribute('sweet', sandbox);
this.frame.removeAttribute('sandbox'); this.frame.removeAttribute('sandbox');
refreshAndDo(writeInsideIframe); refreshAndDo(writeInsideIframe);
}); });

View File

@@ -1,6 +1,6 @@
<script> <script>
function callback(e) { function callback(e) {
console.log('post message recvd', e.data); // console.log('post message recvd', e.data);
window.document.open(); window.document.open();
const { contents } = e.data; const { contents } = e.data;