Skip to content

Commit 7c5daa6

Browse files
committed
Revert "Fix request interception with complex PostData"
This reverts commit 0112e13.
1 parent 0112e13 commit 7c5daa6

14 files changed

+23
-76
lines changed

lib/PuppeteerSharp/BrowserData/JsonUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace PuppeteerSharp.BrowserData
77
{
8-
internal static class JsonUtils
8+
internal class JsonUtils
99
{
1010
public static async Task<T> GetAsync<T>(string url)
1111
{

lib/PuppeteerSharp/CDPSession.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public abstract class CDPSession : ICDPSession
3030
/// <inheritdoc/>
3131
public string Id { get; init; }
3232

33-
/// <inheritdoc/>
34-
public string CloseReason { get; protected set; }
35-
3633
/// <inheritdoc/>
3734
public ILoggerFactory LoggerFactory => Connection.LoggerFactory;
3835

lib/PuppeteerSharp/Cdp/CdpCDPSession.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class CdpCDPSession : CDPSession
4040
private readonly ConcurrentDictionary<int, MessageTask> _callbacks = new();
4141
private readonly string _parentSessionId;
4242
private readonly TargetType _targetType;
43+
private string _closeReason;
4344
private int _lastId;
4445

4546
internal CdpCDPSession(Connection connection, TargetType targetType, string sessionId, string parentSessionId)
@@ -78,8 +79,8 @@ public override Task DetachAsync()
7879
throw new TargetClosedException(
7980
$"Protocol error ({method}): Session closed. " +
8081
$"Most likely the {_targetType} has been closed." +
81-
$"Close reason: {CloseReason}",
82-
CloseReason);
82+
$"Close reason: {_closeReason}",
83+
_closeReason);
8384
}
8485

8586
var id = GetMessageId();
@@ -146,7 +147,7 @@ internal override void Close(string closeReason)
146147
return;
147148
}
148149

149-
CloseReason = closeReason;
150+
_closeReason = closeReason;
150151
IsClosed = true;
151152

152153
foreach (var callback in _callbacks.Values.ToArray())

lib/PuppeteerSharp/Cdp/CdpHttpRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal CdpHttpRequest(
2929
IFrame frame,
3030
string interceptionId,
3131
bool allowInterception,
32-
RequestWillBeSentResponse data,
32+
RequestWillBeSentPayload data,
3333
List<IRequest> redirectChain,
3434
ILoggerFactory loggerFactory)
3535
{

lib/PuppeteerSharp/Cdp/LifecycleWatcher.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,7 @@ private void OnFrameDetached(object sender, EventArgs e)
110110
var frame = sender as Frame;
111111
if (_frame == frame)
112112
{
113-
var message = "Navigating frame was detached";
114-
115-
if (!string.IsNullOrEmpty(frame?.Client?.CloseReason))
116-
{
117-
message += $": {frame.Client.CloseReason}";
118-
}
119-
120-
Terminate(new PuppeteerException(message));
113+
Terminate(new PuppeteerException("Navigating frame was detached"));
121114
return;
122115
}
123116

lib/PuppeteerSharp/Cdp/Messaging/FetchRequestPausedResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace PuppeteerSharp.Cdp.Messaging
22
{
3-
internal class FetchRequestPausedResponse : RequestWillBeSentResponse
3+
internal class FetchRequestPausedResponse : RequestWillBeSentPayload
44
{
55
public ResourceType? ResourceType { get; set; }
66
}

lib/PuppeteerSharp/Cdp/Messaging/Request.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

lib/PuppeteerSharp/Cdp/Messaging/RequestWillBeSentResponse.cs renamed to lib/PuppeteerSharp/Cdp/Messaging/RequestWillBeSentPayload.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace PuppeteerSharp.Cdp.Messaging
22
{
3-
internal class RequestWillBeSentResponse
3+
internal class RequestWillBeSentPayload
44
{
55
public string RequestId { get; set; }
66

77
public string LoaderId { get; set; }
88

9-
public Request Request { get; set; }
9+
public Payload Request { get; set; }
1010

1111
public ResponsePayload RedirectResponse { get; set; }
1212

lib/PuppeteerSharp/Cdp/NetworkEventManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PuppeteerSharp.Cdp
77
{
88
internal class NetworkEventManager
99
{
10-
private readonly ConcurrentDictionary<string, RequestWillBeSentResponse> _requestWillBeSentMap = new();
10+
private readonly ConcurrentDictionary<string, RequestWillBeSentPayload> _requestWillBeSentMap = new();
1111
private readonly ConcurrentDictionary<string, FetchRequestPausedResponse> _requestPausedMap = new();
1212
private readonly ConcurrentDictionary<string, CdpHttpRequest> _httpRequestsMap = new();
1313
private readonly ConcurrentDictionary<string, QueuedEventGroup> _queuedEventGroupMap = new();
@@ -59,10 +59,10 @@ internal ResponseReceivedExtraInfoResponse ShiftResponseExtraInfo(string network
5959
return result;
6060
}
6161

62-
internal void StoreRequestWillBeSent(string networkRequestId, RequestWillBeSentResponse e)
62+
internal void StoreRequestWillBeSent(string networkRequestId, RequestWillBeSentPayload e)
6363
=> _requestWillBeSentMap.AddOrUpdate(networkRequestId, e, (_, _) => e);
6464

65-
internal RequestWillBeSentResponse GetRequestWillBeSent(string networkRequestId)
65+
internal RequestWillBeSentPayload GetRequestWillBeSent(string networkRequestId)
6666
{
6767
_requestWillBeSentMap.TryGetValue(networkRequestId, out var result);
6868
return result;

lib/PuppeteerSharp/Cdp/NetworkManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private async void Client_MessageReceived(object sender, MessageEventArgs e)
173173
await OnAuthRequiredAsync(client, e.MessageData.ToObject<FetchAuthRequiredResponse>()).ConfigureAwait(false);
174174
break;
175175
case "Network.requestWillBeSent":
176-
await OnRequestWillBeSentAsync(client, e.MessageData.ToObject<RequestWillBeSentResponse>()).ConfigureAwait(false);
176+
await OnRequestWillBeSentAsync(client, e.MessageData.ToObject<RequestWillBeSentPayload>()).ConfigureAwait(false);
177177
break;
178178
case "Network.requestServedFromCache":
179179
OnRequestServedFromCache(e.MessageData.ToObject<RequestServedFromCacheResponse>());
@@ -462,7 +462,7 @@ private async void OnRequestWithoutNetworkInstrumentationAsync(CDPSession client
462462
_ = request.FinalizeInterceptionsAsync();
463463
}
464464

465-
private async Task OnRequestAsync(CDPSession client, RequestWillBeSentResponse e, string fetchRequestId)
465+
private async Task OnRequestAsync(CDPSession client, RequestWillBeSentPayload e, string fetchRequestId)
466466
{
467467
CdpHttpRequest request;
468468
var redirectChain = new List<IRequest>();
@@ -549,7 +549,7 @@ private void HandleRequestRedirect(CDPSession client, CdpHttpRequest request, Re
549549
RequestFinished?.Invoke(this, new RequestEventArgs(request));
550550
}
551551

552-
private async Task OnRequestWillBeSentAsync(CDPSession client, RequestWillBeSentResponse e)
552+
private async Task OnRequestWillBeSentAsync(CDPSession client, RequestWillBeSentPayload e)
553553
{
554554
// Request interception doesn't happen for data URLs with Network Service.
555555
if (_userRequestInterceptionEnabled && !e.Request.Url.StartsWith("data:", StringComparison.InvariantCultureIgnoreCase))
@@ -571,7 +571,7 @@ private async Task OnRequestWillBeSentAsync(CDPSession client, RequestWillBeSent
571571
await OnRequestAsync(client, e, null).ConfigureAwait(false);
572572
}
573573

574-
private void PatchRequestEventHeaders(RequestWillBeSentResponse requestWillBeSentEvent, FetchRequestPausedResponse requestPausedEvent)
574+
private void PatchRequestEventHeaders(RequestWillBeSentPayload requestWillBeSentEvent, FetchRequestPausedResponse requestPausedEvent)
575575
{
576576
foreach (var kv in requestPausedEvent.Request.Headers)
577577
{

0 commit comments

Comments
 (0)