Skip to main content
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.

Migrating Canvas Menus

Old Approach (Deprecated)

The old approach modified the prototype during extension setup:
The new approach uses a dedicated extension hook:

Key Differences

Migrating Node Menus

Old Approach (Deprecated)

The old approach modified the node type prototype:
The new approach uses a dedicated extension hook:

Key Differences

Common Patterns

Conditional Menu Items

Both approaches support conditional items, but the new API is cleaner:

Adding Separators

Separators are added the same way in both approaches:

Creating Submenus

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:
  1. Remove all prototype modifications from setup() and beforeRegisterNodeDef()
  2. Add getCanvasMenuItems() and/or getNodeMenuItems() hooks
  3. Test that your menu items still appear correctly
  4. Verify no deprecation warnings appear in the console

Complete Migration Example

Before:
After:

Additional Resources