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
This file contains 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
Error Handling The method removeCallback throws an error if the callback ID is not found. It might be beneficial to handle this scenario more gracefully, perhaps by logging a warning instead of throwing, to prevent potential disruptions in the application flow.
Callback ID Increment The addCallback method increments the #callbackId directly. Consider using a more robust ID generation strategy to avoid potential issues with ID conflicts or limits in long-running applications.
Add error handling for unsupported event types in callback management
Add error handling for the get method calls on this.#listener to ensure that the event type exists before attempting to manipulate the callback map, preventing runtime errors.
const eventCallbackMap = this.#listener.get(eventType)
+if (!eventCallbackMap) {+ throw new Error(`Event type ${eventType} is not supported.`);+}
Apply this suggestion
Suggestion importance[1-10]: 8
Why: Adding error handling for unsupported event types is a significant improvement that prevents potential runtime errors, enhancing the robustness of the code.
8
Provide feedback on callback removal success
Modify the removeCallback method to return a boolean indicating whether the callback was successfully removed, providing clearer feedback to the caller.
-if (!hasId) {- throw Error(`Callback with id ${id} not found`)-}+return hasId
Apply this suggestion
Suggestion importance[1-10]: 6
Why: Modifying the removeCallback method to return a boolean indicating success provides clearer feedback to the caller, improving usability. However, the current exception handling already provides a clear indication of failure.
6
Possible bug
Ensure the event type is specified before invoking callbacks
Implement a check to ensure that the eventType parameter in invokeCallbacks method is not undefined or null before proceeding with invoking callbacks, to prevent potential runtime errors.
+if (!eventType) {+ throw new Error('Event type must be specified.');+}
const callbacks = this.#listener.get(eventType)
Apply this suggestion
Suggestion importance[1-10]: 7
Why: Implementing a check to ensure the event type is specified before invoking callbacks helps prevent potential runtime errors, improving code reliability. However, the likelihood of eventType being undefined or null might be low.
7
Possible issue
Improve the reliability of the callback ID increment operation
Replace the increment operation inside the addCallback method with a safer approach using this.#callbackId += 1 to avoid potential issues with the ++ operator when used in more complex expressions.
-const id = ++this.#callbackId+const id = this.#callbackId += 1
Apply this suggestion
Suggestion importance[1-10]: 5
Why: The suggestion improves the reliability of the callback ID increment operation by using a more explicit and safer approach. However, the original code is not necessarily problematic, so the improvement is minor.
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.
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Related to #13993
Motivation and Context
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
NetworkEvent
constants and private fields#callbackId
and#listener
to theNetwork
class.Network
class.Network
class to manage network intercepts and authentication handlers.Network
class intoWebDriver
and added anetwork
method for accessing network functionalities.Changes walkthrough 📝
network.js
Add callback handling and event subscription enhancements in Network
class
javascript/node/selenium-webdriver/bidi/network.js
NetworkEvent
constants.#callbackId
and#listener
.network.js
Introduce Network class for managing network intercepts and
authentication
javascript/node/selenium-webdriver/lib/network.js
Network
class to manage network intercepts and authenticationhandlers.
webdriver.js
Integrate Network class into WebDriver for network functionalities
javascript/node/selenium-webdriver/lib/webdriver.js
Network
class intoWebDriver
.network
method toWebDriver
for accessing networkfunctionalities.
network_commands_test.js
Update network command tests to handle multiple callback invocations
javascript/node/selenium-webdriver/test/bidi/network_commands_test.js
webdriver_network_test.js
Add tests for WebDriver network authentication handlers
javascript/node/selenium-webdriver/test/lib/webdriver_network_test.js