run code in iframe on load

This commit is contained in:
Dmitry Vasilev
2022-11-29 01:20:40 +08:00
parent 840c2eb6d9
commit 21d5580f4b

View File

@@ -30,12 +30,13 @@ const get_html_url = state => {
// By default run code in hidden iframe, until user explicitly opens visible // By default run code in hidden iframe, until user explicitly opens visible
// window // window
const open_run_iframe = state => { const open_run_iframe = (state, onload) => {
const iframe = document.createElement('iframe') const iframe = document.createElement('iframe')
iframe.src = get_html_url(state) iframe.src = get_html_url(state)
iframe.setAttribute('hidden', '') iframe.setAttribute('hidden', '')
document.body.appendChild(iframe) document.body.appendChild(iframe)
set_error_handler(iframe.contentWindow) set_error_handler(iframe.contentWindow)
iframe.contentWindow.addEventListener('load', onload)
globalThis.run_window = iframe.contentWindow globalThis.run_window = iframe.contentWindow
} }
@@ -158,10 +159,9 @@ export const init = (container, _COMMANDS) => {
render_initial_state(ui, state) render_initial_state(ui, state)
open_run_iframe(state) open_run_iframe(state, () => {
exec('open_run_window')
// TODO exec on iframe load })
exec('open_run_window')
}) })
} }