jackwener/OpenCLI · error · CommandExecutionError
Midjourney reference upload fallback could not initialize it
Error message
Midjourney reference upload fallback could not initialize its transfer buffer
What it means
For local files, the upload fallback initializes an in-page transfer buffer by pushing a file descriptor into a window-scoped array via page.evaluate. If the returned index is not a valid non-negative integer — meaning the buffer could not be created in the page context — this CommandExecutionError is thrown before any file data is transferred.
Source
Thrown at clis/midjourney/utils.js:1004
const uploadKey = `opencli_${Date.now()}_${Math.random().toString(36).slice(2)}`;
await page.evaluate((key) => {
window[key] = [];
return true;
}, uploadKey);
try {
for (const localPath of localPaths) {
const descriptor = {
name: path.basename(localPath),
mime: IMAGE_EXTENSIONS.get(path.extname(localPath).toLowerCase()),
};
const fileIndex = unwrapEvaluateResult(await page.evaluate((key, item) => {
const files = window[key];
if (!Array.isArray(files)) return -1;
files.push({ ...item, chunks: [] });
return files.length - 1;
}, uploadKey, descriptor));
if (!Number.isInteger(fileIndex) || fileIndex < 0) {
throw new CommandExecutionError('Midjourney reference upload fallback could not initialize its transfer buffer');
}
const base64 = (await fs.readFile(localPath)).toString('base64');
const chunkSize = 96 * 1024;
for (let offset = 0; offset < base64.length; offset += chunkSize) {
const chunk = base64.slice(offset, offset + chunkSize);
const appended = unwrapEvaluateResult(await page.evaluate((key, index, value) => {
const file = window[key]?.[index];
if (!file || !Array.isArray(file.chunks)) return false;
file.chunks.push(value);
return true;
}, uploadKey, fileIndex, chunk));
if (!appended) throw new CommandExecutionError('Midjourney reference upload fallback lost its transfer buffer');
}
}
const result = unwrapEvaluateResult(await page.evaluate((key) => {
const input = document.querySelector('[data-opencli-image-input="1"]');
if (!(input instanceof HTMLInputElement)) return { ok: false, reason: 'image file input not found' };
const transfer = new DataTransfer();View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the upload on a freshly loaded, stable page (avoid navigation during upload)
- Retry — transient context destruction during SPA re-renders often resolves on a second attempt
- Verify no browser extensions or page scripts interfere with injected window state
- Update the CLI in case the page's CSP or structure changed
Example fix
// before
await page.click('nav a'); // triggers SPA navigation mid-upload
await uploadReferences(page, refs);
// after
await uploadReferences(page, refs); // complete upload before any navigation
await page.click('nav a'); Defensive patterns
Strategy: retry
Validate before calling
const ok = await page.evaluate((k) => Array.isArray(window[k]), uploadKey);
if (!ok) throw new Error('Page context lost buffer key; reload before uploading'); Type guard
null
Try / catch
let lastErr;
for (let attempt = 0; attempt < 2; attempt++) {
try { await uploadReferences(page, refs); return; }
catch (e) {
if (!String(e.message).includes('transfer buffer')) throw e;
lastErr = e;
await page.reload();
}
}
throw lastErr; Prevention
- Never navigate or reload the page during an upload
- Upload on a freshly loaded, idle page
- Avoid extensions/scripts that clear injected window state
- Wrap uploads in a bounded retry with a page reload between attempts
When it happens
Trigger: The page.evaluate returning undefined/null due to a page navigation or context destruction mid-call, the evaluation being blocked by CSP or a page error, or the window-keyed array being reset between calls.
Common situations: The Midjourney tab navigated/reloaded while uploads were being prepared, an SPA route change destroyed the execution context, or an extension/script wiped the injected window state.
Related errors
- Midjourney reference upload fallback lost its transfer buffe
- Unexpected 12306 probe: ${JSON.stringify(probe)}
- Waiting for 12306 tk auth cookie
- amazon.com
- Unexpected Amazon probe: ${JSON.stringify(probe)}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/47d51b3128a96a5e.
Report an issue: GitHub.