You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add scoped BiDi event subscriptions via SubscriptionScope
✨ Enhancement🕐 10-20 Minutes
AI Description
• Introduce a SubscriptionScope transport type to carry context/user-context subscription scoping.
• Add new subscribe/listener overloads to pass scoping parameters into session.subscribe.
• Keep subscription parameter construction outside generated types to avoid generator coupling.
➖ Blocks progress until generator output and packaging are finalized
3. Make SubscriptionScope immutable (builder or value type)
➕ Safer to share across threads and easier to reason about
➕ Enables simple equality/testing and future validation hooks
➖ More boilerplate now; may slow iteration while the generator work is in flight
Recommendation: The current approach (a small, transport-layer SubscriptionScope passed through new overloads) is a good precursor to CDDL generation: it keeps subscription-shaping capability without binding the API to generated parameter classes. If this becomes widely used, consider evolving SubscriptionScope toward an immutable value type and adding light validation/documentation of supported key combinations.
Files changed (4) +78 / -0
Enhancement (4) +78 / -0
BiDi.javaAdd scoped addListener overload that merges SubscriptionScope into subscribe params+13/-0
Add scoped addListener overload that merges SubscriptionScope into subscribe params
• Introduces a package-private addListener overload that accepts a SubscriptionScope, merges its map into the session.subscribe parameters, and subscribes to the event. Uses a mutable params map to combine scope keys with the required "events" field.
Handle.javaExpose scoped subscribe overload for package-internal module usage+4/-0
Expose scoped subscribe overload for package-internal module usage
• Adds a new subscribe overload that forwards event/handler/scope to BiDi, enabling modules to request scoped subscriptions without accessing BiDi directly.
• Extends the base Module API with a protected subscribe method that takes a SubscriptionScope, allowing generated modules to pass scoping information through the Handle.
SubscriptionScope.javaIntroduce SubscriptionScope to model contexts and userContexts scoping+56/-0
Introduce SubscriptionScope to model contexts and userContexts scoping
• Adds a new @Beta transport-layer type with fluent setters for browsing contexts and user contexts. Provides toMap() that emits only non-empty parameters to be merged into session.subscribe.
The new public API methods contexts(...) and userContexts(...) in SubscriptionScope lack
Javadoc, which makes the new API harder to understand and violates the requirement for complete
public method documentation (including tags).
Rule 330200/330201 requires Javadoc for all public API methods and complete tags. In
SubscriptionScope, the public methods contexts(Set<String> contexts) and
userContexts(Set<String> userContexts) have no preceding Javadoc blocks.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
`SubscriptionScope` introduces new public methods but they have no Javadoc. This violates the project requirement to document public API methods and include complete tags.
## Issue Context
`SubscriptionScope` is `public` and annotated `@Beta`, so it is part of the user-visible Java API surface and should be documented.
## Fix Focus Areas
- java/src/org/openqa/selenium/bidi/SubscriptionScope.java[36-44]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
2. Scoped subscribe has no tests 📘 Rule violation▣ Testability
Description
New subscription-scoping functionality was added (via SubscriptionScope and the new scoped
addListener/subscribe overloads), but no corresponding tests were added or updated to exercise
the new behavior.
Rule 389273 requires tests for new functionality. The PR adds a new scoped listener/subscription
path in BiDi.addListener(..., SubscriptionScope) and introduces SubscriptionScope map-building
logic, but there are no accompanying test changes covering these new code paths.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The PR adds new functionality for subscription scoping but does not add test coverage to ensure scoped subscriptions are correctly translated into `session.subscribe` parameters.
## Issue Context
This change adds a new API surface (`SubscriptionScope`) and a new subscription path that builds a params map from scope + events.
## Fix Focus Areas
- java/src/org/openqa/selenium/bidi/BiDi.java[120-130]
- java/src/org/openqa/selenium/bidi/SubscriptionScope.java[46-55]
- java/test/org/openqa/selenium/bidi/BiDiTest.java[37-67]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
SubscriptionScope stores caller-provided Set instances and places them directly into the
session.subscribe params map. If those sets are mutated concurrently with JSON serialization,
JsonOutput’s Collection iteration may throw ConcurrentModificationException (or serialize
inconsistent data), causing subscription setup to fail.
SubscriptionScope forwards the stored sets into the params map; Connection.send serializes the
params directly, and JsonOutput handles Collection values by streaming over them, which is
susceptible to concurrent modification of non-thread-safe sets.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
### Issue description
`SubscriptionScope` keeps direct references to the caller’s `Set<String>` instances (`contexts`, `userContexts`) and returns them via `toMap()`. Those sets are later serialized by `Connection.send()` using `JsonOutput`, which iterates `Collection` values; if a caller mutates a non-thread-safe set concurrently, serialization can throw or produce inconsistent output.
### Issue Context
This is primarily an API-ownership / thread-safety hardening issue: callers can pass mutable sets (e.g., `HashSet`) and reuse them across threads while subscribing.
### Fix Focus Areas
- java/src/org/openqa/selenium/bidi/SubscriptionScope.java[33-54]
### Suggested fix
- Snapshot inputs in the setters, e.g. `this.contexts = Set.copyOf(contexts);` and `this.userContexts = Set.copyOf(userContexts);`.
- (Optional) If you want to preserve insertion order for JSON output, consider copying to `List.copyOf(...)` in `toMap()` instead of returning a `Set`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
The new Java API adds userContexts scoping support, but other bindings appear to differ (some
support only contexts), and the change is not documented as an intentional cross-binding
divergence.
+/**+ * Where a subscription applies: globally, or scoped to browsing contexts and/or user contexts. Part+ * of the transport layer, not generated — the remote end decides which combinations are valid.+ */+@Beta+public final class SubscriptionScope {++ private Set<String> contexts = Set.of();+ private Set<String> userContexts = Set.of();++ public SubscriptionScope contexts(Set<String> contexts) {+ this.contexts = Require.nonNull("Browsing context ids", contexts);+ return this;+ }++ public SubscriptionScope userContexts(Set<String> userContexts) {+ this.userContexts = Require.nonNull("User context ids", userContexts);+ return this;+ }
Evidence
Rule 389265 requires comparing cross-language bindings when changing user-visible behavior. Java now
exposes scoping via SubscriptionScope including userContexts, while the JavaScript and .NET
bindings’ subscribe APIs shown here only expose context scoping; Ruby exposes both, indicating
potential cross-binding inconsistency that should be explicitly checked and documented.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
This PR changes user-visible BiDi subscription scoping behavior in the Java binding, but there is no nearby documentation explaining how this aligns (or intentionally diverges) from other language bindings.
## Issue Context
Other bindings implement `session.subscribe` with varying support for `contexts` and `userContexts`. The Java binding now exposes both via `SubscriptionScope`.
## Fix Focus Areas
- java/src/org/openqa/selenium/bidi/SubscriptionScope.java[26-44]
- java/src/org/openqa/selenium/bidi/BiDi.java[120-130]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
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
B-devtoolsIncludes everything BiDi or Chrome DevTools relatedC-javaJava Bindings
2 participants
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.
🔗 Related Issues
💥 What does this PR do?
It add a method that is extensible in future to allow passing subscription parameters for events related to BiDi.
🔧 Implementation Notes
Using the generated SubscriptionParameters is not ideal and would create circular dependency.
This change is precursor to the CDDL generator work.
🤖 AI assistance
💡 Additional Considerations
🔄 Types of changes