Skip to content

Commit 2940e6f

Browse files
committed
[bidi][java] Allow pass browsing context to subscribe to an event
1 parent 32e38eb commit 2940e6f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

java/src/org/openqa/selenium/bidi/BiDi.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.Closeable;
2323
import java.time.Duration;
2424
import java.util.Collections;
25+
import java.util.List;
2526
import java.util.function.Consumer;
2627

2728
import org.openqa.selenium.internal.Require;
@@ -65,6 +66,30 @@ public <X> void addListener(Event<X> event, Consumer<X> handler) {
6566
connection.addListener(event, handler);
6667
}
6768

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+
6893
public <X> void clearListener(Event<X> event) {
6994
Require.nonNull("Event to listen for", event);
7095

0 commit comments

Comments
 (0)