@@ -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 {
@@ -371,7 +372,24 @@ await BidiBrowser.Driver.Storage.DeleteCookiesAsync(new WebDriverBiDi.Storage.De
371372 public override Task SetRequestInterceptionAsync ( bool value ) => throw new NotImplementedException ( ) ;
372373
373374 /// <inheritdoc />
374- public override Task SetOfflineModeAsync ( bool value ) => throw new NotImplementedException ( ) ;
375+ public override async Task SetOfflineModeAsync ( bool value )
376+ {
377+ if ( ! BidiBrowser . CdpSupported )
378+ {
379+ throw new NotSupportedException ( ) ;
380+ }
381+
382+ _emulatedNetworkConditions ??= new InternalNetworkConditions
383+ {
384+ Offline = false ,
385+ Upload = - 1 ,
386+ Download = - 1 ,
387+ Latency = 0 ,
388+ } ;
389+
390+ _emulatedNetworkConditions . Offline = value ;
391+ await ApplyNetworkConditionsAsync ( ) . ConfigureAwait ( false ) ;
392+ }
375393
376394 /// <inheritdoc />
377395 public override Task EmulateNetworkConditionsAsync ( NetworkConditions networkConditions ) => throw new NotImplementedException ( ) ;
@@ -506,6 +524,24 @@ private async Task<IResponse> GoAsync(int delta, NavigationOptions options)
506524 return waitForNavigationTask . Result ;
507525 }
508526
527+ private async Task ApplyNetworkConditionsAsync ( )
528+ {
529+ if ( _emulatedNetworkConditions == null )
530+ {
531+ return ;
532+ }
533+
534+ await BidiMainFrame . Client . SendAsync (
535+ "Network.emulateNetworkConditions" ,
536+ new Cdp . Messaging . NetworkEmulateNetworkConditionsRequest
537+ {
538+ Offline = _emulatedNetworkConditions . Offline ,
539+ Latency = _emulatedNetworkConditions . Latency ,
540+ UploadThroughput = _emulatedNetworkConditions . Upload ,
541+ DownloadThroughput = _emulatedNetworkConditions . Download ,
542+ } ) . ConfigureAwait ( false ) ;
543+ }
544+
509545 private void Initialize ( )
510546 {
511547 }
0 commit comments