mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
fix change html_file for iframe
This commit is contained in:
17
src/index.js
17
src/index.js
@@ -53,8 +53,8 @@ const open_run_iframe = (state) => {
|
|||||||
// for run_window, do not set unhandled rejection, because having rejected
|
// for run_window, do not set unhandled rejection, because having rejected
|
||||||
// promises in user code is normal condition
|
// promises in user code is normal condition
|
||||||
set_error_handler(iframe.contentWindow, false)
|
set_error_handler(iframe.contentWindow, false)
|
||||||
iframe.contentWindow.addEventListener('load', on_window_load)
|
|
||||||
globalThis.run_window = iframe.contentWindow
|
globalThis.run_window = iframe.contentWindow
|
||||||
|
init_run_window()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open another browser window so user can interact with application
|
// Open another browser window so user can interact with application
|
||||||
@@ -63,11 +63,14 @@ export const open_run_window = state => {
|
|||||||
// TODO set_error_handler? Or we dont need to set_error_handler for child
|
// TODO set_error_handler? Or we dont need to set_error_handler for child
|
||||||
// window because error is always caught by parent window handler?
|
// window because error is always caught by parent window handler?
|
||||||
globalThis.run_window.close()
|
globalThis.run_window.close()
|
||||||
|
globalThis.run_window = open(get_html_url(state))
|
||||||
|
init_run_window()
|
||||||
|
}
|
||||||
|
|
||||||
const next_window = globalThis.run_window = open(get_html_url(state))
|
const init_run_window = () => {
|
||||||
|
|
||||||
const is_loaded = () => {
|
const is_loaded = () => {
|
||||||
const nav = next_window.performance.getEntriesByType("navigation")[0]
|
const nav = globalThis.run_window.performance.getEntriesByType("navigation")[0]
|
||||||
return nav != null && nav.loadEventEnd > 0
|
return nav != null && nav.loadEventEnd > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +92,7 @@ export const open_run_window = state => {
|
|||||||
add_unload_handler()
|
add_unload_handler()
|
||||||
on_window_load()
|
on_window_load()
|
||||||
} else {
|
} else {
|
||||||
next_window.addEventListener('load', () => {
|
globalThis.run_window.addEventListener('load', () => {
|
||||||
add_unload_handler()
|
add_unload_handler()
|
||||||
// Wait until `load` event before executing code, because service worker that
|
// Wait until `load` event before executing code, because service worker that
|
||||||
// is responsible for loading external modules seems not working until `load`
|
// is responsible for loading external modules seems not working until `load`
|
||||||
@@ -101,12 +104,12 @@ export const open_run_window = state => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const add_unload_handler = () => {
|
const add_unload_handler = () => {
|
||||||
next_window.addEventListener('unload', (e) => {
|
globalThis.run_window.addEventListener('unload', (e) => {
|
||||||
// Set timeout to 100ms because it takes some time for page to get closed
|
// Set timeout to 100ms because it takes some time for page to get closed
|
||||||
// after triggering 'unload' event
|
// after triggering 'unload' event
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if(next_window.closed) {
|
if(globalThis.run_window.closed) {
|
||||||
// If by that time next_window.closed was set to true, then page was
|
// If by that time globalThis.run_window.closed was set to true, then page was
|
||||||
// closed
|
// closed
|
||||||
// TODO get back to iframe?
|
// TODO get back to iframe?
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user