Skip to content

fix: reset printToPDF queue after a rejection#51174

Open
codebytere wants to merge 1 commit intomainfrom
pdf-reject-fix
Open

fix: reset printToPDF queue after a rejection#51174
codebytere wants to merge 1 commit intomainfrom
pdf-reject-fix

Conversation

@codebytere
Copy link
Copy Markdown
Member

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

Release Notes

Notes: Fixed webContents.printToPDF rejecting on all subsequent calls after a prior call was rejected with an invalid pageRanges value.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 20, 2026
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Apr 20, 2026
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.
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/patch backwards-compatible bug fixes target/40-x-y PR should also be added to the "40-x-y" branch. target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exporting to PDF is broken after an invalid page range is provided

1 participant