hakimel/reveal.js · error · Error
Please specify a valid media type to preview
Error message
Please specify a valid media type to preview
What it means
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.
Source
Thrown at js/controllers/overlay.js:189
video.playsInline = true;
video.src = url;
contentElement.appendChild( video );
video.addEventListener( 'loadeddata', () => {
this.dom.dataset.state = 'loaded';
}, false );
video.addEventListener( 'error', () => {
this.dom.dataset.state = 'error';
contentElement.innerHTML =
`<span class="r-overlay-error">Unable to load video.</span>`;
}, false );
this.Reveal.dispatchEvent({ type: 'previewvideo', data: { url } });
}
else {
throw new Error( 'Please specify a valid media type to preview' );
}
this.dom.querySelector( '.r-overlay-close' ).addEventListener( 'click', ( event ) => {
this.close();
event.preventDefault();
}, false );
}
previewImage( url, fitMode ) {
this.previewMedia( url, 'image', fitMode );
}
previewVideo( url, fitMode ) {
this.previewMedia( url, 'video', fitMode );View on GitHub (pinned to a3b9406956)
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.
Example fix
// before
overlay.previewMedia(url, fileType, fit); // fileType may be 'audio' or undefined
// after
if (fileType === 'image' || fileType === 'video') {
overlay.previewMedia(url, fileType, fit);
} else {
console.warn(`Unsupported preview media type: ${fileType}`);
} Defensive patterns
Strategy: validation
Validate before calling
const VALID_MEDIA_TYPES = new Set(['image', 'video']);
function safePreviewMedia(overlay, url, mediaType, fitMode) {
if (!VALID_MEDIA_TYPES.has(mediaType)) {
console.warn(`previewMedia: unsupported mediaType '${mediaType}'; skipping.`);
return;
}
overlay.previewMedia(url, mediaType, fitMode);
} Type guard
function isOverlayMediaType(value) {
return value === 'image' || value === 'video';
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Fragment with asChild expects exactly one React element chil
- Fragment with asChild expects exactly one non-Fragment React
AI-assisted analysis of hakimel/reveal.js@a3b9406956 (2026-08-12).
Data as JSON: /api/errors/8eef8235360d538a.
Report an issue: GitHub.