Skip to content

Commit 3f0422a

Browse files
committed
fix
1 parent e56e641 commit 3f0422a

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

lib/PuppeteerSharp.Tests/FrameTests/FrameEvaluateTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ namespace PuppeteerSharp.Tests.FrameTests
66
{
77
public class FrameEvaluateTests : PuppeteerPageBaseTest
88
{
9-
public FrameEvaluateTests() : base()
10-
{
11-
}
12-
139
[Test, PuppeteerTest("frame.spec", "Frame.evaluate", "should throw for detached frames")]
1410
public async Task ShouldThrowForDetachedFrames()
1511
{

lib/PuppeteerSharp/Bidi/BidiElementHandle.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// * SOFTWARE.
2222

23+
using System.Linq;
2324
using System.Threading.Tasks;
2425
using PuppeteerSharp.QueryHandlers;
2526
using WebDriverBiDi.Script;
@@ -50,5 +51,30 @@ public static IJSHandle From(RemoteValue value, BidiRealm realm)
5051

5152
public override Task UploadFileAsync(bool resolveFilePaths, params string[] filePaths) => throw new System.NotImplementedException();
5253

53-
public override Task<IFrame> ContentFrameAsync() => throw new System.NotImplementedException();
54+
public override async Task<IFrame> ContentFrameAsync()
55+
{
56+
var handle = await EvaluateFunctionHandleAsync(@"element => {
57+
if (element instanceof HTMLIFrameElement || element instanceof HTMLFrameElement) {
58+
return element.contentWindow;
59+
}
60+
return;
61+
}").ConfigureAwait(false);
62+
63+
if (handle is not BidiJSHandle bidiHandle)
64+
{
65+
await handle.DisposeAsync().ConfigureAwait(false);
66+
return null;
67+
}
68+
69+
var value = bidiHandle.RemoteValue;
70+
await handle.DisposeAsync().ConfigureAwait(false);
71+
72+
if (value.Type == "window" && value.Value is WindowProxyProperties windowProxy)
73+
{
74+
var contextId = windowProxy.Context;
75+
return BidiFrame.BidiPage.Frames.FirstOrDefault(frame => frame.Id == contextId);
76+
}
77+
78+
return null;
79+
}
5480
}

0 commit comments

Comments
 (0)