Skip to content

Commit

Permalink
Add Page.IsClosed property (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meir017 authored and kblok committed Aug 4, 2018
1 parent f19813b commit 1de769f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/PuppeteerSharp.Tests/PageTests/CloseTests.cs
Expand Up @@ -59,5 +59,13 @@ public async Task ShouldRunBeforeunloadIfAskedFor()
closeTask.Task
);
}

[Fact]
public async Task ShouldSetThePageCloseState()
{
Assert.False(Page.IsClosed);
await Page.CloseAsync();
Assert.True(Page.IsClosed);
}
}
}
13 changes: 11 additions & 2 deletions lib/PuppeteerSharp/Page.cs
Expand Up @@ -78,7 +78,10 @@ private Page(CDPSession client, Target target, FrameTree frameTree, bool ignoreH
_networkManager.Response += (sender, e) => Response?.Invoke(this, e);
_networkManager.RequestFinished += (sender, e) => RequestFinished?.Invoke(this, e);

target.CloseTask.ContinueWith((arg) => Close?.Invoke(this, EventArgs.Empty));
target.CloseTask.ContinueWith((arg) => {
Close?.Invoke(this, EventArgs.Empty);
IsClosed = true;
});

Client.MessageReceived += Client_MessageReceived;
}
Expand Down Expand Up @@ -243,7 +246,7 @@ private Page(CDPSession client, Target target, FrameTree frameTree, bool ignoreH
public ViewPortOptions Viewport { get; private set; }

/// <summary>
/// List of suported metrics provided by the <see cref="Metrics"/> event.
/// List of supported metrics provided by the <see cref="Metrics"/> event.
/// </summary>
public static readonly IEnumerable<string> SupportedMetrics = new List<string>
{
Expand All @@ -266,6 +269,12 @@ private Page(CDPSession client, Target target, FrameTree frameTree, bool ignoreH
/// Get the browser the page belongs to.
/// </summary>
public Browser Browser => Target.Browser;

/// <summary>
/// Get an indication that the page has been closed.
/// </summary>
public bool IsClosed { get; private set; }

#endregion

#region Public Methods
Expand Down

0 comments on commit 1de769f

Please sign in to comment.