#51174: fix: reset printToPDF queue after a rejection
Merged
Description of Change
Closes #51145
The module-scoped pendingPromise in webContents.printToPDF was chained with .then(onFulfilled) and never cleared. Once a call rejected (e.g. an out-of-range pageRanges like "999"), subsequent calls chained onto the rejected promise and short-circuited without ever invoking _printToPDF — so every following call re-surfaced the original error.
Replace the shared variable with a per-WebContents WeakMap queue that swallows prior rejections before chaining and clears its entry once the tail drains.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense.
Release Notes
Notes: Fixed webContents.printToPDF rejecting on all subsequent calls after a prior call was rejected with an invalid pageRanges value.
Backports
40-x-y
MergedPR Number
#51220Merged At
Apr 21, 2026, 3:31:08 PM
Released In
v40.9.3Release Date
Apr 30, 2026, 2:33:39 PM
41-x-y
MergedPR Number
#51221Merged At
Apr 22, 2026, 5:32:47 AM
Released In
v41.3.0Release Date
Apr 22, 2026, 4:04:18 PM
42-x-y
MergedPR Number
#51222Merged At
Apr 22, 2026, 5:32:50 AM
Released In
v42.0.0-beta.7Release Date
Apr 29, 2026, 3:06:55 PM
Semver Impact
Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron