{"record":{"id":"82bb4c570a2083a0","repo":"microsoft/playwright","slug":"path-unsupported-mime-type-mimetype","errorCode":null,"errorMessage":"path: unsupported mime type \"${mimeType}\"","messagePattern":"path: unsupported mime type \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/client/elementHandle.ts","lineNumber":333,"sourceCode":"    };\n  }\n\n  const payloads = items as FilePayload[];\n  if (filePayloadExceedsSizeLimit(payloads))\n    throw new Error('Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.');\n  return { payloads };\n}\n\nexport function determineScreenshotType(options: { path?: string, type?: 'png' | 'jpeg' | 'webp' }): 'png' | 'jpeg' | 'webp' | undefined {\n  if (options.path) {\n    const mimeType = getMimeTypeForPath(options.path);\n    if (mimeType === 'image/png')\n      return 'png';\n    else if (mimeType === 'image/jpeg')\n      return 'jpeg';\n    else if (mimeType === 'image/webp')\n      return 'webp';\n    throw new Error(`path: unsupported mime type \"${mimeType}\"`);\n  }\n  return options.type;\n}\n","sourceCodeStart":315,"sourceCodeEnd":337,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/client/elementHandle.ts#L315-L337","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a supported extension: .png, .jpg/.jpeg, or .webp.","If you must use a different filename, pass an explicit type: screenshot({ path: 'shot.dat', type: 'png' }) (then rename on disk if needed).","Check the path string for typos before the call."],"exampleFix":"// before\nawait page.screenshot({ path: 'shot.bmp' });\n\n// after\nawait page.screenshot({ path: 'shot.png' });","handlingStrategy":"type-guard","validationCode":"import { extname } from 'node:path';\nconst SUPPORTED = new Set(['.png', '.jpg', '.jpeg', '.webp']);\nfunction assertScreenshotPath(p) {\n  if (!SUPPORTED.has(extname(p).toLowerCase()))\n    throw new Error(`Unsupported screenshot extension ${extname(p)}; use .png, .jpg, or .webp`);\n}","typeGuard":"import { extname } from 'node:path';\nfunction isSupportedScreenshotPath(p: string): boolean {\n  return new Set(['.png', '.jpg', '.jpeg', '.webp']).has(extname(p).toLowerCase());\n}","tryCatchPattern":null,"preventionTips":["Restrict screenshot paths to .png/.jpg/.jpeg/.webp.","If the filename must differ, pass type explicitly: screenshot({ path, type: 'png' }).","Lint config-derived paths for supported extensions."],"tags":["screenshot","validation","mime-type"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}