Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions custom-nodes/javascript_examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}
},
})
```