From 80fd7d0ce8c72a290a948720b5ab050695c5050f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Fri, 18 Jul 2025 09:13:05 -0300 Subject: [PATCH 1/6] Unlock setContent --- .../TestExpectations/TestExpectations.local.json | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json index cfe6877c4..02df38a38 100644 --- a/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json +++ b/lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.local.json @@ -1522,21 +1522,6 @@ "FAIL" ] }, - { - "comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one", - "testIdPattern": "[page.spec] *Page.setContent*", - "platforms": [ - "darwin", - "linux", - "win32" - ], - "parameters": [ - "webDriverBiDi" - ], - "expectations": [ - "FAIL" - ] - }, { "comment": "This is part of organizing the webdriver bidi implementation, We will remove it one by one", "testIdPattern": "[proxy.spec] *", From ee90f950e50833c4a1032936bfbd96248d4465f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 21 Jul 2025 14:52:31 -0300 Subject: [PATCH 2/6] implement --- lib/PuppeteerSharp/Bidi/BidiFrame.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/PuppeteerSharp/Bidi/BidiFrame.cs b/lib/PuppeteerSharp/Bidi/BidiFrame.cs index 195765065..44550a4d3 100644 --- a/lib/PuppeteerSharp/Bidi/BidiFrame.cs +++ b/lib/PuppeteerSharp/Bidi/BidiFrame.cs @@ -97,7 +97,26 @@ internal BidiPage BidiPage public override Task AddScriptTagAsync(AddTagOptions options) => throw new System.NotImplementedException(); /// - public override Task SetContentAsync(string html, NavigationOptions options = null) => throw new System.NotImplementedException(); + public override async Task SetContentAsync(string html, NavigationOptions options = null) + { + var waitUntil = options?.WaitUntil ?? new[] { WaitUntilNavigation.Load }; + var timeout = options?.Timeout ?? TimeoutSettings.NavigationTimeout; + + // Set the frame content using JavaScript, similar to CDP implementation + await EvaluateFunctionAsync( + @"html => { + document.open(); + document.write(html); + document.close(); + }", + html).ConfigureAwait(false); + + // Wait for load and network idle events + var waitForLoadTask = WaitForLoadAsync(options); + var waitForNetworkIdleTask = WaitForNetworkIdleAsync(options); + + await Task.WhenAll(waitForLoadTask, waitForNetworkIdleTask).WithTimeout(timeout).ConfigureAwait(false); + } /// public override async Task GoToAsync(string url, NavigationOptions options) From bf2db011b450e0babc3278f741b08d0fb4d01a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 21 Jul 2025 16:56:55 -0300 Subject: [PATCH 3/6] Bring some code changes --- .../PageTests/SetContentTests.cs | 6 +- .../PuppeteerBrowserBaseTest.cs | 11 ++- lib/PuppeteerSharp/Bidi/BidiElementHandle.cs | 7 +- lib/PuppeteerSharp/Bidi/BidiFrame.cs | 9 +-- lib/PuppeteerSharp/Bidi/BidiFrameRealm.cs | 35 +++++--- lib/PuppeteerSharp/Bidi/BidiJSHandle.cs | 18 ++++- lib/PuppeteerSharp/Bidi/BidiRealm.cs | 81 +++++++++++++++---- lib/PuppeteerSharp/Bidi/Core/Realm.cs | 3 + lib/PuppeteerSharp/Bidi/Core/Session.cs | 2 + lib/PuppeteerSharp/Cdp/CdpElementHandle.cs | 14 ---- lib/PuppeteerSharp/ElementHandle.cs | 14 ++++ lib/PuppeteerSharp/PuppeteerSharp.csproj | 2 +- 12 files changed, 144 insertions(+), 58 deletions(-) diff --git a/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs b/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs index 3c186af30..efd10544e 100644 --- a/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs +++ b/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs @@ -7,7 +7,7 @@ namespace PuppeteerSharp.Tests.PageTests { public class SetContentTests : PuppeteerPageBaseTest { - const string ExpectedOutput = "
hello
"; + private const string ExpectedOutput = "
hello
"; public async Task Usage(IBrowser browser) { @@ -65,7 +65,7 @@ public async Task ShouldRespectTimeout() Timeout = 1 })); - Assert.That(exception.Message, Does.Contain("Timeout of 1 ms exceeded")); + Assert.That(exception!.Message, Does.Contain("Timeout of 1 ms exceeded")); } [Test, PuppeteerTest("page.spec", "Page Page.setContent", "should respect default navigation timeout")] @@ -79,7 +79,7 @@ public async Task ShouldRespectDefaultTimeout() var exception = Assert.ThrowsAsync(async () => await Page.SetContentAsync($"")); - Assert.That(exception.Message, Does.Contain("Timeout of 1 ms exceeded")); + Assert.That(exception!.Message, Does.Contain("Timeout of 1 ms exceeded")); } [Test, PuppeteerTest("page.spec", "Page Page.setContent", "should await resources to load")] diff --git a/lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs b/lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs index 5395435c2..aa94988f3 100644 --- a/lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs +++ b/lib/PuppeteerSharp.Tests/PuppeteerBrowserBaseTest.cs @@ -18,9 +18,16 @@ public async Task InitializeAsync() [TearDown] public async Task TearDownAsync() { - if (Browser is not null) + try { - await Browser.DisposeAsync(); + if (Browser is not null) + { + await Browser.DisposeAsync(); + } + } + catch + { + // Ignore exceptions during browser disposal } } } diff --git a/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs b/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs index b3fb070ac..70d6a738a 100644 --- a/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs +++ b/lib/PuppeteerSharp/Bidi/BidiElementHandle.cs @@ -21,7 +21,6 @@ // * SOFTWARE. using System.Threading.Tasks; -using PuppeteerSharp.Cdp.Messaging; using PuppeteerSharp.QueryHandlers; using WebDriverBiDi.Script; @@ -40,15 +39,15 @@ internal class BidiElementHandle(RemoteValue value, BidiRealm realm) : ElementHa internal override CustomQuerySelectorRegistry CustomQuerySelectorRegistry { get; } = new(); - protected override Page Page { get; } + internal BidiFrame BidiFrame => realm.Environment as BidiFrame; + + protected override Page Page => BidiFrame.BidiPage; public static IJSHandle From(RemoteValue value, BidiRealm realm) { return new BidiElementHandle(value, realm); } - public override ValueTask DisposeAsync() => throw new System.NotImplementedException(); - public override Task UploadFileAsync(bool resolveFilePaths, params string[] filePaths) => throw new System.NotImplementedException(); public override Task