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(