1
+ // <copyright file="RemoteNetwork.cs" company="WebDriver Committers">
2
+ // Licensed to the Software Freedom Conservancy (SFC) under one
3
+ // or more contributor license agreements. See the NOTICE file
4
+ // distributed with this work for additional information
5
+ // regarding copyright ownership. The SFC licenses this file
6
+ // to you under the Apache License, Version 2.0 (the "License");
7
+ // you may not use this file except in compliance with the License.
8
+ // You may obtain a copy of the License at
9
+ //
10
+ // http://www.apache.org/licenses/LICENSE-2.0
11
+ //
12
+ // Unless required by applicable law or agreed to in writing, software
13
+ // distributed under the License is distributed on an "AS IS" BASIS,
14
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ // See the License for the specific language governing permissions and
16
+ // limitations under the License.
17
+ // </copyright>
18
+
1
19
using System ;
2
20
using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
21
using System . Threading . Tasks ;
6
22
using OpenQA . Selenium . DevTools ;
7
23
8
24
namespace OpenQA . Selenium . Remote
9
25
{
26
+ /// <summary>
27
+ /// Provides methods for monitoring, intercepting, and modifying network requests and responses.
28
+ /// </summary>
10
29
public class RemoteNetwork : INetwork
11
30
{
12
31
private Lazy < DevToolsSession > session ;
13
32
private List < NetworkRequestHandler > requestHandlers = new List < NetworkRequestHandler > ( ) ;
14
33
private List < NetworkAuthenticationHandler > authenticationHandlers = new List < NetworkAuthenticationHandler > ( ) ;
15
34
35
+ /// <summary>
36
+ /// Initializes a new instance of the <see cref="RemoteNetwork"/> class.
37
+ /// </summary>
38
+ /// <param name="driver">The <see cref="IWebDriver"/> instance on which the network should be monitored.</param>
16
39
public RemoteNetwork ( IWebDriver driver )
17
40
{
18
41
// Use of Lazy<T> means this exception won't be thrown until the user first
@@ -30,9 +53,20 @@ public RemoteNetwork(IWebDriver driver)
30
53
} ) ;
31
54
}
32
55
33
- public event EventHandler < NetworkResponseRecievedEventArgs > NetworkResponseReceived ;
56
+ /// <summary>
57
+ /// Occurs when a browser sends a network request.
58
+ /// </summary>
34
59
public event EventHandler < NetworkRequestSentEventArgs > NetworkRequestSent ;
35
60
61
+ /// <summary>
62
+ /// Occurs when a browser receives a network response.
63
+ /// </summary>
64
+ public event EventHandler < NetworkResponseRecievedEventArgs > NetworkResponseReceived ;
65
+
66
+ /// <summary>
67
+ /// Asynchronously starts monitoring for network traffic.
68
+ /// </summary>
69
+ /// <returns>A task that represents the asynchronous operation.</returns>
36
70
public async Task StartMonitoring ( )
37
71
{
38
72
this . session . Value . Domains . Network . RequestPaused += OnRequestPaused ;
@@ -43,6 +77,10 @@ public async Task StartMonitoring()
43
77
await this . session . Value . Domains . Network . DisableNetworkCaching ( ) ;
44
78
}
45
79
80
+ /// <summary>
81
+ /// Asynchronously stops monitoring for network traffic.
82
+ /// </summary>
83
+ /// <returns>A task that represents the asynchronous operation.</returns>
46
84
public async Task StopMonitoring ( )
47
85
{
48
86
this . session . Value . Domains . Network . ResponsePaused -= OnResponsePaused ;
@@ -51,6 +89,11 @@ public async Task StopMonitoring()
51
89
await this . session . Value . Domains . Network . EnableNetworkCaching ( ) ;
52
90
}
53
91
92
+ /// <summary>
93
+ /// Adds a <see cref="NetworkRequestHandler"/> to examine incoming network requests,
94
+ /// and optionally modify the request or provide a response.
95
+ /// </summary>
96
+ /// <param name="handler">The <see cref="NetworkRequestHandler"/> to add.</param>
54
97
public void AddRequestHandler ( NetworkRequestHandler handler )
55
98
{
56
99
if ( handler == null )
@@ -71,11 +114,19 @@ public void AddRequestHandler(NetworkRequestHandler handler)
71
114
this . requestHandlers . Add ( handler ) ;
72
115
}
73
116
117
+ /// <summary>
118
+ /// Clears all added <see cref="NetworkRequestHandler"/> instances.
119
+ /// </summary>
74
120
public void ClearRequestHandlers ( )
75
121
{
76
122
this . requestHandlers . Clear ( ) ;
77
123
}
78
124
125
+ /// <summary>
126
+ /// Adds a <see cref="NetworkAuthenticationHandler"/> to supply authentication
127
+ /// credentials for network requests.
128
+ /// </summary>
129
+ /// <param name="handler">The <see cref="NetworkAuthenticationHandler"/> to add.</param>
79
130
public void AddAuthenticationHandler ( NetworkAuthenticationHandler handler )
80
131
{
81
132
if ( handler == null )
@@ -102,6 +153,9 @@ public void AddAuthenticationHandler(NetworkAuthenticationHandler handler)
102
153
this . authenticationHandlers . Add ( handler ) ;
103
154
}
104
155
156
+ /// <summary>
157
+ /// Clears all added <see cref="NetworkAuthenticationHandler"/> instances.
158
+ /// </summary>
105
159
public void ClearAuthenticationHandlers ( )
106
160
{
107
161
this . authenticationHandlers . Clear ( ) ;
0 commit comments