{"record":{"id":"8eef8235360d538a","repo":"hakimel/reveal.js","slug":"please-specify-a-valid-media-type-to-preview","errorCode":null,"errorMessage":"Please specify a valid media type to preview","messagePattern":"Please specify a valid media type to preview","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"js/controllers/overlay.js","lineNumber":189,"sourceCode":"\t\t\tvideo.playsInline = true;\n\t\t\tvideo.src = url;\n\t\t\tcontentElement.appendChild( video );\n\n\t\t\tvideo.addEventListener( 'loadeddata', () => {\n\t\t\t\tthis.dom.dataset.state = 'loaded';\n\t\t\t}, false );\n\n\t\t\tvideo.addEventListener( 'error', () => {\n\t\t\t\tthis.dom.dataset.state = 'error';\n\t\t\t\tcontentElement.innerHTML =\n\t\t\t\t\t`<span class=\"r-overlay-error\">Unable to load video.</span>`;\n\t\t\t}, false );\n\n\t\t\tthis.Reveal.dispatchEvent({ type: 'previewvideo', data: { url } });\n\n\t\t}\n\t\telse {\n\t\t\tthrow new Error( 'Please specify a valid media type to preview' );\n\t\t}\n\n\t\tthis.dom.querySelector( '.r-overlay-close' ).addEventListener( 'click', ( event ) => {\n\t\t\tthis.close();\n\t\t\tevent.preventDefault();\n\t\t}, false );\n\n\t}\n\n\tpreviewImage( url, fitMode ) {\n\n\t\tthis.previewMedia( url, 'image', fitMode );\n\n\t}\n\n\tpreviewVideo( url, fitMode ) {\n\n\t\tthis.previewMedia( url, 'video', fitMode );","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/hakimel/reveal.js/blob/a3b940695648aa1c5b0680bc9a5b905cf43020e5/js/controllers/overlay.js#L171-L207","documentation":"Overlay.previewMedia(url, mediaType, fitMode) only recognizes two media types: 'image' and 'video' (branches at overlay.js:135 and :162). Any other mediaType value falls through to the trailing else and throws. The throw happens before any DOM or network work, so it is a pure argument-validation failure, not a load failure.","triggerScenarios":"Calling previewMedia (or a wrapper) with mediaType set to anything other than the literal strings 'image' or 'video' — e.g. 'audio', 'pdf', undefined, null, a typo like 'images', or a value read from an untrusted source. Also triggered when previewImage/previewVideo helpers are bypassed and a raw type string is passed in.","commonSituations":"Deriving mediaType from a file extension or MIME type and forgetting to normalize to the two accepted strings; passing an optional config field that was never set (undefined); copy-pasting a call without the type argument; attempting to preview a media kind reveal.js overlay does not support (audio, iframe, pdf).","solutions":["Pass one of the two supported literals: 'image' or 'video'. Prefer the previewImage(url, fitMode) / previewVideo(url, fitMode) helpers (overlay.js:199) so the type is hardcoded.","If mediaType comes from dynamic input, normalize it first: map MIME prefixes (image/* -> 'image', video/* -> 'video') and reject everything else before calling previewMedia.","Guard the call: only invoke previewMedia when the type is in {'image','video'}; otherwise log and skip rather than letting it throw.","Do not pass undefined hoping for a default — there is no default branch, only the throw."],"exampleFix":"// before\noverlay.previewMedia(url, fileType, fit); // fileType may be 'audio' or undefined\n\n// after\nif (fileType === 'image' || fileType === 'video') {\n  overlay.previewMedia(url, fileType, fit);\n} else {\n  console.warn(`Unsupported preview media type: ${fileType}`);\n}","handlingStrategy":"validation","validationCode":"const VALID_MEDIA_TYPES = new Set(['image', 'video']);\nfunction safePreviewMedia(overlay, url, mediaType, fitMode) {\n  if (!VALID_MEDIA_TYPES.has(mediaType)) {\n    console.warn(`previewMedia: unsupported mediaType '${mediaType}'; skipping.`);\n    return;\n  }\n  overlay.previewMedia(url, mediaType, fitMode);\n}","typeGuard":"function isOverlayMediaType(value) {\n  return value === 'image' || value === 'video';\n}","tryCatchPattern":null,"preventionTips":["Prefer the previewImage/previewVideo helpers so the type literal is fixed at the call site.","When deriving the type from a MIME string, normalize image/* -> 'image' and video/* -> 'video' and drop the rest.","Never pass an optional/possibly-undefined type field straight through to previewMedia."],"tags":["media","overlay","validation","argument-error"],"backgroundTag":null,"analyzedSha":"a3b940695648aa1c5b0680bc9a5b905cf43020e5","analyzedAt":"2026-08-12T23:46:52.821Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}