1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-03-22 19:49:40 +01: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'
: `https://wbmakr.com`;
let cachedSandboxAttribute = '';
export default class ContentWrap extends Component {
constructor(props) {
super(props);
@ -182,9 +184,11 @@ export default class ContentWrap extends Component {
this.frame.src = this.frame.src;
};
const writeInsideIframe = () => {
const sandbox = this.frame.getAttribute('sweet');
console.log('setting back sandbox attr', sandbox);
this.frame.setAttribute('sandbox', sandbox);
if (!cachedSandboxAttribute && window.DEBUG) {
alert('sandbox empty');
}
// console.log('setting back sandbox attr', sandbox);
this.frame.setAttribute('sandbox', cachedSandboxAttribute);
this.frame.removeAttribute('sweet');
// console.log('sending postmessage');
this.frame.contentWindow.postMessage({ contents }, '*');
@ -193,9 +197,9 @@ export default class ContentWrap extends Component {
// this.frame.contentDocument.close();
};
refreshAndDo(() => {
const sandbox = this.frame.getAttribute('sandbox');
console.log('removing sandbox', sandbox);
this.frame.setAttribute('sweet', sandbox);
cachedSandboxAttribute = this.frame.getAttribute('sandbox');
// console.log('removing sandbox', sandbox);
// this.frame.setAttribute('sweet', sandbox);
this.frame.removeAttribute('sandbox');
refreshAndDo(writeInsideIframe);
});

View File

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