microsoft/playwright · error · Error

path: unsupported mime type "${mimeType}"

Error message

path: unsupported mime type "${mimeType}"

What it means

Thrown by determineScreenshotType when options.path is set but its MIME type (resolved from the extension via getMimeTypeForPath) is not image/png, image/jpeg, or image/webp. The screenshot encoder needs one of these three formats; an unrecognized extension cannot be mapped to an encoder.

Source

Thrown at packages/playwright-core/src/client/elementHandle.ts:333

    };
  }

  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

  1. Use a supported extension: .png, .jpg/.jpeg, or .webp.
  2. If you must use a different filename, pass an explicit type: screenshot({ path: 'shot.dat', type: 'png' }) (then rename on disk if needed).
  3. Check the path string for typos before the call.

Example fix

// before
await page.screenshot({ path: 'shot.bmp' });

// after
await page.screenshot({ path: 'shot.png' });
Defensive patterns

Strategy: type-guard

Validate before calling

import { extname } from 'node:path';
const SUPPORTED = new Set(['.png', '.jpg', '.jpeg', '.webp']);
function assertScreenshotPath(p) {
  if (!SUPPORTED.has(extname(p).toLowerCase()))
    throw new Error(`Unsupported screenshot extension ${extname(p)}; use .png, .jpg, or .webp`);
}

Type guard

import { extname } from 'node:path';
function isSupportedScreenshotPath(p: string): boolean {
  return new Set(['.png', '.jpg', '.jpeg', '.webp']).has(extname(p).toLowerCase());
}

Prevention

When it happens

Trigger: Calling elementHandle.screenshot({ path: 'shot.bmp' }) (or .gif, .tiff, .heic, or any non-image extension). The path alone, without an explicit type, drives format selection; an unsupported extension aborts.

Common situations: Typo in the extension (.jp instead of .jpg); assuming a format like BMP/GIF/TIFF is supported; passing a path with no extension; copy-pasting a non-image filename.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/82bb4c570a2083a0. Report an issue: GitHub.