From 8ee8f1d1ec9b3fa40636faa320eefa7cbf9b4f05 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 6 Feb 2019 16:29:13 +0000 Subject: [PATCH] Attempt to lazy-load iframe Needs to be activated twice before it works. --- src/content/commandline_content.ts | 44 +++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/content/commandline_content.ts b/src/content/commandline_content.ts index 87b6412a..4f836c2b 100644 --- a/src/content/commandline_content.ts +++ b/src/content/commandline_content.ts @@ -34,7 +34,6 @@ let enabled = false async function init() { let noiframe = await config.getAsync("noiframe") if (noiframe == "false" && !enabled) { - hide() document.documentElement.appendChild(cmdline_iframe) enabled = true // first theming of page root @@ -44,27 +43,40 @@ async function init() { // Load the iframe immediately if we can (happens if tridactyl is reloaded or on ImageDocument) // Else load lazily to avoid upsetting page JS that hates foreign iframes. -try { - init() -} catch (e) { - // Surrender event loop with setTimeout() to page JS in case it's still doing stuff. - document.addEventListener("DOMContentLoaded", () => - setTimeout(() => { - try { - init() - } catch (e) { - logger.error("Couldn't initialise cmdline_iframe!", e) - } - }, 0), - ) -} +// try { +// init() +// } catch (e) { +// // Surrender event loop with setTimeout() to page JS in case it's still doing stuff. +// document.addEventListener("DOMContentLoaded", () => +// setTimeout(() => { +// try { +// init() +// } catch (e) { +// logger.error("Couldn't initialise cmdline_iframe!", e) +// } +// }, 0), +// ) +// } -export function show() { +export async function show() { try { + await init() cmdline_iframe.classList.remove("hidden") const height = cmdline_iframe.contentWindow.document.body.offsetHeight + "px" cmdline_iframe.setAttribute("style", `height: ${height} !important;`) + + // this actually helps a bit - an empty command line appears, + // so we're obviously not actually awaiting enough things. + // + // completions are broken though. + // + // setTimeout(_ => { + // cmdline_iframe.classList.remove("hidden") + // const height = + // cmdline_iframe.contentWindow.document.body.offsetHeight + "px" + // cmdline_iframe.setAttribute("style", `height: ${height} !important;`) + // },100) } catch (e) { // Note: We can't use cmdline_logger.error because it will try to log // the error in the commandline, which we can't show!