diff --git a/shell/browser/api/atom_api_web_contents.cc b/shell/browser/api/atom_api_web_contents.cc index eeb869b0b9940..b28dcdb327fd5 100644 --- a/shell/browser/api/atom_api_web_contents.cc +++ b/shell/browser/api/atom_api_web_contents.cc @@ -1728,18 +1728,20 @@ void WebContents::Print(mate::Arguments* args) { settings.SetInteger(printing::kSettingMarginsType, margin_type); if (margin_type == printing::CUSTOM_MARGINS) { + auto custom_margins = std::make_unique(); int top = 0; margins.Get("top", &top); - settings.SetInteger(printing::kSettingMarginTop, top); + custom_margins->SetInteger(printing::kSettingMarginTop, top); int bottom = 0; margins.Get("bottom", &bottom); - settings.SetInteger(printing::kSettingMarginBottom, bottom); + custom_margins->SetInteger(printing::kSettingMarginBottom, bottom); int left = 0; margins.Get("left", &left); - settings.SetInteger(printing::kSettingMarginLeft, left); + custom_margins->SetInteger(printing::kSettingMarginLeft, left); int right = 0; margins.Get("right", &right); - settings.SetInteger(printing::kSettingMarginRight, right); + custom_margins->SetInteger(printing::kSettingMarginRight, right); + settings.SetDictionary(printing::kSettingMarginsCustom, custom_margins); } } else { settings.SetInteger(printing::kSettingMarginsType, diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index ab7006cfe2b7c..89df0a16c832f 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -130,9 +130,18 @@ describe('webContents module', () => { }).to.throw('webContents.print(): Invalid deviceName provided.') }) - it('does not crash', () => { + it('does not crash with custom margins', () => { expect(() => { - w.webContents.print({ silent: true }) + w.webContents.print({ + silent: true, + margins: { + marginType: 'custom', + top: 1, + bottom: 1, + left: 1, + right: 1 + } + }) }).to.not.throw() }) })