Documentation Index
Fetch the complete documentation index at: https://dripart-fix-cloud-button-text-1773163393.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Extension hooks
At various points during Comfy execution, the application calls#invokeExtensionsAsync or #invokeExtensions with the name of a hook.
These invoke, on all registered extensions, the appropriately named method (if present), such as setup
in the example above.
Comfy provides a variety of hooks for custom extension code to use to modify client behavior.
A few of the most significant hooks are described below.
As Comfy is being actively developed, from time to time additional hooks are added, so
search for #invokeExtensions in app.js to find all available hooks.
See also the sequence in which hooks are invoked.
Commonly used hooks
Start withbeforeRegisterNodeDef, which is used by the majority of extensions, and is often the only one needed.
beforeRegisterNodeDef()
Called once for each node type (the list of nodes available in theAddNode menu), and is used to
modify the behaviour of the node.
nodeType parameter essentially serves as a template
for all nodes that will be created of this type, so modifications made to nodeType.prototype will apply
to all nodes of this type. nodeData is an encapsulation of aspects of the node defined in the Python code,
such as its category, inputs, and outputs. app is a reference to the main Comfy app object (which you
have already imported anyway!)
The usual idiom is to check nodeType.ComfyClass, which holds the Python class name corresponding to this node,
to see if you need to modify the node. Often this means modifying the custom nodes that you have added,
although you may sometimes need to modify the behavior of other nodes (or other custom nodes
might modify yours!), in which case care should be taken to ensure interoperability.
A very common idiom in beforeRegisterNodeDef is to ‘hijack’ an existing method:
Deprecated: The prototype hijacking pattern shown below is deprecated and subject to change at any point in the near future. For context menus, use the official Context Menu API instead. For other use cases, prefer using the official extension hooks where available.
?.apply ensures that if there wasn’t one this is still safe) and then
performs additional operations. Depending on your code logic, you may need to place the apply elsewhere in your replacement code,
or even make calling it conditional.
When hijacking a method in this way, you will want to look at the core comfy code (breakpoints are your friend) to check
and conform with the method signature.
nodeCreated()
ComfyNode() function on nodeType which serves as a constructor).
In this hook you can make modifications to individual instances of your node.
init()
LiteGraph object). This is discussed further in Comfy Objects.
setup()
Call sequences
These sequences were obtained by insert logging code into the Comfyapp.js file. You may find similar code helpful
in understanding the execution flow.