Files
solidlime-Comfyui-Random_Im…/web/random_image_picker.js
T
solidlime 12cd33bbc8 Fix: Make image_data a visible widget and remove alert messages
Changes:
- Moved image_data from optional to required (no forceInput)
- image_data is now a multiline STRING widget (auto-filled by file picker)
- Removed alert() and console.log() messages
- Store base64 data in both node.properties and widget.value

This fixes the 'object supporting the buffer API required' error
by ensuring image_data widget exists and can be set by JavaScript.
2026-01-07 21:37:33 +09:00

60 lines
2.6 KiB
JavaScript

import { app } from "../../scripts/app.js";
app.registerExtension({
name: "Comfy.RandomImagePicker",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "RandomImagePicker") {
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
const result = onNodeCreated ? onNodeCreated.apply(this, arguments) : undefined;
const node = this;
// Add file picker button
node.addWidget("button", "📁 Choose File", null, () => {
const input = document.createElement("input");
input.type = "file";
input.accept = "image/png,image/jpeg,image/jpg,image/webp,image/bmp,image/gif";
input.onchange = (e) => {
if (e.target.files && e.target.files[0]) {
const file = e.target.files[0];
// Automatically switch to Single mode (folder_mode = False)
const folderModeWidget = node.widgets.find(w => w.name === "folder_mode");
if (folderModeWidget) {
folderModeWidget.value = false;
}
// Read file as base64
const reader = new FileReader();
reader.onload = (event) => {
const base64Data = event.target.result;
// Store image_data in node properties
if (!node.properties) {
node.properties = {};
}
node.properties.image_data = base64Data;
// Also try to set widget if it exists
let imageDataWidget = node.widgets.find(w => w.name === "image_data");
if (imageDataWidget) {
imageDataWidget.value = base64Data;
}
};
reader.readAsDataURL(file);
}
};
input.click();
});
return result;
};
}
}
});