[bidi][java] Allow pass browsing context to subscribe to an event
import java.io.Closeable;
import java.time.Duration;
import java.util.Collections;
+import java.util.List;
import java.util.function.Consumer;
import org.openqa.selenium.internal.Require;
@@ -65,6 +66,30 @@ public void disconnectSession() {
connection.addListener(event, handler);
}
+ <X> void addListener(String browsingContextId, Event<X> event, Consumer<X> handler) {
+ Require.nonNull("Event to listen for", event);
+ Require.nonNull("Browsing context id", browsingContextId);
+ Require.nonNull("Handler to call", handler);
+
+ send(new Command<>("session.subscribe",
+ ImmutableMap.of("contexts", Collections.singletonList(browsingContextId),
+ "events", Collections.singletonList(event.getMethod()))));
+
+ connection.addListener(event, handler);
+ }
+
+ <X> void addListener(List<String> browsingContextIds, Event<X> event, Consumer<X> handler) {
+ Require.nonNull("List of browsing context ids", browsingContextIds);
+ Require.nonNull("Event to listen for", event);
+ Require.nonNull("Handler to call", handler);
+
+ send(new Command<>("session.subscribe",
+ ImmutableMap.of("contexts", Collections.singletonList(browsingContextIds),
+ "events", Collections.singletonList(event.getMethod()))));
+
+ connection.addListener(event, handler);
+ }
+
public <X> void clearListener(Event<X> event) {
Require.nonNull("Event to listen for", event);
