diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index d30fcca9f6..ec746904f6 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -460,6 +460,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( @@ -3365,10 +3367,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(