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
22 changes: 22 additions & 0 deletions lib/PuppeteerSharp.Tests/BrowserTests/CreateCDPSessionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Threading.Tasks;
using NUnit.Framework;
using PuppeteerSharp.Nunit;

namespace PuppeteerSharp.Tests.BrowserTests
{
public class CreateCDPSessionTests : PuppeteerBrowserBaseTest
{
[Test, Retry(2), PuppeteerTest("puppeteer-sharp", "Browser.CreateCDPSessionAsync", "should work")]
public async Task ShouldWork()
{
var session = await Browser.CreateCDPSessionAsync();
Assert.That(session, Is.Not.Null);

var response = await session.SendAsync("Browser.getVersion");
Assert.That(response, Is.Not.Null);
Assert.That(response.Value.GetProperty("product").GetString(), Is.Not.Empty);

await session.DetachAsync();
}
}
}
3 changes: 3 additions & 0 deletions lib/PuppeteerSharp/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public void UnregisterCustomQueryHandler(string name)
public void ClearCustomQueryHandlers()
=> CustomQuerySelectorRegistry.Default.ClearCustomQueryHandlers();

/// <inheritdoc/>
public Task<ICDPSession> CreateCDPSessionAsync() => Target.CreateCDPSessionAsync();

/// <inheritdoc/>
public abstract Task<WindowBounds> GetWindowBoundsAsync(string windowId);

Expand Down
6 changes: 6 additions & 0 deletions lib/PuppeteerSharp/IBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,11 @@ public interface IBrowser : IDisposable, IAsyncDisposable
/// <returns>A task that completes when the screen is removed.</returns>
/// <remarks>Only supported in headless mode. Fails if the primary screen ID is specified.</remarks>
Task RemoveScreenAsync(string screenId);

/// <summary>
/// Creates a Chrome Devtools Protocol session attached to the browser.
/// </summary>
/// <returns>A task that returns a <see cref="ICDPSession"/>.</returns>
Task<ICDPSession> CreateCDPSessionAsync();
}
}
Loading