Skip to content

Custom widget problem on 2nd Firefox window #84

@garywill

Description

@garywill

I'm having problems with CustomizableUI.createWidget({ type: "custom" } ) .

When I was using Firefox 128 with xiaoxiaoflood's uc loader, it worked fine.
Recently I upgraded to Firefox 140 and migrated to your uc loader.

I found this code has problem:

console.debug("cusotom_widget.uc.js");

function funcA() {
    console.log('funcA()');
    console.log('123');
}
function funcB() {
    console.log('funcB()');
    console.log('456');
}
function funcC() {
    console.log('funcC()');
    console.log('789');
}

ChromeUtils.importESModule("resource:///modules/CustomizableUI.sys.mjs")

CustomizableUI.createWidget({
    type: "custom",
    id: "abcd", // button id
    defaultArea: CustomizableUI.AREA_NAVBAR,
    removable: true,
    onBuild: function (doc) {
        let btn = doc.createXULElement('toolbarbutton');
        btn.id = 'abcd';
        btn.label = 'btn abcd';
        btn.tooltipText = 'btn abcd';
        btn.type = 'menu';
        btn.style.width = '20px';
        btn.style.height = '20px';
        btn.onclick = funcA;

        let mp = doc.createXULElement("menupopup");
        mp.addEventListener('popupshowing', funcB);

        let menuitem = doc.createXULElement("menuitem");
        menuitem.label = "menu item text";
        menuitem.onclick = funcC;

        mp.appendChild(menuitem);

        btn.appendChild(mp);

        return btn;
    },
});

Steps to reproduce:

  1. Run Firefox. Open Browser Toolbox (ctrl+shift+alt+I)
  2. Click the custom widget created by above uc.js code. Menu pops up. Click the menu item. funcA() ~ funcC() logs can appear in console. Events can trigger.
  3. Close Browser Toolbox
  4. Firefox Menu -> New Window. Open a 2nd window.
  5. Close the 1st window.
  6. Open Browser Toolbox from the 2nd window
  7. Try step 2 again. Now no logs can appear. Events funcA() ~ funcC() can't trigger

It seems that when the 1st window is closed, events or functions funcA() ~ funcC() are destroyed. (If keep 2 Firefox main windows open, events can trigget on both windows)

I need to use type: custom when creating custom widget, so I can't use onCommand like general widget.

Any solutions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions