mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 17:41:40 -05:00
Attempt to lazy-load iframe
Needs to be activated twice before it works.
This commit is contained in:
parent
799f2d3233
commit
8ee8f1d1ec
1 changed files with 28 additions and 16 deletions
|
@ -34,7 +34,6 @@ let enabled = false
|
||||||
async function init() {
|
async function init() {
|
||||||
let noiframe = await config.getAsync("noiframe")
|
let noiframe = await config.getAsync("noiframe")
|
||||||
if (noiframe == "false" && !enabled) {
|
if (noiframe == "false" && !enabled) {
|
||||||
hide()
|
|
||||||
document.documentElement.appendChild(cmdline_iframe)
|
document.documentElement.appendChild(cmdline_iframe)
|
||||||
enabled = true
|
enabled = true
|
||||||
// first theming of page root
|
// 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)
|
// 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.
|
// Else load lazily to avoid upsetting page JS that hates foreign iframes.
|
||||||
try {
|
// try {
|
||||||
init()
|
// init()
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
// Surrender event loop with setTimeout() to page JS in case it's still doing stuff.
|
// // Surrender event loop with setTimeout() to page JS in case it's still doing stuff.
|
||||||
document.addEventListener("DOMContentLoaded", () =>
|
// document.addEventListener("DOMContentLoaded", () =>
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
try {
|
// try {
|
||||||
init()
|
// init()
|
||||||
} catch (e) {
|
// } catch (e) {
|
||||||
logger.error("Couldn't initialise cmdline_iframe!", e)
|
// logger.error("Couldn't initialise cmdline_iframe!", e)
|
||||||
}
|
// }
|
||||||
}, 0),
|
// }, 0),
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
|
|
||||||
export function show() {
|
export async function show() {
|
||||||
try {
|
try {
|
||||||
|
await init()
|
||||||
cmdline_iframe.classList.remove("hidden")
|
cmdline_iframe.classList.remove("hidden")
|
||||||
const height =
|
const height =
|
||||||
cmdline_iframe.contentWindow.document.body.offsetHeight + "px"
|
cmdline_iframe.contentWindow.document.body.offsetHeight + "px"
|
||||||
cmdline_iframe.setAttribute("style", `height: ${height} !important;`)
|
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) {
|
} catch (e) {
|
||||||
// Note: We can't use cmdline_logger.error because it will try to log
|
// Note: We can't use cmdline_logger.error because it will try to log
|
||||||
// the error in the commandline, which we can't show!
|
// the error in the commandline, which we can't show!
|
||||||
|
|
Loading…
Add table
Reference in a new issue