mozilla/pdf.js · error · Error
Invalid thumbnails rotation angle.
Error message
Invalid thumbnails rotation angle.
What it means
Thrown by PDFThumbnailViewer.pagesRotation setter when the rotation value fails isValidRotation (must be an integer multiple of 90: 0, 90, 180, 270, ...). Thumbnails mirror the page rotation and require a valid angle.
Source
Thrown at web/pdf_thumbnail_viewer.js:487
shouldScroll = percent < 100;
break;
}
}
if (shouldScroll) {
thumbnailView.div.scrollIntoView(SCROLL_OPTIONS);
}
}
this._currentPageNumber = pageNumber;
}
get pagesRotation() {
return this._pagesRotation;
}
set pagesRotation(rotation) {
if (!isValidRotation(rotation)) {
throw new Error("Invalid thumbnails rotation angle.");
}
if (!this.pdfDocument) {
return;
}
if (this._pagesRotation === rotation) {
return; // The rotation didn't change.
}
this._pagesRotation = rotation;
const updateArgs = { rotation };
for (const thumbnail of this._thumbnails) {
thumbnail.update(updateArgs);
}
}
cleanup() {
for (const thumbnail of this._thumbnails) {
if (thumbnail.renderingState !== RenderingStates.FINISHED) {View on GitHub (pinned to 5903d58d58)
Solutions
- Pass only integer multiples of 90 (0, 90, 180, 270).
- Normalize input before setting: rotation = Math.round(rotation / 90) * 90 % 360.
- Guard with isValidRotation from ui_utils before assigning.
Example fix
// before
thumbnailViewer.pagesRotation = rawDegrees;
// after
function normalizeRotation(r) {
if (!Number.isInteger(r) || r % 90 !== 0) return null;
return ((r % 360) + 360) % 360;
}
const rot = normalizeRotation(rawDegrees);
if (rot !== null) thumbnailViewer.pagesRotation = rot; Defensive patterns
Strategy: validation
Validate before calling
function validRotation(r) {
return Number.isInteger(r) && r % 90 === 0;
}
if (validRotation(degrees)) {
thumbnailViewer.pagesRotation = degrees;
} Type guard
function isValidRotation(angle) {
return Number.isInteger(angle) && angle % 90 === 0;
} Prevention
- Snap rotation controls to 90-degree steps.
- Normalize saved rotation state on load.
- Use the shared isValidRotation helper from ui_utils.
When it happens
Trigger: Setting pdfThumbnailViewer.pagesRotation = 45, or a non-integer/NaN/non-number value. Also from passing rotation derived from user input or a corrupted state without normalization.
Common situations: Custom toolbar rotation controls passing arbitrary degrees; deserialization of saved rotation state; passing a float like 90.0 is fine, but 45.5 or NaN throws.
Related errors
- Not enough parameters.
- The overlay does not exist.
- Invalid pages rotation angle.
- BinaryCMapReader.process: Invalid dataSize.
- Page count in top-level pages dictionary is not an integer.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/1e0a856858af056e.
Report an issue: GitHub.