diff --git a/custom-nodes/javascript_examples.mdx b/custom-nodes/javascript_examples.mdx index 62461e6c..33f2e210 100644 --- a/custom-nodes/javascript_examples.mdx +++ b/custom-nodes/javascript_examples.mdx @@ -133,3 +133,33 @@ async nodeCreated(node) { } } ``` + +## Node customization + +### Adding a button widget to a node + +```javascript +import { app } from "../../scripts/app.js" +import { api } from "../../scripts/api.js" + +app.registerExtension({ + name: "my.custom.extension", + async nodeCreated(node, app) { + console.log("node created", node, node.comfyClass) + if (node.comfyClass === "ParamSequenceInput") { + node.addWidget("button", "Queue Prompt", "This queues the prompt just like the normal queue btn", async () => { + console.log("button clicked") + const prompt = await app.graphToPrompt() + console.log("current prompt", prompt) + + // you could add logic to modify the prompt here + + await api.queuePrompt(1, prompt) + // using api.queuePrompt(1, prompt) lets you pass a custom prompt object + // app.queuePrompt() will queue with the result of app.graphToPrompt() + console.log("queued prompt") + }) + } + }, +}) +``` \ No newline at end of file