@@ -114,10 +114,11 @@ public async Task ShouldPreventLoadingOfBlocklistedSubresources()
114114
115115 await page . GoToAsync ( TestConstants . EmptyPage ) ;
116116
117+ var idleTask = page . WaitForNetworkIdleAsync ( ) ;
117118 await page . SetContentAsync (
118119 $@ "<img src=""{ blockedUrl } "" />
119- <link rel=""stylesheet"" href=""{ allowedUrl } "" />" ,
120- new NavigationOptions { WaitUntil = [ WaitUntilNavigation . Networkidle0 ] } ) ;
120+ <link rel=""stylesheet"" href=""{ allowedUrl } "" />" ) ;
121+ await idleTask ;
121122
122123 Assert . That ( failedRequests . ContainsKey ( blockedUrl ) , Is . True ) ;
123124 Assert . That ( failedRequests [ blockedUrl ] , Does . Contain ( "net::ERR_INTERNET_DISCONNECTED" ) ) ;
@@ -289,10 +290,11 @@ public async Task ShouldPreventLoadingOfSubresourcesNotInAllowlist()
289290
290291 await page . GoToAsync ( TestConstants . EmptyPage ) ;
291292
293+ var idleTask = page . WaitForNetworkIdleAsync ( ) ;
292294 await page . SetContentAsync (
293295 $@ "<img src=""{ blockedUrl } "" />
294- <link rel=""stylesheet"" href=""{ allowedUrl } "" />" ,
295- new NavigationOptions { WaitUntil = [ WaitUntilNavigation . Networkidle0 ] } ) ;
296+ <link rel=""stylesheet"" href=""{ allowedUrl } "" />" ) ;
297+ await idleTask ;
296298
297299 Assert . That ( failedRequests . ContainsKey ( blockedUrl ) , Is . True ) ;
298300 Assert . That ( failedRequests [ blockedUrl ] , Does . Contain ( "net::ERR_INTERNET_DISCONNECTED" ) ) ;
@@ -420,4 +422,51 @@ await frame.GoToAsync(blockedUrl).ContinueWith(t =>
420422 Assert . That ( error , Is . Not . Null ) ;
421423 Assert . That ( error . Message , Does . Contain ( "is blocked by blocklist/allowlist rules" ) ) ;
422424 }
425+
426+ [ Test , PuppeteerTest ( "BrowserConnector.test" , "BrowserConnector _connectToBrowser" , "should reject blocklist for WebDriver BiDi connections" ) ]
427+ public void ShouldRejectBlocklistForWebDriverBiDiConnections ( )
428+ {
429+ var connectOptions = new ConnectOptions
430+ {
431+ BrowserWSEndpoint = "ws://localhost:1234" ,
432+ Protocol = ProtocolType . WebdriverBiDi ,
433+ BlockList = [ "https://example.com/*" ] ,
434+ } ;
435+
436+ var error = Assert . ThrowsAsync < PuppeteerException > ( async ( ) =>
437+ await Puppeteer . ConnectAsync ( connectOptions ) ) ;
438+
439+ Assert . That ( error . Message , Does . Contain ( "blocklist and allowlist are only supported with the CDP protocol" ) ) ;
440+ }
441+
442+ [ Test , PuppeteerTest ( "BrowserConnector.test" , "BrowserConnector _connectToBrowser" , "should reject allowlist for WebDriver BiDi connections" ) ]
443+ public void ShouldRejectAllowlistForWebDriverBiDiConnections ( )
444+ {
445+ var connectOptions = new ConnectOptions
446+ {
447+ BrowserWSEndpoint = "ws://localhost:1234" ,
448+ Protocol = ProtocolType . WebdriverBiDi ,
449+ Allowlist = [ "https://example.com/*" ] ,
450+ } ;
451+
452+ var error = Assert . ThrowsAsync < PuppeteerException > ( async ( ) =>
453+ await Puppeteer . ConnectAsync ( connectOptions ) ) ;
454+
455+ Assert . That ( error . Message , Does . Contain ( "blocklist and allowlist are only supported with the CDP protocol" ) ) ;
456+ }
457+
458+ [ Test , PuppeteerTest ( "FirefoxLauncher.test" , "FirefoxLauncher launch" , "should reject blocklist for the default Firefox WebDriver BiDi protocol" ) ]
459+ public void ShouldRejectBlocklistForDefaultFirefoxWebDriverBiDiProtocol ( )
460+ {
461+ var options = new LaunchOptions
462+ {
463+ Browser = SupportedBrowser . Firefox ,
464+ BlockList = [ "https://example.com/*" ] ,
465+ } ;
466+
467+ var error = Assert . ThrowsAsync < PuppeteerException > ( async ( ) =>
468+ await Puppeteer . LaunchAsync ( options ) ) ;
469+
470+ Assert . That ( error . Message , Does . Contain ( "blocklist and allowlist are only supported with the CDP protocol" ) ) ;
471+ }
423472}
0 commit comments