Skip to content

Commit b1b8982

Browse files
authored
Make sure headful browser closes with beforeuload page (#913)
1 parent 74deb46 commit b1b8982

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/PuppeteerSharp.Tests/PuppeteerTests/HeadfulTests.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.IO;
52
using System.Linq;
6-
using System.Net;
7-
using System.Runtime.InteropServices;
83
using System.Threading.Tasks;
94
using PuppeteerSharp.Helpers;
105
using Xunit;
@@ -110,6 +105,20 @@ await page.EvaluateFunctionHandleAsync(@"() => {
110105
}
111106
}
112107

108+
[Fact]
109+
public async Task ShouldCloseBrowserWithBeforeunloadPage()
110+
{
111+
var headfulOptions = TestConstants.DefaultBrowserOptions();
112+
headfulOptions.Headless = false;
113+
using (var browser = await Puppeteer.LaunchAsync(headfulOptions))
114+
using (var page = await browser.NewPageAsync())
115+
{
116+
await page.GoToAsync(TestConstants.ServerUrl + "/beforeunload.html");
117+
// We have to interact with a page so that 'beforeunload' handlers fire.
118+
await page.ClickAsync("body");
119+
}
120+
}
121+
113122
private Task<Target> WaitForBackgroundPageTargetAsync(Browser browser)
114123
{
115124
var target = browser.Targets().FirstOrDefault(t => t.Type == TargetType.BackgroundPage);

0 commit comments

Comments
 (0)