From dd74ff34511ec4cf37e35fdb49eae1e8f72a8f0e Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 18:36:54 -0500 Subject: [PATCH] fix: honor webContents.print dpi horizontal/vertical options (#51355) * fix: honor webContents.print dpi horizontal/vertical options Co-authored-by: Kunal Dubey * style: fix clang-format in print dpi parsing Co-authored-by: Kunal Dubey * style: extract print dpi key constants Co-authored-by: Kunal Dubey * fix: use local dpi constants in print options parser Co-authored-by: Kunal Dubey --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Kunal Dubey --- shell/browser/api/electron_api_web_contents.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index d62a5cafe5..e0a7df5733 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -459,6 +459,8 @@ constexpr char kFooterTemplate[] = "footerTemplate"; constexpr char kPreferCSSPageSize[] = "preferCSSPageSize"; constexpr char kGenerateTaggedPDF[] = "generateTaggedPDF"; constexpr char kGenerateDocumentOutline[] = "generateDocumentOutline"; +constexpr char kDpiHorizontal[] = "horizontal"; +constexpr char kDpiVertical[] = "vertical"; #endif // BUILDFLAG(ENABLE_PRINTING) constexpr std::string_view CursorTypeToString( @@ -3346,10 +3348,16 @@ void WebContents::Print(gin::Arguments* const args) { // Set custom dots per inch (dpi) if (gin_helper::Dictionary dpi; options.Get(kDpi, &dpi)) { + // `webContents.print()` exposes `dpi: { horizontal, vertical }` in JS. + // Keep backward compatibility with internal key names as a fallback. settings.Set(printing::kSettingDpiHorizontal, - dpi.ValueOrDefault(printing::kSettingDpiHorizontal, 72)); + dpi.ValueOrDefault( + kDpiHorizontal, + dpi.ValueOrDefault(printing::kSettingDpiHorizontal, 72))); settings.Set(printing::kSettingDpiVertical, - dpi.ValueOrDefault(printing::kSettingDpiVertical, 72)); + dpi.ValueOrDefault( + kDpiVertical, + dpi.ValueOrDefault(printing::kSettingDpiVertical, 72))); } print_task_runner_->PostTaskAndReplyWithResult(