or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

events.mdindex.mdjavascript.mdlogging.mdnetwork.mdtarget.md

network.mddocs/

0

# Network Domain

1

2

Network domain implementation for HTTP request/response interception, authentication handling, and caching control. Provides comprehensive network monitoring capabilities for automated testing, API mocking, and performance analysis.

3

4

## Capabilities

5

6

### Network Interception

7

8

Enable and disable request/response interception for all network patterns, allowing modification of HTTP traffic in real-time.

9

10

```java { .api }

11

public Command<Void> enableFetchForAllPatterns();

12

public Command<Void> disableFetch();

13

```

14

15

Usage example:

16

```java

17

v111Network network = domains.network();

18

19

// Enable interception for all requests

20

devTools.send(network.enableFetchForAllPatterns());

21

22

// Listen for paused requests

23

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

24

// Handle intercepted request

25

if (pausedRequest.getRequest().getUrl().contains("/api/")) {

26

// Modify API requests

27

HttpRequest modifiedRequest = createModifiedRequest(pausedRequest);

28

devTools.send(network.continueRequest(pausedRequest, modifiedRequest));

29

} else {

30

// Continue without modification

31

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

32

}

33

});

34

```

35

36

### Authentication Handling

37

38

Handle HTTP authentication challenges with credential provision or cancellation.

39

40

```java { .api }

41

public Event<AuthRequired> authRequiredEvent();

42

public String getUriFrom(AuthRequired authRequired);

43

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

44

public Command<Void> cancelAuth(AuthRequired authRequired);

45

```

46

47

Usage example:

48

```java

49

// Listen for authentication challenges

50

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

51

String uri = network.getUriFrom(authRequired);

52

53

if (uri.contains("secure-api.example.com")) {

54

// Provide credentials

55

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

56

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

57

} else {

58

// Cancel authentication

59

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

60

}

61

});

62

```

63

64

### Request/Response Management

65

66

Handle intercepted requests and responses with modification capabilities.

67

68

```java { .api }

69

public Event<RequestPaused> requestPausedEvent();

70

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

71

public String getRequestId(RequestPaused pausedReq);

72

public Command<Void> continueWithoutModification(RequestPaused pausedRequest);

73

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

74

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

75

```

76

77

Usage example:

78

```java

79

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

80

Either<HttpRequest, HttpResponse> message = network.createSeMessages(pausedRequest);

81

82

if (message.isLeft()) {

83

// Handle request

84

HttpRequest request = message.left();

85

if (request.getUri().contains("/block-me")) {

86

// Block request with 404 response

87

HttpResponse blockedResponse = new HttpResponse()

88

.setStatus(404)

89

.setContent(Contents.utf8String("Blocked"));

90

devTools.send(network.fulfillRequest(pausedRequest, blockedResponse));

91

} else {

92

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

93

}

94

} else {

95

// Handle response

96

HttpResponse response = message.right();

97

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

98

}

99

});

100

```

101

102

### User Agent Management

103

104

Override browser user agent string with custom values.

105

106

```java { .api }

107

public Command<Void> setUserAgentOverride(UserAgent userAgent);

108

```

109

110

Usage example:

111

```java

112

UserAgent customUA = new UserAgent(

113

"CustomBot/1.0 (Testing)",

114

"en-US,en;q=0.9",

115

"CustomPlatform"

116

);

117

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

118

```

119

120

### Caching Control

121

122

Enable or disable network caching for testing scenarios.

123

124

```java { .api }

125

public Command<Void> enableNetworkCaching();

126

public Command<Void> disableNetworkCaching();

127

```

128

129

Usage example:

130

```java

131

// Disable caching for testing

132

devTools.send(network.disableNetworkCaching());

133

134

// Re-enable caching

135

devTools.send(network.enableNetworkCaching());

136

```

137

138

## Types

139

140

### Network Events

141

142

```java { .api }

143

class AuthRequired {

144

public AuthChallenge getAuthChallenge();

145

public RequestId getRequestId();

146

}

147

148

class RequestPaused {

149

public RequestId getRequestId();

150

public Request getRequest();

151

public Optional<Integer> getResponseStatusCode();

152

public Optional<String> getResponseErrorReason();

153

public Optional<List<HeaderEntry>> getResponseHeaders();

154

}

155

```

156

157

### HTTP Types

158

159

```java { .api }

160

class UserAgent {

161

public UserAgent(String userAgent, String acceptLanguage, String platform);

162

public String userAgent();

163

public String acceptLanguage();

164

public String platform();

165

}

166

167

class UsernameAndPassword {

168

public UsernameAndPassword(String username, String password);

169

public String username();

170

public String password();

171

}

172

```

173

174

### Request/Response Types

175

176

```java { .api }

177

class HttpRequest {

178

public String getMethod();

179

public String getUri();

180

public Iterable<String> getHeaderNames();

181

public Iterable<String> getHeaders(String name);

182

public Supplier<InputStream> getContent();

183

}

184

185

class HttpResponse {

186

public int getStatus();

187

public Iterable<String> getHeaderNames();

188

public Iterable<String> getHeaders(String name);

189

public Supplier<InputStream> getContent();

190

}

191

```