{"record":{"id":"b66fcbd86a6c756a","repo":"jackwener/OpenCLI","slug":"midjourney-reference-upload-fallback-failed-res","errorCode":null,"errorMessage":"Midjourney reference upload fallback failed: ${result?.reason || 'unknown error'}","messagePattern":"Midjourney reference upload fallback failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":1040,"sourceCode":"    const transfer = new DataTransfer();\n    for (const item of window[key] || []) {\n      const binary = atob(item.chunks.join(''));\n      const bytes = new Uint8Array(binary.length);\n      for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);\n      transfer.items.add(new File([bytes], item.name, { type: item.mime }));\n    }\n    input.files = transfer.files;\n    const nativeEvent = new Event('change', { bubbles: true });\n    const propsKey = Object.keys(input).find((key) => key.startsWith('__reactProps$'));\n    if (propsKey && typeof input[propsKey]?.onChange === 'function') {\n      input[propsKey].onChange({ target: input, currentTarget: input, nativeEvent });\n    } else {\n      input.dispatchEvent(nativeEvent);\n      input.dispatchEvent(new Event('input', { bubbles: true }));\n    }\n    return { ok: true, count: transfer.files.length };\n    }, uploadKey));\n    if (!result?.ok) throw new CommandExecutionError(`Midjourney reference upload fallback failed: ${result?.reason || 'unknown error'}`);\n  } finally {\n    await page.evaluate((key) => {\n      delete window[key];\n      return true;\n    }, uploadKey).catch(() => {});\n  }\n}\n\nasync function markReferenceTarget(page, sourceUrl, slotLabel) {\n  const result = unwrapEvaluateResult(await page.evaluate((url, label) => {\n    document.querySelectorAll('[data-opencli-ref-source],[data-opencli-ref-target]').forEach((el) => {\n      el.removeAttribute('data-opencli-ref-source');\n      el.removeAttribute('data-opencli-ref-target');\n    });\n    const source = [...document.querySelectorAll('img[src]')].find((img) => img.src === url);\n    const labelNode = [...document.querySelectorAll('div,span')].find((node) => node.children.length === 0 && node.textContent?.trim() === label);\n    if (!source || !labelNode) return { ok: false, source: Boolean(source), target: Boolean(labelNode) };\n    let target = labelNode.parentElement;","sourceCodeStart":1022,"sourceCodeEnd":1058,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L1022-L1058","documentation":"Thrown when the page-level fallback upload path (dispatching native/input events on a file input inside the browser) returns a non-ok result. The evaluate returns {ok:false, reason} and the CLI surfaces the reason, defaulting to 'unknown error' when none is provided. It indicates the simulated file drop into Midjourney's reference input did not complete.","triggerScenarios":"Calling the fallback upload path after the primary drag-and-drop upload fails; page.evaluate dispatchEvent/natural file transfer returns {ok:false, reason:...} or returns null/undefined.","commonSituations":"Midjourney UI changed so the file input selector no longer matches; the injected DataTransfer/natural event pipeline is blocked; browser Bridge evaluate returns undefined; uploadKey global was already cleaned up by a concurrent run.","solutions":["Inspect result?.reason in the thrown message and fix the underlying in-page condition (missing input, disabled form).","Update the file input selector / event dispatch logic to match the current Midjourney composer DOM.","Ensure the browser Bridge (page.evaluate with native events) is up to date and the page is fully loaded before uploading.","Retry the upload after reloading the Midjourney page."],"exampleFix":"// before\nif (!result?.ok) throw new CommandExecutionError(`Midjourney reference upload fallback failed: ${result?.reason || 'unknown error'}`);\n// after\nif (!result?.ok) {\n  await page.reload();\n  await page.wait(2);\n  throw new CommandExecutionError(`Midjourney reference upload fallback failed: ${result?.reason || 'unknown error'}`);\n}","handlingStrategy":"retry","validationCode":"const probe = await page.evaluate(() => !!document.querySelector('input[type=file]'));\nif (!probe) throw new Error('No file input available for fallback upload');","typeGuard":"function isUploadResult(r) { return r && typeof r === 'object' && typeof r.ok === 'boolean'; }","tryCatchPattern":"try {\n  await uploadReferenceLibrary(page, paths);\n} catch (err) {\n  if (String(err.message).includes('fallback failed')) {\n    await page.reload();\n    await uploadReferenceLibrary(page, paths);\n  } else throw err;\n}","preventionTips":["Keep the Browser Bridge extension updated","Ensure the page is fully loaded before uploading","Log result.reason for diagnostics","Reload the page between retries"],"tags":["midjourney","browser-automation","file-upload","dom"],"backgroundTag":"browser-file-upload-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}