Skip to content

fix: avoid crash in window.print() when prefilling native print dialog#50843

Merged
samuelmaddock merged 1 commit intomainfrom
fix-window-print-crash
Apr 9, 2026
Merged

fix: avoid crash in window.print() when prefilling native print dialog#50843
samuelmaddock merged 1 commit intomainfrom
fix-window-print-crash

Conversation

@codebytere
Copy link
Copy Markdown
Member

@codebytere codebytere commented Apr 9, 2026

Description of Change

Closes #50827

When UpdatePrinterSettings() fails (e.g. the printer rejects the requested resolution), OnError() nullifies print_info_ via ReleaseContext(). The return value was not checked, so AskUserForSettings() passed nil to [NSPrintPanel runModalWithPrintInfo:], crashing in PJCSessionHasApplicationSetPrinter with a null PMPrintSession.

Check the return value and fall back to UseDefaultSettings() on failure so the dialog opens with defaults instead of crashing.

Checklist

Release Notes

Notes: Fixed a potential crash when using webContents.print().

@codebytere codebytere requested a review from samuelmaddock April 9, 2026 12:26
@codebytere codebytere requested a review from a team as a code owner April 9, 2026 12:26
@codebytere codebytere added semver/patch backwards-compatible bug fixes 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 9, 2026
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Apr 9, 2026
When UpdatePrinterSettings() fails (e.g. the printer rejects the
requested resolution), OnError() nullifies print_info_ via
ReleaseContext(). The return value was not checked, so
AskUserForSettings() passed nil to [NSPrintPanel runModalWithPrintInfo:],
crashing in PJCSessionHasApplicationSetPrinter with a null PMPrintSession.

Check the return value and fall back to UseDefaultSettings() on failure
so the dialog opens with defaults instead of crashing.
@codebytere codebytere force-pushed the fix-window-print-crash branch from 650d737 to f7d5770 Compare April 9, 2026 12:29
@samuelmaddock samuelmaddock merged commit 044be7c into main Apr 9, 2026
116 of 118 checks passed
@samuelmaddock samuelmaddock deleted the fix-window-print-crash branch April 9, 2026 17:14
@release-clerk
Copy link
Copy Markdown

release-clerk bot commented Apr 9, 2026

Release Notes Persisted

Fixed a potential crash when using webContents.print().

@trop
Copy link
Copy Markdown
Contributor

trop bot commented Apr 9, 2026

I was unable to backport this PR to "41-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/41-x-y and removed target/41-x-y PR should also be added to the "41-x-y" branch. labels Apr 9, 2026
@trop
Copy link
Copy Markdown
Contributor

trop bot commented Apr 9, 2026

I have automatically backported this PR to "42-x-y", please check out #50853

@trop trop bot added in-flight/42-x-y and removed target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in-flight/42-x-y needs-manual-bp/41-x-y new-pr 🌱 PR opened recently semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling window.print() causes crash

3 participants