Skip to content

Commit

Permalink
Refactor ElementHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Dec 26, 2024
1 parent e1b7456 commit f5039f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion lib/PuppeteerSharp/Cdp/CdpElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ public class CdpElementHandle : ElementHandle

internal CdpElementHandle(
IsolatedWorld world,
RemoteObject remoteObject) : base(world, remoteObject)
RemoteObject remoteObject)
{
Handle = new CdpJSHandle(world, remoteObject);
Logger = Realm.Environment.Client.Connection.LoggerFactory.CreateLogger(GetType());
_cdpFrame = Realm.Frame as CdpFrame;
}

/// <inheritdoc />
public override RemoteObject RemoteObject => Handle.RemoteObject;

internal override IsolatedWorld Realm => Handle.Realm;

/// <summary>
/// Logger.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion lib/PuppeteerSharp/Cdp/CdpJSHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ namespace PuppeteerSharp.Cdp;
/// <inheritdoc/>
public class CdpJSHandle : JSHandle
{
internal CdpJSHandle(IsolatedWorld world, RemoteObject remoteObject) : base(world, remoteObject)
internal CdpJSHandle(IsolatedWorld world, RemoteObject remoteObject)
{
Logger = Client.Connection.LoggerFactory.CreateLogger(GetType());
Realm = world;
RemoteObject = remoteObject;
}

/// <inheritdoc/>
public override RemoteObject RemoteObject { get; }

internal override IsolatedWorld Realm { get; }

/// <summary>
/// Logger.
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions lib/PuppeteerSharp/ElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public abstract class ElementHandle : JSHandle, IElementHandle
{
private ElementHandle _isolatedHandle;

internal ElementHandle(
IsolatedWorld world,
RemoteObject remoteObject) : base(world, remoteObject)
internal ElementHandle()
{
}

Expand Down
8 changes: 3 additions & 5 deletions lib/PuppeteerSharp/JSHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ namespace PuppeteerSharp
/// <inheritdoc/>
public abstract class JSHandle : IJSHandle
{
internal JSHandle(IsolatedWorld world, RemoteObject remoteObject)
internal JSHandle()
{
Realm = world;
RemoteObject = remoteObject;
}

/// <inheritdoc/>
public bool Disposed { get; protected set; }

/// <inheritdoc/>
public RemoteObject RemoteObject { get; }
public abstract RemoteObject RemoteObject { get; }

internal Func<Task> DisposeAction { get; set; }

internal IsolatedWorld Realm { get; }
internal abstract IsolatedWorld Realm { get; }

internal Frame Frame => Realm.Environment as Frame;

Expand Down

0 comments on commit f5039f5

Please sign in to comment.