microsoft/playwright · error · Error
Cannot set buffer larger than 50Mb, please write it to a fil
Error message
Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.
What it means
Thrown by convertInputFiles when the in-memory payload branch is taken and filePayloadExceedsSizeLimit returns true. The limit is fileUploadSizeLimit = 50 * 1024 * 1024 (50 MiB), summed across every payload's buffer.byteLength. Buffers are sent inline over the protocol; large uploads must go through file paths so the server can stream them.
Source
Thrown at packages/playwright-core/src/client/elementHandle.ts:320
}, kNoTimeout), { internal: true });
for (let i = 0; i < files.length; i++) {
const writable = WritableStream.from(writableStreams[i]);
await stream.promises.pipeline(fs.createReadStream(files[i]), writable.stream());
}
return {
directoryStream: rootDir,
streams: localDirectory ? undefined : writableStreams,
};
}
return {
localPaths,
localDirectory,
};
}
const payloads = items as FilePayload[];
if (filePayloadExceedsSizeLimit(payloads))
throw new Error('Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.');
return { payloads };
}
export function determineScreenshotType(options: { path?: string, type?: 'png' | 'jpeg' | 'webp' }): 'png' | 'jpeg' | 'webp' | undefined {
if (options.path) {
const mimeType = getMimeTypeForPath(options.path);
if (mimeType === 'image/png')
return 'png';
else if (mimeType === 'image/jpeg')
return 'jpeg';
else if (mimeType === 'image/webp')
return 'webp';
throw new Error(`path: unsupported mime type "${mimeType}"`);
}
return options.type;
}
View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Write the buffer to a temp file and pass its path instead: setInputFiles('/tmp/big.bin').
- If multiple large files, pass their paths (paths are streamed, not buffered).
- Compress or chunk the payload to stay under 50 MiB if a temp file is impossible.
Example fix
// before
const buf = await fs.promises.readFile('/tmp/big.bin'); // > 50 MiB
await locator.setInputFiles({ name: 'big.bin', mimeType: 'application/octet-stream', buffer: buf });
// after
await locator.setInputFiles('/tmp/big.bin'); Defensive patterns
Strategy: validation
Validate before calling
const LIMIT = 50 * 1024 * 1024; // matches fileUploadSizeLimit
function totalPayloadSize(payloads) {
return payloads.reduce((n, p) => n + (p.buffer ? p.buffer.byteLength : 0), 0);
}
function assertUnderLimit(payloads) {
if (totalPayloadSize(payloads) >= LIMIT)
throw new Error('Combined buffer size ≥ 50 MiB; write to temp files and pass paths instead.');
} Type guard
import { statSync } from 'node:fs';
// Prefer path-based input for large files — paths bypass the 50 MiB inline limit.
function isLargeFile(p: string): boolean { try { return statSync(p).size >= 50 * 1024 * 1024; } catch { return false; } } Prevention
- Default to file paths for uploads; reserve buffers for small in-memory data.
- Sum buffer sizes before assembling the payload list.
- Write oversized buffers to a temp file with fs.promises.writeFile.
When it happens
Trigger: Passing FilePayload objects whose combined buffer size is ≥ 50 MiB, e.g. setInputFiles([{ name: 'big.bin', buffer: hugeBuffer }]). The size guard rejects before any transfer.
Common situations: Reading large media/archives into memory and uploading as buffers; converting many files to payloads in a loop; pushing log/data dumps.
Related errors
- Multiple directories are not supported
- File paths must be all files or a single directory
- File paths cannot be mixed with buffers
- localPaths are not allowed when the client is not local
- Exactly one of payloads, localPaths and streams must be prov
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/4f64fb0eca4a1c3d.
Report an issue: GitHub.