|
22 | 22 | import java.io.Closeable; |
23 | 23 | import java.time.Duration; |
24 | 24 | import java.util.Collections; |
| 25 | +import java.util.List; |
25 | 26 | import java.util.function.Consumer; |
26 | 27 |
|
27 | 28 | import org.openqa.selenium.internal.Require; |
@@ -65,6 +66,30 @@ public <X> void addListener(Event<X> event, Consumer<X> handler) { |
65 | 66 | connection.addListener(event, handler); |
66 | 67 | } |
67 | 68 |
|
| 69 | + <X> void addListener(String browsingContextId, Event<X> event, Consumer<X> handler) { |
| 70 | + Require.nonNull("Event to listen for", event); |
| 71 | + Require.nonNull("Browsing context id", browsingContextId); |
| 72 | + Require.nonNull("Handler to call", handler); |
| 73 | + |
| 74 | + send(new Command<>("session.subscribe", |
| 75 | + ImmutableMap.of("contexts", Collections.singletonList(browsingContextId), |
| 76 | + "events", Collections.singletonList(event.getMethod())))); |
| 77 | + |
| 78 | + connection.addListener(event, handler); |
| 79 | + } |
| 80 | + |
| 81 | + <X> void addListener(List<String> browsingContextIds, Event<X> event, Consumer<X> handler) { |
| 82 | + Require.nonNull("List of browsing context ids", browsingContextIds); |
| 83 | + Require.nonNull("Event to listen for", event); |
| 84 | + Require.nonNull("Handler to call", handler); |
| 85 | + |
| 86 | + send(new Command<>("session.subscribe", |
| 87 | + ImmutableMap.of("contexts", Collections.singletonList(browsingContextIds), |
| 88 | + "events", Collections.singletonList(event.getMethod())))); |
| 89 | + |
| 90 | + connection.addListener(event, handler); |
| 91 | + } |
| 92 | + |
68 | 93 | public <X> void clearListener(Event<X> event) { |
69 | 94 | Require.nonNull("Event to listen for", event); |
70 | 95 |
|
|
0 commit comments