Merge pull request #5260 from Chic-Tweetz/cmdline-check-isconnected

Reinsert the iframe if it's removed before document.readyState "complete"
This commit is contained in:
Oliver Blanthorn 2025-09-13 12:09:30 +00:00 committed by GitHub
commit 5b278be67e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View file

@ -267,6 +267,7 @@ if (
}
// Really bad status indicator
let statusIndicator
config.getAsync("modeindicator").then(mode => {
if (mode !== "true") return
@ -284,7 +285,7 @@ config.getAsync("modeindicator").then(mode => {
}
}`
const statusIndicator = document.createElement("span")
statusIndicator = document.createElement("span")
const privateMode = browser.extension.inIncognitoContext
? "TridactylPrivate"
: ""
@ -315,7 +316,7 @@ config.getAsync("modeindicator").then(mode => {
// This listener makes the modeindicator disappear when the mouse goes over it
statusIndicator.addEventListener("mouseenter", ev => {
const target = ev.target as any
const target = ev.target
const rect = target.getBoundingClientRect()
target.classList.add("TridactylInvisible")
const onMouseOut = ev => {
@ -468,6 +469,20 @@ document.addEventListener("selectionchange", () => {
}
})
// Try to catch the iframe/status indicator being removed by a script (React again)
const checkElemsSurvived = () => {
if (document.readyState === "complete") {
commandline_content.ensureIframeExists()
if (statusIndicator !== undefined)
document.body.appendChild(statusIndicator)
// We only want to check the iframe survived between "interactive" and "complete"
document.removeEventListener("readystatechange", checkElemsSurvived)
}
}
document.addEventListener("readystatechange", checkElemsSurvived)
// Listen for statistics from each content script and send them to the
// background for collection. Attach the observer to the window object
// since there's apparently a bug that causes performance observers to

View file

@ -99,6 +99,12 @@ init().catch(() => {
)
})
export function ensureIframeExists() {
if (cmdline_iframe && !cmdline_iframe.isConnected) {
document.documentElement.appendChild(cmdline_iframe)
}
}
export function show(hidehover = false) {
try {
/* Hide "hoverlink" pop-up which obscures command line
@ -114,6 +120,7 @@ export function show(hidehover = false) {
document.body.removeChild(a)
}
ensureIframeExists()
cmdline_iframe.inert = false;
cmdline_iframe.classList.remove("hidden")
const height =
@ -156,7 +163,7 @@ export function hide_and_blur() {
export function executeWithoutCommandLine(fn) {
let parent
if (cmdline_iframe) {
if (cmdline_iframe && cmdline_iframe.isConnected) {
parent = cmdline_iframe.parentNode
parent.removeChild(cmdline_iframe)
}