-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[java][BiDi] add clearListners via browsingContextIds for inspectors #17376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Delta456
wants to merge
13
commits into
SeleniumHQ:trunk
Choose a base branch
from
Delta456:inspector_clear_listener
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
da1ed22
[java][BiDi] add clearListners via browsingContextIds for inspectors
Delta456 0a62208
Merge branch 'trunk' into inspector_clear_listener
Delta456 cf94c6b
style: wrap addSpeculationRulesAndLink params for formatting
Delta456 1cce9c7
Merge branch 'trunk' into inspector_clear_listener
Delta456 cabc46a
Merge branch 'trunk' into inspector_clear_listener
Delta456 339b9c7
Merge branch 'trunk' into inspector_clear_listener
Delta456 4b37637
refactor as per comments
Delta456 9010a8e
Merge branch 'trunk' into inspector_clear_listener
Delta456 fd14c68
Merge branch 'trunk' into inspector_clear_listener
Delta456 5d07026
Merge branch 'trunk' into inspector_clear_listener
VietND96 c8d258d
Merge branch 'trunk' into inspector_clear_listener
Delta456 63c4ff9
undo xml change
Delta456 c4c3bcb
undo xml change x2
Delta456 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,8 @@ | |
|
|
||
| import java.io.Closeable; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
@@ -34,6 +36,7 @@ public class BiDi implements Closeable { | |
|
|
||
| private final Duration timeout; | ||
| private final Connection connection; | ||
| private final Map<Event<?>, List<Long>> contextListenerIds = new HashMap<>(); | ||
|
|
||
| /** | ||
| * @deprecated Use constructor with timeout parameter: {@link #BiDi(Connection, Duration)} | ||
|
|
@@ -104,7 +107,7 @@ public <X> long addListener(String browsingContextId, Event<X> event, Consumer<X | |
| } | ||
|
|
||
| public <X> long addListener(Set<String> browsingContextIds, Event<X> event, Consumer<X> handler) { | ||
| Require.nonNull("List of browsing context ids", browsingContextIds); | ||
| Require.nonEmpty("List of browsing context ids", browsingContextIds); | ||
| Require.nonNull("Event to listen for", event); | ||
| Require.nonNull("Handler to call", handler); | ||
|
|
||
|
|
@@ -113,7 +116,9 @@ public <X> long addListener(Set<String> browsingContextIds, Event<X> event, Cons | |
| "session.subscribe", | ||
| Map.of("contexts", browsingContextIds, "events", List.of(event.getMethod())))); | ||
|
|
||
| return connection.addListener(event, handler); | ||
| long id = connection.addListener(event, handler); | ||
| contextListenerIds.computeIfAbsent(event, k -> new ArrayList<>()).add(id); | ||
| return id; | ||
| } | ||
|
|
||
| public <X> void clearListener(Event<X> event) { | ||
|
|
@@ -127,6 +132,32 @@ public <X> void clearListener(Event<X> event) { | |
| } | ||
| } | ||
|
|
||
| public <X> void clearListener(Set<String> browsingContextIds, Event<X> event) { | ||
| Require.nonEmpty("List of browsing context ids", browsingContextIds); | ||
| Require.nonNull("Event to listen for", event); | ||
|
|
||
| // The browser throws an error if we try to unsubscribe an event that was not subscribed in the | ||
| // first place | ||
| if (!connection.isEventSubscribed(event)) { | ||
| return; | ||
| } | ||
|
|
||
| List<Long> ids = contextListenerIds.remove(event); | ||
| if (ids != null && !ids.isEmpty()) { | ||
| // Subscription was context-specific: unsubscribe only for those contexts. | ||
| send( | ||
| new Command<>( | ||
| "session.unsubscribe", | ||
| Map.of("contexts", browsingContextIds, "events", List.of(event.getMethod())))); | ||
| ids.forEach(connection::removeListener); | ||
| } else { | ||
| // Subscription was global: context-specific unsubscription is invalid per the BiDi protocol, | ||
| // so fall back to a global unsubscription. | ||
| send(new Command<>("session.unsubscribe", Map.of("events", List.of(event.getMethod())))); | ||
| connection.clearListener(event); | ||
| } | ||
|
qodo-code-review[bot] marked this conversation as resolved.
Delta456 marked this conversation as resolved.
Comment on lines
+145
to
+158
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. String context clears globally BiDi.addListener(String, ...) performs a context-scoped session.subscribe but does not record the listener ID in contextListenerIds, so clearListener(Set, ...) will treat it as a global subscription and send a global session.unsubscribe, potentially removing subscriptions beyond the intended contexts. This can also clear all local callbacks for the event even though the caller asked for context-scoped cleanup. Agent Prompt
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair |
||
| } | ||
|
|
||
| public void removeListener(long id) { | ||
| connection.removeListener(id); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. contextlistenerids map not synchronized
📘 Rule violation☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation toolsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion