Skip to content

Commit 4564ee8

Browse files
jpeirsonJeff Peirson
andauthored
Fixed issue with disposing shared screenshot task queue (#1880)
Co-authored-by: Jeff Peirson <[email protected]>
1 parent c63b2d2 commit 4564ee8

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Threading.Tasks;
2+
using PuppeteerSharp.Tests.Attributes;
3+
using Xunit;
4+
using Xunit.Abstractions;
5+
6+
namespace PuppeteerSharp.Tests.Issues
7+
{
8+
[Collection(TestConstants.TestFixtureCollectionName)]
9+
public class Issue1878 : PuppeteerBrowserContextBaseTest
10+
{
11+
public Issue1878(ITestOutputHelper output) : base(output)
12+
{
13+
}
14+
15+
[PuppeteerFact]
16+
public async Task MultiplePagesShouldNotShareSameScreenshotTaskQueue()
17+
{
18+
// 1st page
19+
using (Page page = await Context.NewPageAsync())
20+
{
21+
var html = "...some html..";
22+
await page.GoToAsync($"data:text/html,{html}", new NavigationOptions
23+
{
24+
WaitUntil = new[]
25+
{
26+
WaitUntilNavigation.DOMContentLoaded,
27+
WaitUntilNavigation.Load,
28+
WaitUntilNavigation.Networkidle0,
29+
WaitUntilNavigation.Networkidle2
30+
}
31+
});
32+
33+
await page.ScreenshotAsync("...some path...");
34+
}
35+
36+
//2nd page
37+
using (Page page = await Context.NewPageAsync())
38+
{
39+
var html = "...some html...";
40+
await page.GoToAsync($"data:text/html,{html}", new NavigationOptions
41+
{
42+
WaitUntil = new[]
43+
{
44+
WaitUntilNavigation.DOMContentLoaded,
45+
WaitUntilNavigation.Load,
46+
WaitUntilNavigation.Networkidle0,
47+
WaitUntilNavigation.Networkidle2
48+
}
49+
});
50+
51+
await page.ScreenshotAsync("...some path..."); //<- will throw because Browser TaskQueue is disposed when 1st Page is disposed
52+
}
53+
}
54+
}
55+
}

lib/PuppeteerSharp/Page.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,9 +2586,6 @@ protected virtual void Dispose(bool disposing)
25862586
/// calling <see cref="DisposeAsync"/>, you must release all references to the <see cref="Page"/> so
25872587
/// the garbage collector can reclaim the memory that the <see cref="Page"/> was occupying.</remarks>
25882588
/// <returns>ValueTask</returns>
2589-
public ValueTask DisposeAsync() => new ValueTask(CloseAsync()
2590-
.ContinueWith(
2591-
_ => _screenshotTaskQueue.DisposeAsync(),
2592-
TaskScheduler.Default));
2589+
public ValueTask DisposeAsync() => new ValueTask(CloseAsync());
25932590
}
25942591
}

0 commit comments

Comments
 (0)