`window` argument to `devtools.panels.ExtensionSidebarPane.onShown` listeners is `undefined`
Categories
(WebExtensions :: Developer Tools, defect)
Tracking
(firefox135 affected, firefox136 affected, firefox137 affected)
People
(Reporter: bramus, Unassigned, NeedInfo)
References
Details
Steps to reproduce:
This is a follow-up to https://bugzilla.mozilla.org/show_bug.cgi?id=1852246, in which it was surfaced that the first and only argument to listeners passed into browser.devtools.panels.onShown.addListener
and browser.devtools.panels.onHidden.addListener
is always undefined
.
Demo REPO: https://github.com/bramus/devtools-extension-bug-sidebarpane-events
This extension logs the x
argument of the listener and also the global window
object.
const initSidebarPanel = (sidebarPane) => {
sidebarPane.setPage('devtools.html');
sidebarPane.onShown.addListener((x) => {
console.log('onShown', x, window);
});
sidebarPane.onHidden.addListener((x) => {
console.log('onHidden', x, window);
});
};
Actual results:
The logged value for x
is always undefined
.
Expected results:
According to https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane/onShown this value should be “The window
object of the sidebar page, if a page was set with setPage()
.”
Comment 1•1 month ago
|
||
Hello,
I reproduced the issue on the latest Nightly (137.0a1/20250209212051), Beta (136.0b3/20250207091649) and Release (135.0/20250130195129) on Windows 10 and Ubuntu 24.04 LTS.
After loading the extensions via about:debugging I opened a page in a new tab (Wikipedia) and opened devtools.
From the “Inspector” tab I selected an element and then from the sidebar I selected POC. Below is what was logged to console:
onShown undefined Window moz-extension://0df11701-5c4e-4481-90cc-419dec62416f/devtools-page.html devtools.js:5:17
After that, I selected something else from the sidebar. This was logged to console:
onHidden undefined Window moz-extension://0df11701-5c4e-4481-90cc-419dec62416f/devtools-page.html devtools.js:9:17
Comment 2•1 month ago
|
||
The implementation is at https://searchfox.org/mozilla-central/rev/7b3f3fb5fd2cad8f348131498a35a91bef68b47b/browser/components/extensions/child/ext-devtools-panels.js#189-196
const listener = (eventName, panelContentWindow) => {
fire.asyncWithoutClone(panelContentWindow);
};
this.on("shown", listener);
(this implementation seems to have been copied from the devtools.panels.onShown
implementation at https://searchfox.org/mozilla-central/rev/7b3f3fb5fd2cad8f348131498a35a91bef68b47b/browser/components/extensions/child/ext-devtools-panels.js#91-98)
... but the internal shown
event is never passed a window:
https://searchfox.org/mozilla-central/rev/7b3f3fb5fd2cad8f348131498a35a91bef68b47b/browser/components/extensions/child/ext-devtools-panels.js#156-158
recvInspectorSidebarShown() {
// TODO: wait and emit sidebar contentWindow once sidebar.setPage is supported.
this.emit("shown");
The setPage
method was added later in bug 1398734.
Luca: do you recall why the window is missing? Can this be fixed easily?
Description
•