jackwener/OpenCLI · error · CommandExecutionError

Midjourney media download returned unexpected content type "

Error message

Midjourney media download returned unexpected content type "${payload.type || 'unknown'}"

What it means

The media downloaded successfully, but its content-type header does not start with the expected MIME prefix (e.g. expected 'image/' but got 'text/html' or 'application/json'). This usually means the CDN returned an error page or a redirect/interstitial instead of the actual media file.

Source

Thrown at clis/midjourney/utils.js:560

        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) => {
        const bytes = window[key];
        if (!(bytes instanceof Uint8Array)) return null;
        const chunk = bytes.subarray(start, Math.min(bytes.length, start + length));
        let binary = '';
        const binaryChunkSize = 0x8000;
        for (let index = 0; index < chunk.length; index += binaryChunkSize) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-resolve the media URL (the current one is likely serving an interstitial or wrong resource).
  2. Check the reported content type: 'text/html' usually means a challenge/login page; refresh browser session/cookies.
  3. Confirm you are requesting the correct media kind for the job/index.
  4. Retry later if a bot-challenge page is being served.
Defensive patterns

Strategy: validation

Validate before calling

const res = await fetch(url, { method: 'HEAD' });
const ct = res.headers.get('content-type') || '';
if (!ct.startsWith('image/')) throw new Error('Unexpected content-type ' + ct + '; re-resolve URL');

Try / catch

try {
  await downloadMedia(page, url);
} catch (err) {
  if (/unexpected content type/.test(err.message)) {
    const freshUrl = await resolveFreshUrl(jobId); // interstitial/challenge guard
    await downloadMedia(page, freshUrl);
  } else throw err;
}

Prevention

When it happens

Trigger: CDN returns an HTML error page with 200 status; a login/consent interstitial page replaces the media; the URL points to a different resource type than expectedMimePrefix (e.g. expecting video but getting image).

Common situations: Expired sessions where the CDN serves an HTML sign-in page; Cloudflare-style challenge pages; passing an image URL where a video was expected.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/692bee3685a41770. Report an issue: GitHub.