Skip to content

Commit a65943e

Browse files
Meir017kblok
authored andcommitted
Request.ResourceType enum (#174)
1 parent 99f62f9 commit a65943e

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

lib/PuppeteerSharp/NetworkManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ private void HandleRequestStart(string requestId, dynamic messageData)
263263
requestId,
264264
messageData.interceptionId?.ToString(),
265265
messageData.request.url?.ToString(),
266-
(messageData.resourceType ?? messageData.type)?.ToString(),
266+
(messageData.resourceType ?? messageData.type)?.ToObject<ResourceType>(),
267267
((JObject)messageData.request).ToObject<Payload>(),
268268
messageData.frameId?.ToString());
269269
}
270270

271-
private void HandleRequestStart(string requestId, string interceptionId, string url, string resourceType, Payload requestPayload, string frameId)
271+
private void HandleRequestStart(string requestId, string interceptionId, string url, ResourceType resourceType, Payload requestPayload, string frameId)
272272
{
273273
Frame frame = null;
274274

lib/PuppeteerSharp/Request.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class Request : Payload
1212
#region Private Members
1313
private Session _client;
1414
private bool _allowInterception;
15-
private string _resourceType;
1615
private bool _interceptionHandled;
1716
private string _failureText;
1817

@@ -34,15 +33,15 @@ public class Request : Payload
3433
#endregion
3534

3635
public Request(Session client, string requestId, string interceptionId, bool allowInterception, string url,
37-
string resourceType, Payload payload, Frame frame)
36+
ResourceType resourceType, Payload payload, Frame frame)
3837
{
3938
_client = client;
4039
RequestId = requestId;
4140
InterceptionId = interceptionId;
4241
_allowInterception = allowInterception;
4342
_interceptionHandled = false;
4443
Url = url;
45-
_resourceType = resourceType.ToLower();
44+
ResourceType = resourceType;
4645
Method = payload.Method;
4746
PostData = payload.PostData;
4847
Frame = frame;
@@ -61,6 +60,7 @@ public Request(Session client, string requestId, string interceptionId, bool all
6160
public string Failure { get; set; }
6261
public string RequestId { get; internal set; }
6362
public string InterceptionId { get; internal set; }
63+
public ResourceType ResourceType { get; internal set; }
6464
public Task<bool> CompleteTask => CompleteTaskWrapper.Task;
6565
public TaskCompletionSource<bool> CompleteTaskWrapper { get; internal set; }
6666
public Frame Frame { get; }

lib/PuppeteerSharp/ResourceType.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Converters;
3+
using System.Runtime.Serialization;
4+
5+
namespace PuppeteerSharp
6+
{
7+
[JsonConverter(typeof(StringEnumConverter), true)]
8+
public enum ResourceType
9+
{
10+
Document,
11+
[EnumMember(Value = "stylesheet")]
12+
StyleSheet,
13+
Image,
14+
Media,
15+
Font,
16+
Script,
17+
[EnumMember(Value = "texttrack")]
18+
TextTrack,
19+
Xhr,
20+
Fetch,
21+
[EnumMember(Value = "eventsource")]
22+
EventSource,
23+
[EnumMember(Value = "websocket")]
24+
WebSocket,
25+
Manifest,
26+
Other
27+
}
28+
}

0 commit comments

Comments
 (0)