[Bug]: Toolbar page number input allows invalid range, causing silent no‑op
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 53.9k
- Forks
- 10.7k
- Avg merge
- 18h 38m
- Merged PRs (30d)
- 130
Description
Attach (recommended) or Link to PDF file
https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf
Web browser and its version
Firefox 122.0 (64-bit)
Operating system and its version
Ubuntu 22.04 LTS (64-bit)
PDF.js version
Latest (from https://mozilla.github.io/pdf.js/web/viewer.html)
Is the bug present in the latest PDF.js version?
Yes
Is a browser extension
No
Steps to reproduce the problem
- Open any PDF document in the PDF.js viewer (e.g., https://mozilla.github.io/pdf.js/web/viewer.html?file=compressed.tracemonkey-pldi-09.pdf)
- Note the total number of pages (e.g., 14 pages)
- Click on the page number input field in the toolbar
- Enter an invalid page number:
- Enter
0(less than minimum) - OR enter a number greater than total pages (e.g.,
999)
- Enter
- Press
Enterkey
What is the expected behavior?
he user should receive clear feedback when entering an invalid page number:
Option 1 (Preferred):
- Input field shows a brief visual error indication (red border/background)
- A tooltip or small message appears: "Please enter a page between 1 and 14"
- Input automatically resets to the current page number after 2 seconds
Option 2:
- Input is automatically clamped to valid range
- For
0→ jumps to page 1 - For
999→ jumps to last page (14)
Option 3:
- Dialog/alert notifies user: "Invalid page number. Please enter a number between 1 and 14"
What went wrong?
Actual behavior:
- No visual feedback occurs
- No error message appears
- The viewer silently stays on the current page
- The input field shows the invalid number briefly, then reverts
- User receives no indication that their input was invalid
Why this is problematic:
- Poor UX - Users are confused why nothing happens
- Accessibility issue - Screen reader users get no feedback
- Common mistake - Easy to mistype or forget page count
- Violates best practices - Form inputs should validate and provide feedback
Link to a viewer
https://mozilla.github.io/pdf.js/web/viewer.html?file=compressed.tracemonkey-pldi-09.pdf
Additional context
Comparison with other PDF viewers
Adobe Acrobat Reader:
- Shows error message: "Please enter a value between 1 and [total]"
- Input field highlights in red
Chrome PDF Viewer:
- Automatically clamps to valid range
- Goes to page 1 if too low, last page if too high
Firefox built-in PDF Viewer:
- Shows inline validation message
- Prevents navigation with invalid input
Foxit Reader:
- Dialog box with error message
- Input field retains focus for correction
Technical Implementation Notes
The issue appears to be in the page number validation logic. Looking at the codebase:
File: web/app.js (around line 3241)
function onPageNumberChanged(evt) {
const { pdfViewer } = this;
if (evt.value !== "") {
this.pdfLinkService.goToPage(evt.value);
}
// ... rest of function
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in web/app.js around onPageNumberChanged and reproduce the invalid-input behavior in the PDF.js viewer with values below 1 and above the document length. Determine which stated validation behavior is selected, then verify that invalid input gives feedback or clamps correctly and that valid page navigation still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- accessibility, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100