or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

events.mdindex.mdjavascript.mdlogging.mdnetwork.mdtargets.md

events.mddocs/

0

# Event Handling

1

2

The v133Events class provides comprehensive runtime event monitoring capabilities, enabling developers to listen for console API calls, JavaScript exceptions, and other runtime events in the browser.

3

4

## Capabilities

5

6

### v133Events Class

7

8

Main event handling class that extends the base Events functionality with v133-specific implementations.

9

10

```java { .api }

11

/**

12

* v133-specific event handling implementation

13

* Extends Events<ConsoleAPICalled, ExceptionThrown> for type-safe event processing

14

*/

15

public class v133Events extends Events<ConsoleAPICalled, ExceptionThrown> {

16

/**

17

* Creates a new v133Events instance

18

* @param devtools DevTools instance for communication with browser

19

*/

20

public v133Events(DevTools devtools);

21

}

22

```

23

24

### Runtime Control

25

26

Methods for enabling and disabling runtime event monitoring.

27

28

```java { .api }

29

/**

30

* Enable runtime domain for event monitoring

31

* Implementation delegates to Runtime.enable()

32

* @return Command to enable runtime events

33

*/

34

protected Command<Void> enableRuntime();

35

36

/**

37

* Disable runtime domain to stop event monitoring

38

* Implementation delegates to Runtime.disable()

39

* @return Command to disable runtime events

40

*/

41

protected Command<Void> disableRuntime();

42

```

43

44

### Console Event Monitoring

45

46

Monitor console API calls such as console.log(), console.error(), console.warn(), etc.

47

48

```java { .api }

49

/**

50

* Get the console API called event

51

* Implementation delegates to Runtime.consoleAPICalled()

52

* @return Event for monitoring console API calls

53

*/

54

protected Event<ConsoleAPICalled> consoleEvent();

55

56

/**

57

* Convert CDP console event to Selenium ConsoleEvent

58

* Handles timestamp conversion and remote object processing

59

* @param event CDP ConsoleAPICalled event

60

* @return Selenium ConsoleEvent with timestamp and arguments

61

*/

62

protected ConsoleEvent toConsoleEvent(ConsoleAPICalled event);

63

```

64

65

**Usage Example:**

66

67

```java

68

import org.openqa.selenium.devtools.v133.v133Events;

69

import org.openqa.selenium.devtools.events.ConsoleEvent;

70

import org.openqa.selenium.devtools.v133.runtime.model.ConsoleAPICalled;

71

72

v133Events events = new v133Events(devTools);

73

74

// Listen for console events

75

devTools.addListener(events.consoleEvent(), (ConsoleAPICalled event) -> {

76

ConsoleEvent consoleEvent = events.toConsoleEvent(event);

77

System.out.println("Console: " + consoleEvent.getType() +

78

" - " + consoleEvent.getMessages());

79

});

80

81

// Enable runtime to start receiving events

82

devTools.send(events.enableRuntime());

83

```

84

85

### JavaScript Exception Handling

86

87

Monitor and process JavaScript exceptions with detailed stack traces and error information.

88

89

```java { .api }

90

/**

91

* Get the JavaScript exception thrown event

92

* @return Event for monitoring JavaScript exceptions

93

*/

94

protected Event<ExceptionThrown> exceptionThrownEvent();

95

96

/**

97

* Convert CDP exception event to Selenium JavascriptException

98

* @param event CDP ExceptionThrown event

99

* @return JavascriptException with message and stack trace

100

*/

101

protected JavascriptException toJsException(ExceptionThrown event);

102

```

103

104

**Usage Example:**

105

106

```java

107

import org.openqa.selenium.JavascriptException;

108

import org.openqa.selenium.devtools.v133.runtime.model.ExceptionThrown;

109

110

// Listen for JavaScript exceptions

111

devTools.addListener(events.exceptionThrownEvent(), (ExceptionThrown event) -> {

112

JavascriptException jsException = events.toJsException(event);

113

System.err.println("JavaScript Error: " + jsException.getMessage());

114

jsException.printStackTrace();

115

});

116

```

117

118

## Event Data Types

119

120

### ConsoleAPICalled

121

122

Represents a console API call event from the browser runtime.

123

124

```java { .api }

125

// From org.openqa.selenium.devtools.v133.runtime.model.ConsoleAPICalled

126

public class ConsoleAPICalled {

127

public String getType(); // Type of console call (log, error, warn, etc.)

128

public List<RemoteObject> getArgs(); // Arguments passed to console method

129

public Timestamp getTimestamp(); // When the console call occurred

130

}

131

```

132

133

### ExceptionThrown

134

135

Represents a JavaScript exception event with detailed error information.

136

137

```java { .api }

138

// From org.openqa.selenium.devtools.v133.runtime.model.ExceptionThrown

139

public class ExceptionThrown {

140

public ExceptionDetails getExceptionDetails(); // Detailed exception information

141

}

142

143

public class ExceptionDetails {

144

public String getText(); // Exception message text

145

public Integer getLineNumber(); // Line number where exception occurred

146

public Optional<String> getUrl(); // URL of script where exception occurred

147

public Optional<StackTrace> getStackTrace(); // JavaScript stack trace

148

public Optional<RemoteObject> getException(); // Exception object details

149

}

150

```

151

152

### Selenium Event Wrappers

153

154

The v133Events class converts CDP events to Selenium's standard event types:

155

156

```java { .api }

157

// From org.openqa.selenium.devtools.events.ConsoleEvent

158

public class ConsoleEvent {

159

public ConsoleEvent(String type, Instant timestamp, List<Object> messages, List<RemoteObject> originalArgs);

160

public String getType();

161

public Instant getTimestamp();

162

public List<Object> getMessages();

163

}

164

165

// From org.openqa.selenium.JavascriptException

166

public class JavascriptException extends RuntimeException {

167

public JavascriptException(String message);

168

public void setStackTrace(StackTraceElement[] stackTrace);

169

}

170

```

171

172

## Error Handling

173

174

The event system includes robust error handling for various scenarios:

175

176

- **Missing Stack Traces**: When stack trace information is unavailable, creates placeholder stack elements

177

- **Timestamp Parsing**: Handles timestamp conversion from CDP format to Java time types

178

- **Message Extraction**: Safely extracts error messages from exception details with fallbacks

179

180

## Integration with Base Events

181

182

The v133Events class integrates seamlessly with Selenium's base Events infrastructure, providing:

183

184

- Type-safe event parameter mapping

185

- Consistent event listener interfaces

186

- Standardized error handling patterns

187

- Cross-domain event coordination