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 removeCallback method in logInspector.js now throws an error if the callback ID is not found. Ensure that all calling code properly handles this exception.
Initialization Pattern: The #init method in Script class uses a pattern that might be confusing as it mixes async initialization with regular constructor usage. Consider documenting this pattern clearly or revising the approach to initialization.
Return early after deleting the callback to simplify the code
Instead of using a let variable to track if the callback ID was found, you can return early once the callback is deleted. This will make the code more concise and potentially more efficient.
-let hasId = false
for (const [, callbacks] of this.listener) {
if (callbacks.has(id)) {
callbacks.delete(id)
- hasId = true+ return
}
}
-if (!hasId) {- throw Error(`Callback with id ${id} not found`)-}+throw Error(`Callback with id ${id} not found`)
Apply this suggestion
Suggestion importance[1-10]: 8
Why: The suggestion correctly identifies an opportunity to simplify the code by using an early return instead of a flag variable. This change enhances readability and efficiency.
8
Performance
Initialize the #logInspector in the constructor to avoid multiple initializations
The #init method should be called only once in the constructor to avoid multiple initializations. You can use a flag to check if initialization is complete.
Why: The suggestion is valid and improves the initialization pattern of #logInspector, ensuring it's done once, which is a good practice for performance and maintainability.
7
Possible issue
Mark the script method as async to ensure proper initialization
The script method should be marked as async to ensure that the Script instance is fully initialized before being used.
-script() {+async script() {
if (this.#script === undefined) {
this.#script = new Script(this)
+ await this.#script.#init()
}
return this.#script
}
Apply this suggestion
Suggestion importance[1-10]: 6
Why: The suggestion correctly points out the need for the script method to be asynchronous to ensure the Script instance is fully initialized. This is important for correct operation but is a moderate issue.
6
Add a timeout to the delay function to prevent infinite waits
Add a timeout to the delay function to avoid potential infinite waits if the promise is not resolved.
function delay(ms) {
- return new Promise((resolve) => setTimeout(resolve, ms))+ return new Promise((resolve, reject) => {+ const timeout = setTimeout(resolve, ms)+ setTimeout(() => {+ clearTimeout(timeout)+ reject(new Error('Delay timed out'))+ }, ms + 5000)+ })
}
Apply this suggestion
Suggestion importance[1-10]: 5
Why: Adding a timeout to the delay function is a good practice to avoid potential infinite waits. However, the context of usage (in tests) and the specific implementation suggested might not be necessary or optimal, thus the moderate score.
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
Partial implementation of #13992
Motivation and Context
Provide high-level API that is easy for users to use.
Types of changes
Checklist
PR Type
Enhancement, Tests
Description
Script
class to handle JavaScript error and console message logging.Script
class into theWebDriver
class with a newscript
method.LogInspector
for removing non-existent callbacks.Script
class methods, including error handling.Changes walkthrough 📝
logInspector.js
Add error handling for callback removal
javascript/node/selenium-webdriver/bidi/logInspector.js
deletion.
script.js
Introduce Script class for logging handlers
javascript/node/selenium-webdriver/lib/script.js
Script
class to handle JavaScript error and consolemessage logging.
handlers.
webdriver.js
Integrate Script class into WebDriver
javascript/node/selenium-webdriver/lib/webdriver.js
Script
class into theWebDriver
class.script
method to initialize and return aScript
instance.webdriver_script_test.js
Add tests for Script class logging handlers
javascript/node/selenium-webdriver/test/lib/webdriver_script_test.js
Script
class methods.message handlers.