Skip to content

Commit

Permalink
Fix CDP refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Dec 27, 2024
1 parent deaae6b commit fc902ee
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/PuppeteerSharp/Cdp/CdpElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace PuppeteerSharp.Cdp;

/// <inheritdoc />
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CdpElementHandle : ElementHandle
public class CdpElementHandle : ElementHandle, ICdpHandle
{
private readonly CdpFrame _cdpFrame;

Expand All @@ -52,6 +52,7 @@ internal CdpElementHandle(
/// </summary>
public RemoteObject RemoteObject => ((CdpJSHandle)Handle).RemoteObject;

/// <inheritdoc/>
internal override Realm Realm => Handle.Realm;

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion lib/PuppeteerSharp/Cdp/CdpJSHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace PuppeteerSharp.Cdp;

/// <inheritdoc/>
public class CdpJSHandle : JSHandle
public class CdpJSHandle : JSHandle, ICdpHandle
{
internal CdpJSHandle(IsolatedWorld world, RemoteObject remoteObject)
{
Expand All @@ -45,6 +45,7 @@ internal CdpJSHandle(IsolatedWorld world, RemoteObject remoteObject)

internal string Id => RemoteObject.ObjectId;

/// <inheritdoc/>
internal override Realm Realm { get; }

/// <summary>
Expand Down
36 changes: 36 additions & 0 deletions lib/PuppeteerSharp/Cdp/ICdpHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// * MIT License
// *
// * Copyright (c) Darío Kondratiuk
// *
// * Permission is hereby granted, free of charge, to any person obtaining a copy
// * of this software and associated documentation files (the "Software"), to deal
// * in the Software without restriction, including without limitation the rights
// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// * copies of the Software, and to permit persons to whom the Software is
// * furnished to do so, subject to the following conditions:
// *
// * The above copyright notice and this permission notice shall be included in all
// * copies or substantial portions of the Software.
// *
// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// * SOFTWARE.

using PuppeteerSharp.Cdp.Messaging;

namespace PuppeteerSharp.Cdp;

/// <summary>
/// CDP Specific handle info.
/// </summary>
internal interface ICdpHandle : IJSHandle
{
/// <summary>
/// CDP remote object.
/// </summary>
RemoteObject RemoteObject { get; }
}
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/IsolatedWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ internal override async Task<IElementHandle> AdoptBackendNodeAsync(object backen

internal override async Task<IJSHandle> TransferHandleAsync(IJSHandle handle)
{
var cdpHandle = (CdpJSHandle)handle;
if (cdpHandle.Realm == this)
var cdpHandle = (ICdpHandle)handle;
if (((JSHandle)cdpHandle).Realm == this)
{
return handle;
}
Expand Down

0 comments on commit fc902ee

Please sign in to comment.