From 766eab12e7e8e139ee7ed11550f242391d045227 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Sat, 7 Mar 2026 23:28:18 +0100 Subject: [PATCH] asdsad --- modules/pi_control/assets/console.js | 41 +++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/modules/pi_control/assets/console.js b/modules/pi_control/assets/console.js index 0a13946..92b792b 100644 --- a/modules/pi_control/assets/console.js +++ b/modules/pi_control/assets/console.js @@ -1,4 +1,13 @@ (() => { + // Disable any beforeunload prompts on this page + window.onbeforeunload = null; + window.addEventListener( + 'beforeunload', + (e) => { + e.stopImmediatePropagation(); + }, + { capture: true } + ); const tabBar = document.querySelector('[data-console-tab-bar]'); const tabPanels = document.querySelector('[data-console-tab-panels]'); if (!tabBar || !tabPanels) return; @@ -98,15 +107,33 @@ iframe.addEventListener('load', () => { try { - const clearUnload = () => { - if (!iframe.contentWindow) return; - iframe.contentWindow.onbeforeunload = null; - if (iframe.contentWindow.document) { - iframe.contentWindow.document.onbeforeunload = null; + const disableBeforeUnload = (win) => { + if (!win) return; + try { + win.onbeforeunload = null; + win.addEventListener( + 'beforeunload', + (e) => { + e.stopImmediatePropagation(); + }, + { capture: true } + ); + if (win.document) { + win.document.onbeforeunload = null; + win.document.addEventListener( + 'beforeunload', + (e) => { + e.stopImmediatePropagation(); + }, + { capture: true } + ); + } + } catch (err) { + // ignore } }; - clearUnload(); - setInterval(clearUnload, 2000); + disableBeforeUnload(iframe.contentWindow); + setInterval(() => disableBeforeUnload(iframe.contentWindow), 2000); const doc = iframe.contentWindow.document; ['keydown', 'mousedown', 'wheel', 'touchstart'].forEach((evt) => { doc.addEventListener(evt, markActive, { passive: true });