{"record":{"id":"e6c07c48c841aec9","repo":"jackwener/OpenCLI","slug":"browser-bridge-reported-downloaded-mime-for-s","errorCode":null,"errorMessage":"Browser Bridge reported ${downloaded.mime} for ${sourcePath}; detected ${actualMime} from file bytes","messagePattern":"Browser Bridge reported (.+?) for (.+?); detected (.+?) from file bytes","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"clis/midjourney/utils.js","lineNumber":782,"sourceCode":"  if (!sourceStat?.isFile() || sourceStat.size <= 0) {\n    throw new CommandExecutionError(`Browser reported a completed download but the file is missing: ${sourcePath}`);\n  }\n  const handle = await fs.open(sourcePath, 'r');\n  let actualMime;\n  try {\n    const header = Buffer.alloc(16);\n    const { bytesRead } = await handle.read(header, 0, header.length, 0);\n    actualMime = sniffMediaMime(header.subarray(0, bytesRead));\n  } finally {\n    await handle.close();\n  }\n  if (actualMime !== config.mime) {\n    throw new CommandExecutionError(\n      `Midjourney ${kind} returned invalid media bytes; expected ${config.mime}, detected ${actualMime || 'unknown'}`,\n    );\n  }\n  if (downloaded.mime && downloaded.mime !== actualMime) {\n    log.warn(`Browser Bridge reported ${downloaded.mime} for ${sourcePath}; detected ${actualMime} from file bytes`);\n  }\n  const tempPath = `${filePath}.part-${process.pid}-${Date.now()}`;\n  try {\n    await fs.copyFile(sourcePath, tempPath);\n    await fs.rename(tempPath, filePath);\n    if (sourcePath !== filePath) await fs.unlink(sourcePath).catch(() => {});\n  } catch (error) {\n    await fs.unlink(tempPath).catch(() => {});\n    throw new CommandExecutionError(`Could not store Midjourney ${kind} at ${filePath}: ${errorMessage(error)}`);\n  }\n  return {\n    index,\n    kind,\n    filePath,\n    bytes: sourceStat.size,\n    url: stringOrNull(downloaded.finalUrl ?? downloaded.url),\n    mime: actualMime,\n    cached: false,","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L764-L800","documentation":"After copying media produced by the Browser Bridge, the MIME the bridge reported for the downloaded file differs from the type sniffed from the file's bytes. The sniffed type already matched the expected config.mime (a mismatch would have thrown), so this warns that the bridge's reported metadata was wrong and continues the atomic move into place.","triggerScenarios":"Browser Bridge downloads a Midjourney image/video to a temp path; downloaded.mime is set and differs from sniffMediaMime of the file contents, while the actual bytes match the required type.","commonSituations":"Older extension versions reporting default or generic MIME types, browser assigning Content-Type from the URL extension, bridge download interception layer mislabeling files.","solutions":["No action needed if the output file is valid — the byte-level check passed","Update the browser extension to v1.6+ (CDP-based upload/download fixes metadata reporting)","Verify the saved file opens/plays with the expected type","Re-run the download if the file is unexpectedly corrupt"],"exampleFix":"// before: outdated extension misreports mime\n// warn: Browser Bridge reported application/octet-stream for /tmp/x.jpg; detected image/jpeg\n// after\n// Update extension to v1.6+ so reported mime matches detected bytes","handlingStrategy":"validation","validationCode":"const actual = sniffMediaMime(fs.readFileSync(sourcePath));\nif (actual !== expectedMime) throw new Error(`Bridge file mime mismatch: ${actual}`);","typeGuard":"const matches = (downloaded, actual) => !downloaded.mime || downloaded.mime === actual;","tryCatchPattern":"try {\n  await downloadRenderedVideo(page, jobId, index, kind, dir);\n} catch (err) {\n  if (/invalid media bytes/.test(err.message)) { /* retry; consider updating the extension */ }\n}","preventionTips":["Keep the browser extension at v1.6+ so reported MIME is reliable","Validate bytes, not just reported metadata, before moving files into place","Use atomic .part-file renames as the library does","Spot-check downloaded files with a MIME probe in CI"],"tags":["mime-mismatch","browser-bridge","midjourney","extension"],"backgroundTag":"content-type-mismatch","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}