@@ -986,6 +986,11 @@ internal async Task<byte[]> PdfInternalAsync(string file, PdfOptions options)
986986 var marginBottom = ConvertPrintParameterToInches ( options . MarginOptions . Bottom ) ;
987987 var marginRight = ConvertPrintParameterToInches ( options . MarginOptions . Right ) ;
988988
989+ if ( options . OmitBackground )
990+ {
991+ await SetTransparentBackgroundColorAsync ( ) . ConfigureAwait ( false ) ;
992+ }
993+
989994 var result = await Client . SendAsync < PagePrintToPDFResponse > ( "Page.printToPDF" , new PagePrintToPDFRequest
990995 {
991996 TransferMode = "ReturnAsStream" ,
@@ -1005,6 +1010,11 @@ internal async Task<byte[]> PdfInternalAsync(string file, PdfOptions options)
10051010 PreferCSSPageSize = options . PreferCSSPageSize
10061011 } ) . ConfigureAwait ( false ) ;
10071012
1013+ if ( options . OmitBackground )
1014+ {
1015+ await ResetDefaultBackgroundColorAsync ( ) . ConfigureAwait ( false ) ;
1016+ }
1017+
10081018 return await ProtocolStreamReader . ReadProtocolStreamByteAsync ( Client , result . Stream , file ) . ConfigureAwait ( false ) ;
10091019 }
10101020
@@ -1976,16 +1986,7 @@ private async Task<string> PerformScreenshot(ScreenshotType type, ScreenshotOpti
19761986
19771987 if ( options ? . OmitBackground == true && type == ScreenshotType . Png )
19781988 {
1979- await Client . SendAsync ( "Emulation.setDefaultBackgroundColorOverride" , new EmulationSetDefaultBackgroundColorOverrideRequest
1980- {
1981- Color = new EmulationSetDefaultBackgroundColorOverrideColor
1982- {
1983- R = 0 ,
1984- G = 0 ,
1985- B = 0 ,
1986- A = 0
1987- }
1988- } ) . ConfigureAwait ( false ) ;
1989+ await SetTransparentBackgroundColorAsync ( ) . ConfigureAwait ( false ) ;
19891990 }
19901991 }
19911992
@@ -2036,12 +2037,27 @@ private Clip ProcessClip(Clip clip)
20362037 private Task ResetBackgroundColorAndViewportAsync ( ScreenshotOptions options )
20372038 {
20382039 var omitBackgroundTask = options ? . OmitBackground == true && options . Type == ScreenshotType . Png ?
2039- Client . SendAsync ( "Emulation.setDefaultBackgroundColorOverride" ) : Task . CompletedTask ;
2040+ ResetDefaultBackgroundColorAsync ( ) : Task . CompletedTask ;
20402041 var setViewPortTask = ( options ? . FullPage == true && Viewport != null ) ?
20412042 SetViewportAsync ( Viewport ) : Task . CompletedTask ;
20422043 return Task . WhenAll ( omitBackgroundTask , setViewPortTask ) ;
20432044 }
20442045
2046+ private Task ResetDefaultBackgroundColorAsync ( )
2047+ => Client . SendAsync ( "Emulation.setDefaultBackgroundColorOverride" ) ;
2048+
2049+ private Task SetTransparentBackgroundColorAsync ( )
2050+ => Client . SendAsync ( "Emulation.setDefaultBackgroundColorOverride" , new EmulationSetDefaultBackgroundColorOverrideRequest
2051+ {
2052+ Color = new EmulationSetDefaultBackgroundColorOverrideColor
2053+ {
2054+ R = 0 ,
2055+ G = 0 ,
2056+ B = 0 ,
2057+ A = 0
2058+ }
2059+ } ) ;
2060+
20452061 private decimal ConvertPrintParameterToInches ( object parameter )
20462062 {
20472063 if ( parameter == null )
0 commit comments