or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

domains.mdevents.mdindex.mdjavascript.mdlogging.mdnetwork.mdtarget.md

network.mddocs/

0

# Network Operations

1

2

The v129Network class provides comprehensive network interception and monitoring capabilities through the Chrome DevTools Protocol. It enables request/response manipulation, authentication handling, user agent overrides, and traffic analysis.

3

4

## Capabilities

5

6

### Network Domain

7

8

Core network domain providing request/response interception and monitoring.

9

10

```java { .api }

11

/**

12

* Network domain providing request/response interception and monitoring

13

* @param devTools - DevTools instance for protocol communication

14

*/

15

public class v129Network extends Network<AuthRequired, RequestPaused> {

16

public v129Network(DevTools devTools);

17

18

/** Event fired when a request is paused for interception */

19

public Event<RequestPaused> requestPausedEvent();

20

21

/** Converts paused request to HttpRequest or HttpResponse */

22

public Either<HttpRequest, HttpResponse> createSeMessages(RequestPaused pausedReq);

23

}

24

```

25

26

### User Agent Override

27

28

Set custom user agent strings for network requests.

29

30

```java { .api }

31

/**

32

* Sets user agent override for all network requests

33

* @param userAgent - UserAgent object containing user agent string and optional properties

34

* @return Command to execute the user agent override

35

*/

36

protected Command<Void> setUserAgentOverride(UserAgent userAgent);

37

```

38

39

### Network Caching Control

40

41

Enable or disable network caching for requests.

42

43

```java { .api }

44

/**

45

* Enables network caching for requests

46

* @return Command to enable network caching

47

*/

48

protected Command<Void> enableNetworkCaching();

49

50

/**

51

* Disables network caching for requests

52

* @return Command to disable network caching

53

*/

54

protected Command<Void> disableNetworkCaching();

55

```

56

57

### Request Interception

58

59

Enable fetch interception to modify requests and responses.

60

61

```java { .api }

62

/**

63

* Enables fetch interception for all request and response patterns

64

* @return Command to enable fetch interception

65

*/

66

protected Command<Void> enableFetchForAllPatterns();

67

68

/**

69

* Disables fetch interception

70

* @return Command to disable fetch interception

71

*/

72

protected Command<Void> disableFetch();

73

```

74

75

### Authentication Handling

76

77

Handle HTTP authentication challenges.

78

79

```java { .api }

80

/**

81

* Event fired when authentication is required

82

* @return Event for authentication required notifications

83

*/

84

protected Event<AuthRequired> authRequiredEvent();

85

86

/**

87

* Extracts URI from authentication required event

88

* @param authRequired - Authentication required event

89

* @return URI string requiring authentication

90

*/

91

protected String getUriFrom(AuthRequired authRequired);

92

93

/**

94

* Continues request with provided authentication credentials

95

* @param authRequired - Authentication required event

96

* @param credentials - Username and password credentials

97

* @return Command to continue with authentication

98

*/

99

protected Command<Void> continueWithAuth(AuthRequired authRequired, UsernameAndPassword credentials);

100

101

/**

102

* Cancels authentication for the request

103

* @param authRequired - Authentication required event

104

* @return Command to cancel authentication

105

*/

106

protected Command<Void> cancelAuth(AuthRequired authRequired);

107

```

108

109

### Request Management

110

111

Manage paused requests during interception.

112

113

```java { .api }

114

/**

115

* Checks if paused request has an error response

116

* @param pausedReq - Paused request event

117

* @return true if request has error response

118

*/

119

protected boolean hasErrorResponse(RequestPaused pausedReq);

120

121

/**

122

* Gets request ID from paused request

123

* @param pausedReq - Paused request event

124

* @return Request ID string

125

*/

126

protected String getRequestId(RequestPaused pausedReq);

127

128

/**

129

* Continues request without modification

130

* @param pausedRequest - Paused request event

131

* @return Command to continue request unmodified

132

*/

133

protected Command<Void> continueWithoutModification(RequestPaused pausedRequest);

134

135

/**

136

* Continues request with modifications

137

* @param pausedReq - Paused request event

138

* @param req - Modified HttpRequest

139

* @return Command to continue with modified request

140

*/

141

protected Command<Void> continueRequest(RequestPaused pausedReq, HttpRequest req);

142

143

/**

144

* Fulfills request with custom response

145

* @param pausedReq - Paused request event

146

* @param res - HttpResponse to fulfill request with

147

* @return Command to fulfill request with response

148

*/

149

protected Command<Void> fulfillRequest(RequestPaused pausedReq, HttpResponse res);

150

```

151

152

**Usage Examples:**

153

154

```java

155

import org.openqa.selenium.devtools.v129.v129Network;

156

import org.openqa.selenium.devtools.DevTools;

157

import org.openqa.selenium.UsernameAndPassword;

158

159

// Create network domain

160

DevTools devTools = driver.getDevTools();

161

v129Network network = new v129Network(devTools);

162

163

// Enable request interception

164

devTools.send(network.enableFetchForAllPatterns());

165

166

// Listen for paused requests

167

devTools.addListener(network.requestPausedEvent(), pausedReq -> {

168

if (network.hasErrorResponse(pausedReq)) {

169

// Handle error response

170

return;

171

}

172

173

// Continue request without modification

174

devTools.send(network.continueWithoutModification(pausedReq));

175

});

176

177

// Handle authentication

178

devTools.addListener(network.authRequiredEvent(), authReq -> {

179

String uri = network.getUriFrom(authReq);

180

if (uri.contains("secure-site.com")) {

181

// Provide credentials

182

UsernameAndPassword creds = new UsernameAndPassword("user", "pass");

183

devTools.send(network.continueWithAuth(authReq, creds));

184

} else {

185

// Cancel authentication

186

devTools.send(network.cancelAuth(authReq));

187

}

188

});

189

190

// Set user agent

191

UserAgent customAgent = new UserAgent(

192

"Mozilla/5.0 (Custom Browser)",

193

Optional.of("en-US"),

194

Optional.of("Linux")

195

);

196

devTools.send(network.setUserAgentOverride(customAgent));

197

```

198

199

## Types

200

201

### Network Event Types

202

203

```java { .api }

204

// From v129.fetch.model package

205

import org.openqa.selenium.devtools.v129.fetch.model.AuthRequired;

206

import org.openqa.selenium.devtools.v129.fetch.model.RequestPaused;

207

import org.openqa.selenium.devtools.v129.fetch.model.AuthChallengeResponse;

208

import org.openqa.selenium.devtools.v129.fetch.model.RequestPattern;

209

import org.openqa.selenium.devtools.v129.fetch.model.RequestStage;

210

211

// Network request/response types

212

import org.openqa.selenium.devtools.v129.network.model.Request;

213

import org.openqa.selenium.remote.http.HttpRequest;

214

import org.openqa.selenium.remote.http.HttpResponse;

215

```

216

217

### Authentication Types

218

219

```java { .api }

220

import org.openqa.selenium.UsernameAndPassword;

221

222

// Authentication challenge response

223

class AuthChallengeResponse {

224

public enum Response {

225

PROVIDECREDENTIALS,

226

CANCELAUTH,

227

DEFAULT

228

}

229

230

public AuthChallengeResponse(

231

Response response,

232

Optional<String> username,

233

Optional<String> password

234

);

235

}

236

```

237

238

### User Agent Types

239

240

```java { .api }

241

class UserAgent {

242

public UserAgent(

243

String userAgent,

244

Optional<String> acceptLanguage,

245

Optional<String> platform

246

);

247

248

public String userAgent();

249

public Optional<String> acceptLanguage();

250

public Optional<String> platform();

251

}

252

```