jackwener/OpenCLI · error · CommandExecutionError
Midjourney browser-context media fetch failed: ${errorMessag
Error message
Midjourney browser-context media fetch failed: ${errorMessage(error)} What it means
This error wraps any failure that occurs while executing an in-page fetch inside the Midjourney browser context (page.evaluate) to download media into a window buffer. If the browser-side fetch itself throws (navigation, execution context destroyed, page closed, or fetch rejection), the raw error is rethrown as a CommandExecutionError with a normalized message via errorMessage(error).
Source
Thrown at clis/midjourney/utils.js:554
let payload;
try {
payload = unwrapEvaluateResult(await page.evaluate(async (mediaUrl, key) => {
// CDN is public but Cloudflare-protected. Browser-origin fetch succeeds
// with default same-origin credential mode; forcing cross-origin cookies
// turns it into a credentialed CORS request and Midjourney rejects it.
const response = await fetch(mediaUrl);
if (!response.ok) return { ok: false, status: response.status, type: response.headers.get('content-type') || '' };
const bytes = new Uint8Array(await response.arrayBuffer());
window[key] = bytes;
return {
ok: true,
status: response.status,
type: response.headers.get('content-type') || '',
size: bytes.length,
};
}, url, transferKey));
} catch (error) {
throw new CommandExecutionError(`Midjourney browser-context media fetch failed: ${errorMessage(error)}`);
}
if (!payload || typeof payload !== 'object' || !payload.ok) {
throw new CommandExecutionError(`Midjourney media download failed: HTTP ${payload?.status ?? 0} from ${url}`);
}
if (!String(payload.type || '').startsWith(expectedMimePrefix)) {
throw new CommandExecutionError(`Midjourney media download returned unexpected content type "${payload.type || 'unknown'}"`);
}
const size = Number(payload.size);
if (!Number.isInteger(size) || size <= 0) {
throw new CommandExecutionError(`Midjourney media download returned an empty file from ${url}`);
}
// Returning a complete base64 file in one Browser Bridge response can
// exceed the daemon message limit. Pull it out in bounded chunks instead.
const parts = [];
const chunkSize = 96 * 1024;
for (let offset = 0; offset < size; offset += chunkSize) {
const base64 = unwrapEvaluateResult(await page.evaluate((key, start, length) => {View on GitHub (pinned to 49907e53dc)
Solutions
- Retry the command; transient browser/network failures usually resolve.
- Verify the media URL is still valid (CDN links can expire).
- Ensure the browser page/browser bridge stays open for the duration of the download.
- Check proxy/firewall settings affecting the headless browser.
Example fix
// before downloadMedia(page, expiredUrl); // after const freshUrl = await resolveFreshMediaUrl(jobId); downloadMedia(page, freshUrl);
Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('Browser page closed; reopen before downloading'); Try / catch
try {
await downloadMedia(page, url);
} catch (err) {
if (/browser-context media fetch failed/.test(err.message)) {
page = await newPage(browser); // reopen page and retry once
await downloadMedia(page, url);
} else throw err;
} Prevention
- Keep the browser page open and idle during the whole download.
- Avoid navigating the page while transfers are in flight.
- Re-resolve CDN URLs before downloading (they expire).
- Download sequentially on a dedicated page to avoid races.
When it happens
Trigger: The browser page navigates away or its execution context is destroyed mid-fetch; the in-page fetch to the CDN URL throws (network error, CORS/blocked request, invalid URL); the browser bridge page is closed before the transfer completes.
Common situations: Fetching media right after the job page was closed; CDN URLs that have expired; proxy or network interruptions inside the headless browser; automation races where the page is reused concurrently.
Related errors
- Claude whoami failed: ${result.detail}
- Jike identity probe failed: ${probe.detail}
- Twitter device-follow fetch failed: ${data.detail || 'unknow
- Zhihu answer detail request failed: ${err instanceof Error ?
- Batch fetch failed for ${urls[i]}: ${(r as { error: string }
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/31f6e9fc40219451.
Report an issue: GitHub.