Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/PuppeteerSharp.Tests/LauncherTests/BrowserCloseTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using PuppeteerSharp.Bidi;
using PuppeteerSharp.Nunit;

namespace PuppeteerSharp.Tests.LauncherTests
Expand Down Expand Up @@ -32,6 +34,30 @@ public async Task ShouldTerminateNetworkWaiters()
Assert.That(exception.Message, Does.Not.Contain("Timeout"));
}

[Test, PuppeteerTest("launcher.spec", "Launcher specs Puppeteer Browser.close", "should stop the browser process when the close command fails")]
public async Task ShouldStopTheBrowserProcessWhenTheCloseCommandFails()
{
if (PuppeteerTestAttribute.IsCdp)
{
Assert.Ignore("There is no BiDi connection to break on CDP.");
}

var browser = await Puppeteer.LaunchAsync(TestConstants.DefaultBrowserOptions());
var launcher = ((Browser)browser).Launcher;
try
{
await ((BidiBrowser)browser).Driver.StopAsync();

await browser.CloseAsync();

Assert.That(await launcher.WaitForExitAsync(TimeSpan.FromSeconds(10)), Is.True);
}
finally
{
await launcher.KillAsync();
}
}

[Test, PuppeteerTest("launcher.spec", "PuppeteerSharp", "delete temp user data dir when disposing browser")]
public async Task DeleteTempUserDataDirWhenDisposingBrowser()
{
Expand Down
9 changes: 8 additions & 1 deletion lib/PuppeteerSharp/Bidi/BidiBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ public override async Task CloseAsync()
{
try
{
await BrowserCore.CloseAsync().ConfigureAwait(false);
try
{
await BrowserCore.CloseAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to send browser close command");
}

if (CloseCallback != null)
{
Expand Down
Loading