{"record":{"id":"40a1f354cb13a589","repo":"jackwener/OpenCLI","slug":"midjourney-media-transfer-lost-its-browser-buffer","errorCode":null,"errorMessage":"Midjourney media transfer lost its browser buffer at byte ${offset}","messagePattern":"Midjourney media transfer lost its browser buffer at byte (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":584,"sourceCode":"\n    // Returning a complete base64 file in one Browser Bridge response can\n    // exceed the daemon message limit. Pull it out in bounded chunks instead.\n    const parts = [];\n    const chunkSize = 96 * 1024;\n    for (let offset = 0; offset < size; offset += chunkSize) {\n      const base64 = unwrapEvaluateResult(await page.evaluate((key, start, length) => {\n        const bytes = window[key];\n        if (!(bytes instanceof Uint8Array)) return null;\n        const chunk = bytes.subarray(start, Math.min(bytes.length, start + length));\n        let binary = '';\n        const binaryChunkSize = 0x8000;\n        for (let index = 0; index < chunk.length; index += binaryChunkSize) {\n          binary += String.fromCharCode(...chunk.subarray(index, index + binaryChunkSize));\n        }\n        return btoa(binary);\n      }, transferKey, offset, chunkSize));\n      if (typeof base64 !== 'string' || !base64) {\n        throw new CommandExecutionError(`Midjourney media transfer lost its browser buffer at byte ${offset}`);\n      }\n      parts.push(Buffer.from(base64, 'base64'));\n    }\n    const buffer = Buffer.concat(parts);\n    if (buffer.length !== size) {\n      throw new CommandExecutionError(`Midjourney media transfer size mismatch: expected ${size}, received ${buffer.length}`);\n    }\n    return { buffer, mime: String(payload.type || '').split(';', 1)[0].toLowerCase() };\n  } finally {\n    await page.evaluate((key) => {\n      delete window[key];\n      return true;\n    }, transferKey).catch(() => {});\n  }\n}\n\nfunction sniffMediaMime(buffer) {\n  if (!Buffer.isBuffer(buffer) || buffer.length < 4) return null;","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L566-L602","documentation":"While reading the media back out of the browser window buffer in bounded base64 chunks, a chunk read returned nothing (empty/non-string). This means the browser-side buffer stored under transferKey disappeared or was never populated at that offset, so the transfer is aborted to prevent a corrupted file.","triggerScenarios":"The page was reloaded or navigated between chunk reads, wiping window[transferKey]; another script overwrote or deleted the buffer; the page.evaluate call returned an empty string for a chunk; concurrent transfers on the same page clobbering the key.","commonSituations":"Automation that navigates the page while a large video download is still chunking; sharing one browser page across parallel downloads; very long transfers hitting page instability.","solutions":["Retry the download ensuring the page is not navigated during the transfer.","Download media one at a time (no concurrent transfers sharing the same page/key).","Use a dedicated/stable page for the transfer.","Reduce pressure on the browser session and retry if instability persists."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) throw new Error('Page unstable; stabilize before chunked transfer');","typeGuard":null,"tryCatchPattern":"try {\n  await downloadMedia(page, url);\n} catch (err) {\n  if (/lost its browser buffer/.test(err.message)) {\n    page = await newPage(browser); // fresh page restores window buffer\n    await downloadMedia(page, url);\n  } else throw err;\n}","preventionTips":["Never navigate or reload the page mid-transfer.","Use a dedicated page per download; never share one page for concurrent transfers.","Keep transfers within a stable browser session (avoid long-lived fragile pages).","Keep automation scripts from deleting window keys during a transfer."],"tags":["browser","data-loss","chunked-transfer","midjourney"],"backgroundTag":"browser-buffer-lost","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}