Skip to content

Suppress more errors due to closed documents - #22321

Open
nicolo-ribaudo wants to merge 2 commits into
mozilla:masterfrom
nicolo-ribaudo:silence-errors-destroyed-document
Open

nicolo-ribaudo wants to merge 2 commits into
mozilla:masterfrom
nicolo-ribaudo:silence-errors-destroyed-document

Conversation

@nicolo-ribaudo

@nicolo-ribaudo nicolo-ribaudo commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

I noticed some errors in my console while switching between PDFs. Unfortunately it's very racy so I'm not sure if I updated all the places, but these are the ones I noticed.

Commit messages:

Suppress more errors due to closed documents

Closing/switching the document in the viewer will cause multiple
tasks to fail. Other code paths already have
if (pdfDocument !== this.pdfDocument) return; checks to know if the
document has been changed after an async step, but it was missing in
some places leading to errors being logged in the console.

This commit adds the check in those places.

Reject pagesCapability when the document is closed

This is so that those promises don't remain pending forever, and their
callers can clean up associated resources.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

Commit a8fd84c (build logs).

Viewer Build Preview
Modern (gulp generic) ✅ viewer.html
Legacy (gulp generic-legacy) ✅ viewer.html

Previews are removed when the PR closes and may be pruned after 30 days without an update.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 23, 2026
@codecov-commenter

codecov-commenter commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.57%. Comparing base (f70fabb) to head (a8fd84c).

Files with missing lines Patch % Lines
web/pdf_viewer.js 78.57% 3 Missing ⚠️
web/pdf_scripting_manager.js 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22321      +/-   ##
==========================================
+ Coverage   90.52%   90.57%   +0.04%     
==========================================
  Files         278      278              
  Lines       68586    68603      +17     
==========================================
+ Hits        62090    62136      +46     
+ Misses       6496     6467      -29     
Flag Coverage Δ
browsertest 66.28% <0.00%> (+0.05%) ⬆️
integrationtest 69.59% <80.95%> (+<0.01%) ⬆️
unittest 61.25% <0.00%> (+<0.01%) ⬆️
unittestcli 58.99% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nicolo-ribaudo
nicolo-ribaudo force-pushed the silence-errors-destroyed-document branch from 839d681 to 9145897 Compare October 23, 2026 18:03
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 23, 2026
Comment thread web/pdf_viewer.js Resolved
@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks
⏩ 174 skipped benchmarks1


Comparing nicolo-ribaudo:silence-errors-destroyed-document (a8fd84c) with master (f70fabb)

Open in CodSpeed

Footnotes

  1. 174 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@timvandermeij timvandermeij left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; thank you!

Closing/switching the document in the viewer will cause multiple
tasks to fail. Other code paths already have
`if (pdfDocument !== this.pdfDocument) return;` checks to know if the
document has been changed after an async step, but it was missing in
some places leading to errors being logged in the console.

This commit adds the check in those places.
This is so that those promises don't remain pending forever, and their
callers can clean up associated resources.
@nicolo-ribaudo
nicolo-ribaudo force-pushed the silence-errors-destroyed-document branch from 9145897 to a8fd84c Compare November 2, 2026 15:20
@nicolo-ribaudo

Copy link
Copy Markdown
Collaborator Author

@timvandermeij I updated the PR to reject the promise. I left it as two commits because one might argue that the second one is semver-major (it turns a forever-pending promise into a rejected one). I personally think it's more of a bugfix than a breaking change, but if you prefer I can move it to a separate PR that can wait until when we're ready for PDF.js 6.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Nov 2, 2026
try {
await pdfViewer.pagesPromise;
} catch {
break; // The document was closed, or failed to load.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we're in an async function, but the caller is ignoring its errors anyway so this try-catch prevents the "unhandled rejection" warning that browsers report.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants