This guide helps you migrate from the deprecated monkey-patching approach to the new context menu extension API.
The old approach of monkey-patching LGraphCanvas.prototype.getCanvasMenuOptions and nodeType.prototype.getExtraMenuOptions is deprecated:
If you see deprecation warnings in your browser console, your extension is using the old API and should be migrated.
Old Approach (Deprecated)
The old approach modified the prototype during extension setup:
New Approach (Recommended)
The new approach uses a dedicated extension hook:
Key Differences
Old Approach (Deprecated)
The old approach modified the node type prototype:
New Approach (Recommended)
The new approach uses a dedicated extension hook:
Key Differences
Common Patterns
Both approaches support conditional items, but the new API is cleaner:
Adding Separators
Separators are added the same way in both approaches:
The recommended way to create submenus is using the declarative submenu property:
This declarative approach is cleaner and matches the patterns used throughout the ComfyUI codebase.
While a callback-based approach with has_submenu: true and new LiteGraph.ContextMenu() is also supported, the declarative submenu property is preferred for better maintainability.
Accessing State
Troubleshooting
How to Identify Old API Usage
Look for these patterns in your code:
Understanding Deprecation Warnings
If you see this warning in the console:
Your extension is using the old approach and should be migrated.
Verifying Migration Success
After migration:
- Remove all prototype modifications from
setup() and beforeRegisterNodeDef()
- Add
getCanvasMenuItems() and/or getNodeMenuItems() hooks
- Test that your menu items still appear correctly
- Verify no deprecation warnings appear in the console
Complete Migration Example
Before:
After:
Additional Resources