Plugin dev: trouble displaying an icon next to a menu item with registerMenu()

38 views
Skip to first unread message

A. Jesse Jiryu Davis

unread,
Dec 2, 2025, 4:22:28 PM (2 days ago) Dec 2
to zotero-dev
Hello! I'm developing a plugin with Zotero 8.0-beta.19+b9ef88d4f. I can add a menu item using Zotero.MenuManager.registerMenu(), but the icon is never visible.

    const icon = `chrome://${addon.data.config.addonRef}/content/icons/fav...@0.5x.png`;
    Zotero.MenuManager.registerMenu({
      menuID: `${addon.data.config.addonRef}-rightclick-menuitem`,
      pluginID: addon.data.config.addonID,
      target: "main/library/item",
      menus: [
        {
          menuType: "menuitem",
          l10nID: `${addon.data.config.addonRef}-menuitem-label`,
          // TODO: the icon doesn't appear in the menu
          icon: icon,
        },
      ],
    });

The "Metadata Search" item should have a magnifying class icon to its left, but it doesn't (see attachment).

I think the icon path is correct, because if I use the zotero-plugin-toolkit MenuManager then the icon displays correctly! But the zotero-plugin-toolkit MenuManager is deprecated in favor of the new Zotero.MenuManager, so I'm trying to use only the latter in my code, and I can't make the icon display.

I used the Firefox debugger to step into Zotero's menuManager.js, and it definitely executed this line where it adds my icon to the menu element. But I still don't see the icon.

Here's the relevant code in my repo. Do you have any suggestions for how to debug this? I.e., how do I double-check that the icon path is correct, or figure out why the Firefox runtime isn't displaying it?

Thanks.
Screenshot 2025-12-02 at 3.51.09 PM.png

XY Wong

unread,
Dec 2, 2025, 5:17:08 PM (2 days ago) Dec 2
to zotero-dev
On MacOS, the context menus are not supposed to have icon, at least before MacOS 26 . Though you can use hacky approaches to let the icon be displayed, that's not recommended.

MacOS 26 has added icons to the context menu e.g. in Finder, so maybe we should allow that as well in the API. We'll see what we can do here.

A. Jesse Jiryu Davis

unread,
Dec 2, 2025, 5:27:15 PM (2 days ago) Dec 2
to zotero-dev
Thanks. It seems like icons should be displayed in that menu, but there's a bug, either in my code or in MenuManager. The menu is the right-click context menu in the library pane, target "main/library/item". Other plugins have somehow successfully added icons there, you can see in my screenshot that Better BibTeX and PapersGPT both have icons right above my plugin's item. (My plugin added the "Metadata Search"). And the MenuManager.registerMenu() function leads to this code which tries to display an icon—it just isn't working.

A. Jesse Jiryu Davis

unread,
Dec 2, 2025, 7:34:09 PM (2 days ago) Dec 2
to zotero-dev
I fell back to the zotero-plugin-toolkit MenuManager in this commit, and now my icon appears properly (see the magnifying glass icon in the attachment). I'll wait and see if a later Zotero 8 beta fixes icons for menu items created with the new builtin MenuManager.
Screenshot 2025-12-02 at 7.31.04 PM.png

XY Wong

unread,
Dec 3, 2025, 5:14:27 AM (2 days ago) Dec 3
to zotero-dev
> It seems like icons should be displayed in that menu, but there's a bug,

As I explained above, this is on purpose to not display the icon for context menu on MacOS. We'll need to decide if that should be changed for MacOS 26; but for lower MacOS versions, the icons should never be displayed there.

A. Jesse Jiryu Davis

unread,
Dec 3, 2025, 8:35:43 AM (2 days ago) Dec 3
to zoter...@googlegroups.com
OK, I thought we must be miscommunicating, because what you told me doesn't match the code I see in the new MenuManager. Perhaps that's because MenuManager is still being developed? Anyway thanks for your answer, I'll stop trying to debug this if it's intended behavior.

--
You received this message because you are subscribed to a topic in the Google Groups "zotero-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zotero-dev/JJ7c1XV0QHU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/zotero-dev/899b02d8-c98c-417e-97c8-87e70b4fe2a2n%40googlegroups.com.

XY Wong

unread,
Dec 3, 2025, 8:42:00 AM (2 days ago) Dec 3
to zotero-dev
To be clear, the `MenuManager` is doing exactly what it is designed to. The context menu icon is globally disabled elsewhere.
Reply all
Reply to author
Forward
0 new messages