9
0
mirror of https://github.com/donlon/cloudflare-error-page.git synced 2025-12-19 14:59:28 +00:00

editor/ui: fix preview window flickering caused by page reload

This commit is contained in:
Anthony Donlon
2025-11-22 04:24:21 +08:00
parent 0c2319a48c
commit 4d1cc890ef

View File

@@ -320,7 +320,10 @@
let pageHtml = renderEjs(cfg) let pageHtml = renderEjs(cfg)
// Write into iframe // Write into iframe
const iframe = $('previewFrame'); const iframe = $('previewFrame');
iframe.srcdoc = pageHtml; let doc = iframe.contentDocument
doc.open();
doc.write(pageHtml);
doc.close();
// store last rendered HTML for "open in new tab" // store last rendered HTML for "open in new tab"
lastRenderedHtml = pageHtml; lastRenderedHtml = pageHtml;
@@ -413,7 +416,7 @@
inp.addEventListener('input', debounce(() => { inp.addEventListener('input', debounce(() => {
// Update status block color classes for quick visual feedback in the editor // Update status block color classes for quick visual feedback in the editor
render(); render();
}, 1500)); }, 200));
// for radio change events (error_source) // for radio change events (error_source)
if (inp.type === 'radio') inp.addEventListener('change', () => { render(); }); if (inp.type === 'radio') inp.addEventListener('change', () => { render(); });
}); });
@@ -830,7 +833,8 @@
<h6><strong>Preview</strong></h6> <h6><strong>Preview</strong></h6>
</div> </div>
<iframe id="previewFrame" class="preview-frame" sandbox="allow-scripts"></iframe> <!-- TODO: An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing. -->
<iframe id="previewFrame" class="preview-frame" sandbox="allow-scripts allow-same-origin"></iframe>
</div> </div>
</div> </div>