diff --git a/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo-Local.csproj b/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo-Local.csproj
index f12d1f7da..b9fbd3d89 100644
--- a/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo-Local.csproj
+++ b/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo-Local.csproj
@@ -2,13 +2,8 @@
Exe
- netcoreapp2.0;net471
-
-
- 7.2
-
-
- 7.2
+ netcoreapp2.2;net471
+ 7.3
win7-x64
diff --git a/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo.csproj b/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo.csproj
index 1e72bb176..836052b60 100644
--- a/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo.csproj
+++ b/demos/PuppeteerSharpPdfDemo/PuppeteerSharpPdfDemo.csproj
@@ -2,14 +2,8 @@
Exe
- netcoreapp2.0
-
-
-
- 7.2
-
-
- 7.2
+ netcoreapp2.2
+ 7.3
diff --git a/lib/PuppeteerSharp/CDPSession.cs b/lib/PuppeteerSharp/CDPSession.cs
index 24967eaa2..b8dd4d09e 100644
--- a/lib/PuppeteerSharp/CDPSession.cs
+++ b/lib/PuppeteerSharp/CDPSession.cs
@@ -15,7 +15,7 @@ namespace PuppeteerSharp
{
///
/// The CDPSession instances are used to talk raw Chrome Devtools Protocol:
- /// * Protocol methods can be called with method.
+ /// * Protocol methods can be called with method.
/// * Protocol events, using the event.
///
/// Documentation on DevTools Protocol can be found here: .
@@ -106,7 +106,7 @@ internal CDPSession(IConnection connection, TargetType targetType, string sessio
#region Public Methods
- internal void Send(string method, dynamic args = null)
+ internal void Send(string method, object args = null)
=> _ = SendAsync(method, args, false);
///
@@ -115,9 +115,9 @@ internal void Send(string method, dynamic args = null)
/// The method name
/// The method args
/// The task.
- public async Task SendAsync(string method, dynamic args = null)
+ public async Task SendAsync(string method, object args = null)
{
- JObject content = await SendAsync(method, args).ConfigureAwait(false);
+ var content = await SendAsync(method, args).ConfigureAwait(false);
return content.ToObject(true);
}
@@ -133,7 +133,7 @@ public async Task SendAsync(string method, dynamic args = null)
///
/// The task.
///
- public async Task SendAsync(string method, dynamic args = null, bool waitForCallback = true)
+ public async Task SendAsync(string method, object args = null, bool waitForCallback = true)
{
if (Connection == null)
{
@@ -150,7 +150,7 @@ public async Task SendAsync(string method, dynamic args = null, bool wa
{ MessageKeys.Params, args }
}, JsonHelper.DefaultJsonSerializerSettings);
- _logger.LogTrace("Send ► {Id} Method {Method} Params {@Params}", id, method, (object)args);
+ _logger.LogTrace("Send ► {Id} Method {Method} Params {@Params}", id, method, args);
MessageTask callback = null;
if (waitForCallback)
@@ -310,7 +310,7 @@ internal CDPSession CreateSession(TargetType targetType, string sessionId)
#region IConnection
ILoggerFactory IConnection.LoggerFactory => LoggerFactory;
bool IConnection.IsClosed => IsClosed;
- Task IConnection.SendAsync(string method, dynamic args, bool waitForCallback)
+ Task IConnection.SendAsync(string method, object args, bool waitForCallback)
=> SendAsync(method, args, waitForCallback);
IConnection IConnection.Connection => Connection;
void IConnection.Close(string closeReason) => Close(closeReason);
diff --git a/lib/PuppeteerSharp/Connection.cs b/lib/PuppeteerSharp/Connection.cs
index 2aa04a16e..97a1ef231 100644
--- a/lib/PuppeteerSharp/Connection.cs
+++ b/lib/PuppeteerSharp/Connection.cs
@@ -87,7 +87,7 @@ internal Connection(string url, int delay, IConnectionTransport transport, ILogg
#region Public Methods
- internal async Task SendAsync(string method, dynamic args = null, bool waitForCallback = true)
+ internal async Task SendAsync(string method, object args = null, bool waitForCallback = true)
{
if (IsClosed)
{
@@ -119,9 +119,9 @@ internal async Task SendAsync(string method, dynamic args = null, bool
return waitForCallback ? await callback.TaskWrapper.Task.WithConnectionCheck(this).ConfigureAwait(false) : null;
}
- internal async Task SendAsync(string method, dynamic args = null)
+ internal async Task SendAsync(string method, object args = null)
{
- JToken response = await SendAsync(method, args).ConfigureAwait(false);
+ var response = await SendAsync(method, args).ConfigureAwait(false);
return response.ToObject(true);
}
@@ -305,7 +305,7 @@ public void Dispose()
#region IConnection
ILoggerFactory IConnection.LoggerFactory => LoggerFactory;
bool IConnection.IsClosed => IsClosed;
- Task IConnection.SendAsync(string method, dynamic args, bool waitForCallback)
+ Task IConnection.SendAsync(string method, object args, bool waitForCallback)
=> SendAsync(method, args, waitForCallback);
IConnection IConnection.Connection => null;
void IConnection.Close(string closeReason) => Close(closeReason);
diff --git a/lib/PuppeteerSharp/ElementHandle.cs b/lib/PuppeteerSharp/ElementHandle.cs
index bf15169a0..b0c7df2ef 100644
--- a/lib/PuppeteerSharp/ElementHandle.cs
+++ b/lib/PuppeteerSharp/ElementHandle.cs
@@ -24,7 +24,7 @@ public class ElementHandle : JSHandle
internal ElementHandle(
ExecutionContext context,
CDPSession client,
- JToken remoteObject,
+ RemoteObject remoteObject,
Page page,
FrameManager frameManager) :
base(context, client, remoteObject)
@@ -198,7 +198,7 @@ public async Task ClickAsync(ClickOptions options = null)
public Task UploadFileAsync(params string[] filePaths)
{
var files = filePaths.Select(Path.GetFullPath).ToArray();
- var objectId = RemoteObject[MessageKeys.ObjectId].AsString();
+ var objectId = RemoteObject.ObjectId;
return Client.SendAsync("DOM.setFileInputFiles", new { objectId, files });
}
@@ -386,7 +386,7 @@ public async Task ContentFrameAsync()
{
var nodeInfo = await Client.SendAsync("DOM.describeNode", new Dictionary
{
- { MessageKeys.ObjectId, RemoteObject[MessageKeys.ObjectId] }
+ { MessageKeys.ObjectId, RemoteObject.ObjectId }
}).ConfigureAwait(false);
return string.IsNullOrEmpty(nodeInfo.Node.FrameId) ? null : await _frameManager.GetFrameAsync(nodeInfo.Node.FrameId);
@@ -419,7 +419,7 @@ public Task IsIntersectingViewportAsync()
{
result = await Client.SendAsync("DOM.getContentQuads", new Dictionary
{
- { MessageKeys.ObjectId, RemoteObject[MessageKeys.ObjectId] }
+ { MessageKeys.ObjectId, RemoteObject.ObjectId }
}).ConfigureAwait(false);
}
catch (Exception ex)
@@ -491,7 +491,7 @@ private async Task GetBoxModelAsync()
{
return await Client.SendAsync("DOM.getBoxModel", new
{
- objectId = RemoteObject[MessageKeys.ObjectId].AsString()
+ objectId = RemoteObject.ObjectId
}).ConfigureAwait(false);
}
catch (PuppeteerException ex)
diff --git a/lib/PuppeteerSharp/EvaluationFailedException.cs b/lib/PuppeteerSharp/EvaluationFailedException.cs
index 4c29779ef..01afef4a8 100644
--- a/lib/PuppeteerSharp/EvaluationFailedException.cs
+++ b/lib/PuppeteerSharp/EvaluationFailedException.cs
@@ -4,7 +4,7 @@
namespace PuppeteerSharp
{
///
- /// Exception thrown by .
+ /// Exception thrown by .
///
[Serializable]
public class EvaluationFailedException : PuppeteerException
diff --git a/lib/PuppeteerSharp/ExecutionContext.cs b/lib/PuppeteerSharp/ExecutionContext.cs
index 08f2ae944..c3bc4e2df 100755
--- a/lib/PuppeteerSharp/ExecutionContext.cs
+++ b/lib/PuppeteerSharp/ExecutionContext.cs
@@ -6,6 +6,7 @@
using Newtonsoft.Json.Linq;
using PuppeteerSharp.Messaging;
using PuppeteerSharp.Helpers;
+using static PuppeteerSharp.Messaging.RuntimeQueryObjectsResponse;
namespace PuppeteerSharp
{
@@ -111,17 +112,17 @@ public async Task QueryObjectsAsync(JSHandle prototypeHandle)
throw new PuppeteerException("Prototype JSHandle is disposed!");
}
- if (!((JObject)prototypeHandle.RemoteObject).TryGetValue(MessageKeys.ObjectId, out var objectId))
+ if (prototypeHandle.RemoteObject.ObjectId == null)
{
throw new PuppeteerException("Prototype JSHandle must not be referencing primitive value");
}
- var response = await _client.SendAsync("Runtime.queryObjects", new Dictionary
+ var response = await _client.SendAsync("Runtime.queryObjects", new Dictionary
{
- {"prototypeObjectId", objectId.ToString()}
+ {"prototypeObjectId", prototypeHandle.RemoteObject.ObjectId}
}).ConfigureAwait(false);
- return CreateJSHandle(response[MessageKeys.Objects]);
+ return CreateJSHandle(response.Objects);
}
internal async Task EvaluateExpressionHandleAsync(string script)
@@ -173,8 +174,8 @@ internal async Task EvaluateFunctionHandleAsync(string script, params
}
}
- internal JSHandle CreateJSHandle(dynamic remoteObject)
- => (remoteObject.subtype == "node" && Frame != null)
+ internal JSHandle CreateJSHandle(RemoteObject remoteObject)
+ => remoteObject.Subtype == RemoteObjectSubtype.Node && Frame != null
? new ElementHandle(this, _client, remoteObject, Frame.FrameManager.Page, Frame.FrameManager)
: new JSHandle(this, _client, remoteObject);
@@ -201,17 +202,17 @@ private async Task EvaluateAsync(Task handleEvaluator)
return result is JToken token && token.Type == JTokenType.Null ? default : result;
}
- private async Task EvaluateHandleAsync(string method, dynamic args)
+ private async Task EvaluateHandleAsync(string method, object args)
{
- var response = await _client.SendAsync(method, args).ConfigureAwait(false);
+ var response = await _client.SendAsync(method, args).ConfigureAwait(false);
- if (response[MessageKeys.ExceptionDetails] is JToken exceptionDetails)
+ if (response.ExceptionDetails != null)
{
throw new EvaluationFailedException("Evaluation failed: " +
- GetExceptionMessage(exceptionDetails.ToObject(true)));
+ GetExceptionMessage(response.ExceptionDetails));
}
- return CreateJSHandle(response.result);
+ return CreateJSHandle(response.Result);
}
private object FormatArgument(object arg)
diff --git a/lib/PuppeteerSharp/Helpers/FlexibleStringEnumConverter.cs b/lib/PuppeteerSharp/Helpers/FlexibleStringEnumConverter.cs
index 1422282b7..6f50e2797 100644
--- a/lib/PuppeteerSharp/Helpers/FlexibleStringEnumConverter.cs
+++ b/lib/PuppeteerSharp/Helpers/FlexibleStringEnumConverter.cs
@@ -6,12 +6,9 @@ namespace PuppeteerSharp.Helpers
{
internal class FlexibleStringEnumConverter : StringEnumConverter
{
- private Enum _fallbackValue;
+ private readonly Enum _fallbackValue;
- public FlexibleStringEnumConverter(Enum fallbackValue)
- {
- _fallbackValue = fallbackValue;
- }
+ public FlexibleStringEnumConverter(Enum fallbackValue) => _fallbackValue = fallbackValue;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
diff --git a/lib/PuppeteerSharp/Helpers/RemoteObjectHelper.cs b/lib/PuppeteerSharp/Helpers/RemoteObjectHelper.cs
index c6f8b8f5e..c02bb1b9b 100755
--- a/lib/PuppeteerSharp/Helpers/RemoteObjectHelper.cs
+++ b/lib/PuppeteerSharp/Helpers/RemoteObjectHelper.cs
@@ -8,9 +8,9 @@ namespace PuppeteerSharp.Helpers
{
internal class RemoteObjectHelper
{
- internal static object ValueFromRemoteObject(JToken remoteObject)
+ internal static object ValueFromRemoteObject(RemoteObject remoteObject)
{
- var unserializableValue = remoteObject[MessageKeys.UnserializableValue]?.AsString();
+ var unserializableValue = remoteObject.UnserializableValue;
if (unserializableValue != null)
{
@@ -29,7 +29,7 @@ internal static object ValueFromRemoteObject(JToken remoteObject)
}
}
- var value = remoteObject[MessageKeys.Value];
+ var value = remoteObject.Value;
if (value == null)
{
@@ -37,37 +37,35 @@ internal static object ValueFromRemoteObject(JToken remoteObject)
}
// https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-RemoteObject
- var objectType = remoteObject[MessageKeys.Type].AsString();
+ var objectType = remoteObject.Type;
switch (objectType)
{
- case "object":
+ case RemoteObjectType.Object:
return value.ToObject(true);
- case "undefined":
+ case RemoteObjectType.Undefined:
return null;
- case "number":
+ case RemoteObjectType.Number:
return value.Value();
- case "boolean":
+ case RemoteObjectType.Boolean:
return value.Value();
- case "bigint":
+ case RemoteObjectType.Bigint:
return value.Value();
default: // string, symbol, function
return value.ToObject();
}
}
- internal static async Task ReleaseObject(CDPSession client, JToken remoteObject, ILogger logger)
+ internal static async Task ReleaseObjectAsync(CDPSession client, RemoteObject remoteObject, ILogger logger)
{
- var objectId = remoteObject[MessageKeys.ObjectId]?.AsString();
-
- if (objectId == null)
+ if (remoteObject.ObjectId == null)
{
return;
}
try
{
- await client.SendAsync("Runtime.releaseObject", new { objectId }).ConfigureAwait(false);
+ await client.SendAsync("Runtime.releaseObject", new { remoteObject.ObjectId }).ConfigureAwait(false);
}
catch (Exception ex)
{
diff --git a/lib/PuppeteerSharp/IConnection.cs b/lib/PuppeteerSharp/IConnection.cs
index bd0aa3240..cfb451259 100644
--- a/lib/PuppeteerSharp/IConnection.cs
+++ b/lib/PuppeteerSharp/IConnection.cs
@@ -34,7 +34,7 @@ internal interface IConnection
/// If true the method will return a task to be completed when the message is confirmed by Chromium.
/// If false the task will be considered complete after sending the message to Chromium.
///
- Task SendAsync(string method, dynamic args = null, bool waitForCallback = true);
+ Task SendAsync(string method, object args = null, bool waitForCallback = true);
///
/// Gets the parent connection
///
diff --git a/lib/PuppeteerSharp/JSHandle.cs b/lib/PuppeteerSharp/JSHandle.cs
old mode 100755
new mode 100644
index 615a8f3ae..da0819f70
--- a/lib/PuppeteerSharp/JSHandle.cs
+++ b/lib/PuppeteerSharp/JSHandle.cs
@@ -12,7 +12,7 @@ namespace PuppeteerSharp
///
public class JSHandle
{
- internal JSHandle(ExecutionContext context, CDPSession client, JToken remoteObject)
+ internal JSHandle(ExecutionContext context, CDPSession client, RemoteObject remoteObject)
{
ExecutionContext = context;
Client = client;
@@ -34,7 +34,7 @@ internal JSHandle(ExecutionContext context, CDPSession client, JToken remoteObje
/// Gets or sets the remote object.
///
/// The remote object.
- public JToken RemoteObject { get; }
+ public RemoteObject RemoteObject { get; }
///
/// Gets the client.
///
@@ -79,22 +79,22 @@ public async Task GetPropertyAsync(string propertyName)
///
public async Task> GetPropertiesAsync()
{
- var response = await Client.SendAsync("Runtime.getProperties", new
+ var response = await Client.SendAsync("Runtime.getProperties", new
{
- objectId = RemoteObject[MessageKeys.ObjectId].AsString(),
+ objectId = RemoteObject.ObjectId,
ownProperties = true
}).ConfigureAwait(false);
var result = new Dictionary();
- foreach (var property in response[MessageKeys.Result])
+ foreach (var property in response.Result)
{
- if (property[MessageKeys.Enumerable] == null)
+ if (property.Enumerable == null)
{
continue;
}
- result.Add(property[MessageKeys.Name].AsString(), ExecutionContext.CreateJSHandle(property[MessageKeys.Value]));
+ result.Add(property.Name, ExecutionContext.CreateJSHandle(property.Value));
}
return result;
}
@@ -118,18 +118,18 @@ public async Task> GetPropertiesAsync()
///
public async Task JsonValueAsync()
{
- var objectId = RemoteObject[MessageKeys.ObjectId];
+ var objectId = RemoteObject.ObjectId;
if (objectId != null)
{
- var response = await Client.SendAsync("Runtime.callFunctionOn", new Dictionary
+ var response = await Client.SendAsync("Runtime.callFunctionOn", new Dictionary
{
["functionDeclaration"] = "function() { return this; }",
[MessageKeys.ObjectId] = objectId,
["returnByValue"] = true,
["awaitPromise"] = true
}).ConfigureAwait(false);
- return (T)RemoteObjectHelper.ValueFromRemoteObject(response[MessageKeys.Result]);
+ return (T)RemoteObjectHelper.ValueFromRemoteObject(response.Result);
}
return (T)RemoteObjectHelper.ValueFromRemoteObject(RemoteObject);
@@ -147,16 +147,18 @@ public async Task DisposeAsync()
}
Disposed = true;
- await RemoteObjectHelper.ReleaseObject(Client, RemoteObject, Logger).ConfigureAwait(false);
+ await RemoteObjectHelper.ReleaseObjectAsync(Client, RemoteObject, Logger).ConfigureAwait(false);
}
///
public override string ToString()
{
- if ((RemoteObject)[MessageKeys.ObjectId] != null)
+ if (RemoteObject.ObjectId != null)
{
- var type = RemoteObject[MessageKeys.Subtype] ?? RemoteObject[MessageKeys.Type];
- return "JSHandle@" + type;
+ var type = RemoteObject.Subtype != RemoteObjectSubtype.Other
+ ? RemoteObject.Subtype.ToString()
+ : RemoteObject.Type.ToString();
+ return "JSHandle@" + type.ToLower();
}
return "JSHandle:" + RemoteObjectHelper.ValueFromRemoteObject