@@ -37,6 +37,7 @@ namespace PuppeteerSharp.Bidi;
3737public class BidiPage : Page
3838{
3939 private readonly CdpEmulationManager _cdpEmulationManager ;
40+ private InternalNetworkConditions _emulatedNetworkConditions ;
4041
4142 internal BidiPage ( BidiBrowserContext browserContext , BrowsingContext browsingContext ) : base ( browserContext . ScreenshotTaskQueue )
4243 {
@@ -410,7 +411,24 @@ await BidiBrowser.Driver.Storage.DeleteCookiesAsync(new WebDriverBiDi.Storage.De
410411 public override Task SetRequestInterceptionAsync ( bool value ) => throw new NotImplementedException ( ) ;
411412
412413 /// <inheritdoc />
413- public override Task SetOfflineModeAsync ( bool value ) => throw new NotImplementedException ( ) ;
414+ public override async Task SetOfflineModeAsync ( bool value )
415+ {
416+ if ( ! BidiBrowser . CdpSupported )
417+ {
418+ throw new NotSupportedException ( ) ;
419+ }
420+
421+ _emulatedNetworkConditions ??= new InternalNetworkConditions
422+ {
423+ Offline = false ,
424+ Upload = - 1 ,
425+ Download = - 1 ,
426+ Latency = 0 ,
427+ } ;
428+
429+ _emulatedNetworkConditions . Offline = value ;
430+ await ApplyNetworkConditionsAsync ( ) . ConfigureAwait ( false ) ;
431+ }
414432
415433 /// <inheritdoc />
416434 public override Task EmulateNetworkConditionsAsync ( NetworkConditions networkConditions ) => throw new NotImplementedException ( ) ;
@@ -545,6 +563,24 @@ private async Task<IResponse> GoAsync(int delta, NavigationOptions options)
545563 return waitForNavigationTask . Result ;
546564 }
547565
566+ private async Task ApplyNetworkConditionsAsync ( )
567+ {
568+ if ( _emulatedNetworkConditions == null )
569+ {
570+ return ;
571+ }
572+
573+ await BidiMainFrame . Client . SendAsync (
574+ "Network.emulateNetworkConditions" ,
575+ new Cdp . Messaging . NetworkEmulateNetworkConditionsRequest
576+ {
577+ Offline = _emulatedNetworkConditions . Offline ,
578+ Latency = _emulatedNetworkConditions . Latency ,
579+ UploadThroughput = _emulatedNetworkConditions . Upload ,
580+ DownloadThroughput = _emulatedNetworkConditions . Download ,
581+ } ) . ConfigureAwait ( false ) ;
582+ }
583+
548584 private void Initialize ( )
549585 {
550586 }
0 commit comments