New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bad error passing webContents.print(null)
#38612
Conversation
8f7308a
to
75a0c3b
Compare
WebContents.prototype.print = function (printOptions: ElectronInternal.WebContentsPrintOptions, callback) { | ||
const options = printOptions ?? {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker to the PR; asking for my own info: what's the difference between the default = {}
argument in the old code and the options = printOptions ?? {}
code? Is this to safeguard against an explicit null being passed as the first argument, or...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ckerr default arguments only take effect if the no value or undefined is passed, so when they user passes in null
they're bypassed entirely . This change (and using ??
specifically) ensures it's defaulted if it's null
or undefined
.
Old but nevertheless interesting article about falsy value handling patterns: https://medium.com/@bmb21/default-parameters-and-nulls-in-javascript-9149c8d26b0a
Release Notes Persisted
|
I have automatically backported this PR to "24-x-y", please check out #38640 |
I have automatically backported this PR to "26-x-y", please check out #38641 |
I have automatically backported this PR to "25-x-y", please check out #38642 |
Description of Change
Fixes #38598.
Fixes an issue where passing
webContents.print(null)
would trigger the following error:Cannot read properties of null (reading 'pageSize').
This was happening because we weren't properly validating
options
.Checklist
npm test
passesRelease Notes
Notes: Fixes an issue where passing
webContents.print(null)
could incorrectly trigger an error.