Stable Diffusion: fix stack overflow logging comfy workflows with large images The base64-redaction regex added to the workflow debug log blew V8's stack (RangeError: Maximum call stack size exceeded) once a real multi-megabyte reference image was substituted in, killing every ComfyUI generation client-side before the request was sent. Log the workflow before image payloads are substituted instead - same privacy benefit, no regex over huge strings.
| @@ -5227,6 +5227,13 @@ async function generateComfyImageCommon(prompt, negativePrompt, signal, basePath | |||
| 5227 | (extension_settings.sd.comfy_placeholders ?? []).forEach(ph => { | 5227 | (extension_settings.sd.comfy_placeholders ?? []).forEach(ph => { |
| 5228 | workflow = workflow.replaceAll(`"%${ph.find}%"`, JSON.stringify(substituteParams(ph.replace))); | 5228 | workflow = workflow.replaceAll(`"%${ph.find}%"`, JSON.stringify(substituteParams(ph.replace))); |
| 5229 | }); | 5229 | }); |
| 5230 | // Log the workflow before image payloads are substituted in: keeps private | ||
| 5231 | // image data (avatars, reference images) out of the console and avoids | ||
| 5232 | // scanning multi-megabyte strings (a redaction regex here previously blew | ||
| 5233 | // the stack on large reference images). | ||
| 5234 | console.log(`{ | ||
| 5235 | "prompt": ${workflow} | ||
| 5236 | }`); | ||
| 5230 | if (/%user_avatar%/gi.test(workflow)) { | 5237 | if (/%user_avatar%/gi.test(workflow)) { |
| 5231 | const response = await fetch(getUserAvatarUrl()); | 5238 | const response = await fetch(getUserAvatarUrl()); |
| 5232 | if (response.ok) { | 5239 | if (response.ok) { |
| @@ -5261,10 +5268,6 @@ async function generateComfyImageCommon(prompt, negativePrompt, signal, basePath | |||
| 5261 | workflow = workflow.replaceAll('"%reference_image%"', JSON.stringify(refBase64)); | 5268 | workflow = workflow.replaceAll('"%reference_image%"', JSON.stringify(refBase64)); |
| 5262 | workflow = workflow.replaceAll('"%reference-image%"', JSON.stringify(refBase64)); | 5269 | workflow = workflow.replaceAll('"%reference-image%"', JSON.stringify(refBase64)); |
| 5263 | } | 5270 | } |
| 5264 | // Log the workflow with base64 image payloads redacted (avatars/reference images are private). | ||
| 5265 | console.log(`{ | ||
| 5266 | "prompt": ${workflow.replace(/"[A-Za-z0-9+/=]{200,}"/g, '"<base64 image redacted>"')} | ||
| 5267 | }`); | ||
| 5268 | const promptResult = await fetch(`${basePath}/generate`, { | 5271 | const promptResult = await fetch(`${basePath}/generate`, { |
| 5269 | method: 'POST', | 5272 | method: 'POST', |
| 5270 | headers: getRequestHeaders(), | 5273 | headers: getRequestHeaders(), |