MarshallOfSound

#53977: refactor: validate print() and printToPDF() options natively

Merged
Created: Sep 15, 2026, 6:57:42 PM
Merged: Sep 16, 2026, 11:35:37 AM
2 comments
Target: main

Description of Change

  • webContents.print()'s argument and pageSize handling, webContents/webFrameMain printToPDF()'s option validation and per-frame-tree job queue (lib/browser/print-to-pdf.ts), and getPrintersAsync() are now the native methods themselves rather than JS wrappers over _print/_printToPDF. Defaults, validation order, messages and Error/TypeError/RangeError classes are kept (down to JS <= coercion for the margins check and which getters run).
  • New gin_helper::ConversionError (why a conversion failed, at which property path, and which JS error class to raise) and gin_helper::OptionsReader (reads an options object property by property through gin's converters or a converter that takes the ConversionError; undefined/null count as absent; stops at the first failure) so native option parsing can report "margins.top must be a number" instead of gin's generic conversion error.

Intentional differences: printToPDF(undefined | null | <primitive>) rejects with options must be an object; a PDF job whose WebContents goes away while queued rejects instead of never settling; getPrintersAsync() and printToPDF() on a destroyed WebContents reject rather than throw.

~290 lines out of lib/; no runtime change intended.

Checklist

Release Notes

Notes: none

Backports

45-x-y
Pending
Waiting for a manual backport

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