@@ -239,15 +239,15 @@ public int DefaultTimeout
239
239
240
240
internal bool IsDragging { get ; set ; }
241
241
242
- internal Browser Browser => Target . Browser ;
242
+ internal bool HasPopupEventListeners => Popup ? . GetInvocationList ( ) . Any ( ) == true ;
243
243
244
- internal Target Target { get ; }
244
+ private Browser Browser => Target . Browser ;
245
245
246
- internal bool JavascriptEnabled { get ; set ; } = true ;
246
+ private Target Target { get ; }
247
247
248
- internal bool HasPopupEventListeners => Popup ? . GetInvocationList ( ) . Any ( ) = = true ;
248
+ private bool JavascriptEnabled { get ; set ; } = true ;
249
249
250
- internal FrameManager FrameManager { get ; private set ; }
250
+ private FrameManager FrameManager { get ; set ; }
251
251
252
252
private Task SessionClosedTask
253
253
{
@@ -405,7 +405,7 @@ public Task SetRequestInterceptionAsync(bool value)
405
405
public async Task < CookieParam [ ] > GetCookiesAsync ( params string [ ] urls )
406
406
=> ( await Client . SendAsync < NetworkGetCookiesResponse > ( "Network.getCookies" , new NetworkGetCookiesRequest
407
407
{
408
- Urls = urls . Length > 0 ? urls : new string [ ] { Url } ,
408
+ Urls = urls . Length > 0 ? urls : new [ ] { Url } ,
409
409
} ) . ConfigureAwait ( false ) ) . Cookies ;
410
410
411
411
/// <inheritdoc/>
@@ -620,10 +620,8 @@ public async Task ScreenshotAsync(string file, ScreenshotOptions options)
620
620
621
621
var data = await ScreenshotDataAsync ( options ) . ConfigureAwait ( false ) ;
622
622
623
- using ( var fs = AsyncFileHelper . CreateStream ( file , FileMode . Create ) )
624
- {
625
- await fs . WriteAsync ( data , 0 , data . Length ) . ConfigureAwait ( false ) ;
626
- }
623
+ using var fs = AsyncFileHelper . CreateStream ( file , FileMode . Create ) ;
624
+ await fs . WriteAsync ( data , 0 , data . Length ) . ConfigureAwait ( false ) ;
627
625
}
628
626
629
627
/// <inheritdoc/>
@@ -659,12 +657,12 @@ public Task<string> ScreenshotBase64Async(ScreenshotOptions options)
659
657
}
660
658
}
661
659
662
- if ( options ? . Clip ? . Width == 0 )
660
+ if ( options . Clip ? . Width == 0 )
663
661
{
664
662
throw new PuppeteerException ( "Expected options.Clip.Width not to be 0." ) ;
665
663
}
666
664
667
- if ( options ? . Clip ? . Height == 0 )
665
+ if ( options . Clip ? . Height == 0 )
668
666
{
669
667
throw new PuppeteerException ( "Expected options.Clip.Height not to be 0." ) ;
670
668
}
@@ -826,7 +824,7 @@ public async Task WaitForNetworkIdleAsync(WaitForNetworkIdleOptions options = nu
826
824
Interval = idleTime ,
827
825
} ;
828
826
829
- idleTimer . Elapsed += ( sender , args ) =>
827
+ idleTimer . Elapsed += ( _ , _ ) =>
830
828
{
831
829
networkIdleTcs . TrySetResult ( true ) ;
832
830
} ;
@@ -1098,7 +1096,7 @@ await Client.SendAsync(
1098
1096
/// <inheritdoc/>
1099
1097
public Task EmulateCPUThrottlingAsync ( decimal ? factor = null )
1100
1098
{
1101
- if ( factor != null && factor < 1 )
1099
+ if ( factor is < 1 )
1102
1100
{
1103
1101
throw new ArgumentException ( "Throttling rate should be greater or equal to 1" , nameof ( factor ) ) ;
1104
1102
}
@@ -1150,7 +1148,19 @@ internal static async Task<Page> CreateAsync(
1150
1148
}
1151
1149
}
1152
1150
1153
- internal async Task < byte [ ] > PdfInternalAsync ( string file , PdfOptions options )
1151
+ internal void OnPopup ( IPage popupPage ) => Popup ? . Invoke ( this , new PopupEventArgs { PopupPage = popupPage } ) ;
1152
+
1153
+ /// <summary>
1154
+ /// Dispose resources.
1155
+ /// </summary>
1156
+ /// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
1157
+ protected virtual void Dispose ( bool disposing )
1158
+ {
1159
+ Mouse . Dispose ( ) ;
1160
+ _ = DisposeAsync ( ) ;
1161
+ }
1162
+
1163
+ private async Task < byte [ ] > PdfInternalAsync ( string file , PdfOptions options )
1154
1164
{
1155
1165
var paperWidth = PaperFormat . Letter . Width ;
1156
1166
var paperHeight = PaperFormat . Letter . Height ;
@@ -1211,18 +1221,6 @@ internal async Task<byte[]> PdfInternalAsync(string file, PdfOptions options)
1211
1221
return await ProtocolStreamReader . ReadProtocolStreamByteAsync ( Client , result . Stream , file ) . ConfigureAwait ( false ) ;
1212
1222
}
1213
1223
1214
- internal void OnPopup ( IPage popupPage ) => Popup ? . Invoke ( this , new PopupEventArgs { PopupPage = popupPage } ) ;
1215
-
1216
- /// <summary>
1217
- /// Dispose resources.
1218
- /// </summary>
1219
- /// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
1220
- protected virtual void Dispose ( bool disposing )
1221
- {
1222
- Mouse . Dispose ( ) ;
1223
- _ = DisposeAsync ( ) ;
1224
- }
1225
-
1226
1224
private async Task InitializeAsync ( )
1227
1225
{
1228
1226
await FrameManager . InitializeAsync ( ) . ConfigureAwait ( false ) ;
@@ -1240,8 +1238,8 @@ private async Task InitializeAsync()
1240
1238
networkManager . RequestServedFromCache += ( _ , e ) => RequestServedFromCache ? . Invoke ( this , e ) ;
1241
1239
1242
1240
await Task . WhenAll (
1243
- Client . SendAsync ( "Performance.enable" , null ) ,
1244
- Client . SendAsync ( "Log.enable" , null ) ) . ConfigureAwait ( false ) ;
1241
+ Client . SendAsync ( "Performance.enable" ) ,
1242
+ Client . SendAsync ( "Log.enable" ) ) . ConfigureAwait ( false ) ;
1245
1243
}
1246
1244
1247
1245
private async Task < IResponse > GoAsync ( int delta , NavigationOptions options )
@@ -1293,7 +1291,7 @@ private async Task<string> PerformScreenshot(ScreenshotType type, ScreenshotOpti
1293
1291
1294
1292
// FromSurface is not supported on Firefox.
1295
1293
// It seems that Puppeteer solved this just by ignoring screenshot tests in firefox.
1296
- if ( Browser . Launcher . Options . Browser == SupportedBrowser . Firefox )
1294
+ if ( Browser . BrowserType == SupportedBrowser . Firefox )
1297
1295
{
1298
1296
if ( options . FromSurface != null )
1299
1297
{
@@ -1302,15 +1300,15 @@ private async Task<string> PerformScreenshot(ScreenshotType type, ScreenshotOpti
1302
1300
}
1303
1301
else
1304
1302
{
1305
- options . FromSurface = options . FromSurface . HasValue ? options . FromSurface : true ;
1303
+ options . FromSurface ??= true ;
1306
1304
}
1307
1305
1308
1306
var clip = options . Clip != null ? ProcessClip ( options . Clip ) : null ;
1309
1307
var captureBeyondViewport = options . CaptureBeyondViewport ;
1310
1308
1311
1309
if ( ! _screenshotBurstModeOn )
1312
1310
{
1313
- if ( options ? . FullPage == true )
1311
+ if ( options . FullPage )
1314
1312
{
1315
1313
// Overwrite clip for full page at all times.
1316
1314
clip = null ;
@@ -1356,13 +1354,13 @@ private async Task<string> PerformScreenshot(ScreenshotType type, ScreenshotOpti
1356
1354
}
1357
1355
}
1358
1356
1359
- if ( options ? . OmitBackground == true && type == ScreenshotType . Png )
1357
+ if ( options . OmitBackground && type == ScreenshotType . Png )
1360
1358
{
1361
1359
await SetTransparentBackgroundColorAsync ( ) . ConfigureAwait ( false ) ;
1362
1360
}
1363
1361
}
1364
1362
1365
- if ( options ? . FullPage == false && clip == null )
1363
+ if ( options . FullPage == false && clip == null )
1366
1364
{
1367
1365
captureBeyondViewport = false ;
1368
1366
}
@@ -1417,7 +1415,7 @@ private Clip ProcessClip(Clip clip)
1417
1415
1418
1416
private Task ResetBackgroundColorAndViewportAsync ( ScreenshotOptions options )
1419
1417
{
1420
- var omitBackgroundTask = options ? . OmitBackground == true && options . Type == ScreenshotType . Png ?
1418
+ var omitBackgroundTask = options is { OmitBackground : true , Type : ScreenshotType . Png } ?
1421
1419
ResetDefaultBackgroundColorAsync ( ) : Task . CompletedTask ;
1422
1420
var setViewPortTask = ( options ? . FullPage == true && Viewport != null ) ?
1423
1421
SetViewportAsync ( Viewport ) : Task . CompletedTask ;
@@ -1604,7 +1602,7 @@ private async Task OnLogEntryAddedAsync(LogEntryAddedResponse e)
1604
1602
{
1605
1603
if ( e . Entry . Args != null )
1606
1604
{
1607
- foreach ( var arg in e . Entry ? . Args )
1605
+ foreach ( var arg in e . Entry . Args )
1608
1606
{
1609
1607
await RemoteObjectHelper . ReleaseObjectAsync ( Client , arg , _logger ) . ConfigureAwait ( false ) ;
1610
1608
}
@@ -1648,14 +1646,16 @@ private string GetExceptionMessage(EvaluateExceptionResponseDetails exceptionDet
1648
1646
}
1649
1647
1650
1648
var message = exceptionDetails . Text ;
1651
- if ( exceptionDetails . StackTrace ! = null )
1649
+ if ( exceptionDetails . StackTrace = = null )
1652
1650
{
1653
- foreach ( var callframe in exceptionDetails . StackTrace . CallFrames )
1654
- {
1655
- var location = $ "{ callframe . Url } :{ callframe . LineNumber } :{ callframe . ColumnNumber } ";
1656
- var functionName = callframe . FunctionName ?? "<anonymous>" ;
1657
- message += $ "\n at { functionName } ({ location } )";
1658
- }
1651
+ return message ;
1652
+ }
1653
+
1654
+ foreach ( var callFrame in exceptionDetails . StackTrace . CallFrames )
1655
+ {
1656
+ var location = $ "{ callFrame . Url } :{ callFrame . LineNumber } :{ callFrame . ColumnNumber } ";
1657
+ var functionName = callFrame . FunctionName ?? "<anonymous>" ;
1658
+ message += $ "\n at { functionName } ({ location } )";
1659
1659
}
1660
1660
1661
1661
return message ;
@@ -1732,7 +1732,7 @@ await Task.WhenAll(Frames.Select(
1732
1732
. ContinueWith (
1733
1733
task =>
1734
1734
{
1735
- if ( task . IsFaulted )
1735
+ if ( task . IsFaulted && task . Exception != null )
1736
1736
{
1737
1737
_logger . LogError ( task . Exception . ToString ( ) ) ;
1738
1738
}
0 commit comments