From 740d2bede4e4ab309c79e70d330d57fa24a24cda Mon Sep 17 00:00:00 2001 From: michalsn Date: Fri, 13 Feb 2026 22:02:10 +0100 Subject: [PATCH 1/2] fix: initialize standalone toolbar --- system/Debug/Toolbar/Views/toolbar.js | 3 +- system/Debug/Toolbar/Views/toolbar.tpl.php | 1 + .../Debug/Toolbar/Views/toolbarstandalone.js | 37 +++++++++++++++++++ user_guide_src/source/changelogs/v4.7.1.rst | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 system/Debug/Toolbar/Views/toolbarstandalone.js diff --git a/system/Debug/Toolbar/Views/toolbar.js b/system/Debug/Toolbar/Views/toolbar.js index 9e4547b6cb35..cf4d2e414c23 100644 --- a/system/Debug/Toolbar/Views/toolbar.js +++ b/system/Debug/Toolbar/Views/toolbar.js @@ -8,7 +8,8 @@ var ciDebugBar = { icon: null, init: function () { - this.toolbarContainer = document.getElementById("toolbarContainer"); + // Standalone debugbar pages do not have #toolbarContainer, use body as fallback. + this.toolbarContainer = document.getElementById("toolbarContainer") || document.body; this.toolbar = document.getElementById("debug-bar"); this.icon = document.getElementById("debug-icon"); diff --git a/system/Debug/Toolbar/Views/toolbar.tpl.php b/system/Debug/Toolbar/Views/toolbar.tpl.php index 0768f62915bb..b86baba23336 100644 --- a/system/Debug/Toolbar/Views/toolbar.tpl.php +++ b/system/Debug/Toolbar/Views/toolbar.tpl.php @@ -28,6 +28,7 @@
diff --git a/system/Debug/Toolbar/Views/toolbarstandalone.js b/system/Debug/Toolbar/Views/toolbarstandalone.js new file mode 100644 index 000000000000..ba6af288c763 --- /dev/null +++ b/system/Debug/Toolbar/Views/toolbarstandalone.js @@ -0,0 +1,37 @@ +/* + * Bootstrap for standalone Debug Toolbar pages (?debugbar_time=...). + */ + +if (! document.getElementById('debugbar_loader')) { + if (typeof loadDoc !== 'function') { + window.loadDoc = function (time) { + if (isNaN(time)) { + return; + } + + localStorage.setItem('debugbar-time', time); + localStorage.setItem('debugbar-time-new', time); + window.location.href = ciSiteURL + '?debugbar_time=' + time; + }; + } + + (function () { + function initStandaloneToolbar() { + if (typeof ciDebugBar !== 'object') { + return; + } + + if (! document.getElementById('debug-bar') || ! document.getElementById('debug-icon')) { + return; + } + + ciDebugBar.init(); + } + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', initStandaloneToolbar, false); + } else { + initStandaloneToolbar(); + } + })(); +} diff --git a/user_guide_src/source/changelogs/v4.7.1.rst b/user_guide_src/source/changelogs/v4.7.1.rst index 8a94a731a413..45b8da4c0614 100644 --- a/user_guide_src/source/changelogs/v4.7.1.rst +++ b/user_guide_src/source/changelogs/v4.7.1.rst @@ -34,6 +34,7 @@ Bugs Fixed - **ContentSecurityPolicy:** Fixed a bug where ``generateNonces()`` produces corrupted JSON responses by replacing CSP nonce placeholders with unescaped double quotes. The method now automatically JSON-escapes nonce attributes when the response Content-Type is JSON. - **Session:** Fixed a bug in ``MemcachedHandler`` where the constructor incorrectly threw an exception when ``savePath`` was not empty. +- **Toolbar:** Fixed a bug where the standalone toolbar page loaded from ``?debugbar_time=...`` was not interactive. See the repo's `CHANGELOG.md `_ From 73f0a829187df3036e92063d6b3338634e7c5c20 Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 14 Feb 2026 10:16:34 +0100 Subject: [PATCH 2/2] initialize standalone with ensureToolbarContainer --- system/Debug/Toolbar/Views/toolbar.js | 3 +- .../Debug/Toolbar/Views/toolbarstandalone.js | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/system/Debug/Toolbar/Views/toolbar.js b/system/Debug/Toolbar/Views/toolbar.js index cf4d2e414c23..9e4547b6cb35 100644 --- a/system/Debug/Toolbar/Views/toolbar.js +++ b/system/Debug/Toolbar/Views/toolbar.js @@ -8,8 +8,7 @@ var ciDebugBar = { icon: null, init: function () { - // Standalone debugbar pages do not have #toolbarContainer, use body as fallback. - this.toolbarContainer = document.getElementById("toolbarContainer") || document.body; + this.toolbarContainer = document.getElementById("toolbarContainer"); this.toolbar = document.getElementById("debug-bar"); this.icon = document.getElementById("debug-icon"); diff --git a/system/Debug/Toolbar/Views/toolbarstandalone.js b/system/Debug/Toolbar/Views/toolbarstandalone.js index ba6af288c763..f4a71d5463a7 100644 --- a/system/Debug/Toolbar/Views/toolbarstandalone.js +++ b/system/Debug/Toolbar/Views/toolbarstandalone.js @@ -9,22 +9,54 @@ if (! document.getElementById('debugbar_loader')) { return; } - localStorage.setItem('debugbar-time', time); - localStorage.setItem('debugbar-time-new', time); window.location.href = ciSiteURL + '?debugbar_time=' + time; }; } (function () { + function ensureToolbarContainer(icon, toolbar) { + let toolbarContainer = document.getElementById('toolbarContainer'); + + if (toolbarContainer) { + return; + } + + toolbarContainer = document.createElement('div'); + toolbarContainer.setAttribute('id', 'toolbarContainer'); + + if (icon) { + toolbarContainer.appendChild(icon); + } + + if (toolbar) { + toolbarContainer.appendChild(toolbar); + } + + document.body.appendChild(toolbarContainer); + } + function initStandaloneToolbar() { if (typeof ciDebugBar !== 'object') { return; } - if (! document.getElementById('debug-bar') || ! document.getElementById('debug-icon')) { + const icon = document.getElementById('debug-icon'); + const toolbar = document.getElementById('debug-bar'); + + if (! toolbar || ! icon) { return; } + const currentTime = new URLSearchParams(window.location.search).get('debugbar_time'); + + if (currentTime && ! isNaN(currentTime)) { + if (! localStorage.getItem('debugbar-time')) { + localStorage.setItem('debugbar-time', currentTime); + } + localStorage.setItem('debugbar-time-new', currentTime); + } + + ensureToolbarContainer(icon, toolbar); ciDebugBar.init(); }