Skip to content
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

[dotnet] BiDi implementation #14318

Merged
merged 15 commits into from
Sep 9, 2024
Merged

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Jul 29, 2024

User description

This is the implementation of BiDi protocol for .NET

Description

  • New classes are in OpenQA.Selenium.BiDi namespace

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Implemented BiDi protocol for .NET with new classes in OpenQA.Selenium.BiDi namespace.
  • Added BrowsingContextModule for managing browsing contexts.
  • Implemented Broker class for BiDi protocol communication.
  • Introduced BrowsingContext class for context management.
  • Defined RemoteValue class and derived types for representing remote values.
  • Added NetworkModule for network-related operations.
  • Implemented BiDi class for protocol management.
  • Introduced BrowsingContextNetworkModule for network operations within a browsing context.
  • Defined Command class and derived types for representing commands.
  • Introduced Intercept class for network intercepts.
  • Added ScriptModule for script-related operations.
  • Defined LocalValue class and derived types for representing local values.
  • Implemented RemoteValueConverter for JSON serialization of RemoteValue types.
  • Defined RealmInfo class and derived types for representing realm information.
  • Added PerformActionsCommand for performing input actions.
  • Implemented WebSocketTransport for WebSocket communication.
  • Introduced BrowsingContextScriptModule for script operations within a browsing context.
  • Defined PrintCommand for printing a browsing context.
  • Added GetCookiesCommand for retrieving cookies.
  • Introduced SessionModule for session management.
  • Defined Locator class and derived types for locating elements.
  • Introduced Request class for managing network requests.
  • Added StorageModule for storage-related operations.
  • Defined CaptureScreenshotCommand for capturing screenshots.
  • Implemented RealmInfoConverter for JSON serialization of RealmInfo types.
  • Defined EventHandler class and derived types for handling events.
  • Added EvaluateCommand for evaluating scripts.
  • Introduced BrowserModule for browser operations.
  • Added BrowsingContextStorageModule for storage operations within a browsing context.
  • Implemented RealmTypeConverter for JSON serialization of RealmType enum.
  • Defined UrlPattern class and derived types for representing URL patterns.
  • Added CallFunctionCommand for calling functions.
  • Defined ProxyConfiguration class and derived types for configuring proxies.
  • Introduced Subscription class for event management.
  • Defined LogEntry class and derived types for representing log entries.
  • Added ContinueResponseCommand for continuing responses.
  • Defined ProvideResponseCommand for providing responses.
  • Added ContinueRequestCommand for continuing requests.
  • Implemented LogEntryConverter for JSON serialization of LogEntry types.
  • Defined ContinueWithAuthCommand for continuing with authentication.
  • Implemented EvaluateResultConverter for JSON serialization of EvaluateResult types.
  • Defined SetCookieCommand for setting cookies.
  • Implemented MessageConverter for JSON serialization of Message types.
  • Defined LocateNodesCommand for locating nodes.
  • Added AddInterceptCommand for adding intercepts.
  • Defined AddPreloadScriptCommand for adding preload scripts.
  • Added WebDriver extension methods for BiDi protocol.
  • Implemented DateTimeOffsetConverter for JSON serialization of DateTimeOffset.
  • Added InternalIdConverter for JSON serialization.
  • Implemented ChannelConverter for JSON serialization.
  • Added HandleConverter for JSON serialization.
  • Implemented RealmConverter for JSON serialization.
  • Added RequestConverter for JSON serialization.
  • Added GetRealmsCommand and related records.
  • Added GetTreeCommand and related records.
  • Added Message records for communication.
  • Added SetViewportCommand and related records.
  • Added LogModule for log entry subscriptions.
  • Added NavigateCommand and related records.
  • Added NewCommand and related records.
  • Added PreloadScript class for managing preload scripts.
  • Implemented NavigationConverter for JSON serialization.
  • Added HandleUserPromptCommand and related records.
  • Added UserContext class for managing user contexts.
  • Added ReloadCommand and related records.
  • Added ResponseData record for network responses.
  • Added SetCookieHeader record for cookies.
  • Added SubscribeCommand and related records.
  • Added BrowsingContextInfo record for context info.
  • Added Initiator record and enum for network requests.
  • Added DeleteCookiesCommand and related records.
  • Added BrowsingContextInputModule for input actions.
  • Added UserPromptOpenedEventArgs and UserPromptType enum.
  • Added BaseParametersEventArgs for network events.
  • Added BytesValue and derived records.
  • Added Target and derived records.
  • Added CapabilityRequest class for session capabilities.
  • Added ScriptEvaluateException class.
  • Added FetchTimingInfo record for network timings.
  • Added Cookie record and SameSite enum.
  • Added BeforeRequestSentEventArgs record.
  • Added ITransport interface for communication.
  • Added ResponseCompletedEventArgs record.
  • Added SerializationOptions class and ShadowTree enum.
  • Added FetchErrorEventArgs record.
  • Added ResponseStartedEventArgs record.
  • Added TraverseHistoryCommand and related records.
  • Added AuthCredentials and derived records.
  • Added EventArgs and derived records.
  • Added RemovePreloadScriptCommand and related records.
  • Added RemoveUserContextCommand and related records.
  • Added AuthRequiredEventArgs record.
  • Added RemoveInterceptCommand and related records.
  • Added DisownCommand and related records.
  • Added GetUserContextsCommand and related records.
  • Added ChannelValue and ChannelProperties records.
  • Added RemoteReference and derived records.
  • Added UserPromptClosedEventArgs record.
  • Added ReleaseActionsCommand and related records.
  • Added FailRequestCommand and related records.
  • Added ActivateCommand and related records.
  • Added CloseCommand and related records.
  • Added InternalId class.
  • Added Handle class.
  • Added Realm class.
  • Added Channel class.
  • Added RequestData record for network requests.
  • Added CapabilitiesRequest class.
  • Added StatusCommand and related records.
  • Added RealmType enum for script realms.

Changes walkthrough 📝

Relevant files
New feature
46 files
BrowsingContextModule.cs
Introduce BrowsingContextModule for managing browsing contexts

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs

  • Added a new BrowsingContextModule class with various methods for
    managing browsing contexts.
  • Implemented methods for creating, navigating, activating, and closing
    browsing contexts.
  • Added methods for handling user prompts and capturing screenshots.
  • Included event subscription methods for various browsing context
    events.
  • +270/-0 
    Broker.cs
    Implement Broker class for BiDi protocol communication     

    dotnet/src/webdriver/BiDi/Communication/Broker.cs

  • Added a new Broker class for handling communication with the BiDi
    protocol.
  • Implemented methods for connecting, receiving, and processing
    messages.
  • Added methods for executing commands and subscribing to events.
  • Included JSON serialization options and custom converters.
  • +262/-0 
    BrowsingContext.cs
    Introduce BrowsingContext class for context management     

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs

  • Added a new BrowsingContext class representing a browsing context.
  • Implemented methods for navigating, reloading, and activating the
    context.
  • Included methods for handling user prompts and capturing screenshots.
  • Added event subscription methods for various browsing context events.
  • +184/-0 
    RemoteValue.cs
    Define RemoteValue class and derived types                             

    dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs

  • Added a new RemoteValue class and its derived types for representing
    remote values.
  • Implemented implicit conversions and type-specific methods.
  • Included various derived types like NumberRemoteValue,
    StringRemoteValue, and ObjectRemoteValue.
  • +243/-0 
    NetworkModule.cs
    Introduce NetworkModule for network operations                     

    dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs

  • Added a new NetworkModule class for managing network-related
    operations.
  • Implemented methods for adding and removing intercepts.
  • Included methods for continuing, failing, and providing responses to
    requests.
  • Added event subscription methods for network events.
  • +173/-0 
    BiDi.cs
    Implement BiDi class for protocol management                         

    dotnet/src/webdriver/BiDi/BiDi.cs

  • Added a new BiDi class for managing the BiDi protocol connection.
  • Implemented methods for connecting, creating browsing contexts, and
    getting context trees.
  • Included methods for subscribing to browsing context and user prompt
    events.
  • Added disposal methods for cleaning up resources.
  • +126/-0 
    BrowsingContextNetworkModule.cs
    Introduce BrowsingContextNetworkModule for network operations

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs

  • Added a new BrowsingContextNetworkModule class for managing network
    operations within a browsing context.
  • Implemented methods for adding intercepts and subscribing to network
    events.
  • +92/-0   
    Command.cs
    Define Command class and derived types                                     

    dotnet/src/webdriver/BiDi/Communication/Command.cs

  • Added a new Command class and its derived types for representing
    commands.
  • Implemented various command types for different modules like Session,
    Browser, and Network.
  • +67/-0   
    Intercept.cs
    Introduce Intercept class for network intercepts                 

    dotnet/src/webdriver/BiDi/Modules/Network/Intercept.cs

  • Added a new Intercept class for managing network intercepts.
  • Implemented methods for removing intercepts and subscribing to network
    events.
  • Included filtering logic for handling specific intercepts.
  • +105/-0 
    ScriptModule.cs
    Introduce ScriptModule for script operations                         

    dotnet/src/webdriver/BiDi/Modules/Script/ScriptModule.cs

  • Added a new ScriptModule class for managing script-related operations.
  • Implemented methods for evaluating scripts and calling functions.
  • Included methods for managing preload scripts and getting realms.
  • +91/-0   
    LocalValue.cs
    Define LocalValue class and derived types                               

    dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs

  • Added a new LocalValue class and its derived types for representing
    local values.
  • Implemented implicit conversions and type-specific methods.
  • Included various derived types like NumberLocalValue,
    StringLocalValue, and ObjectLocalValue.
  • +83/-0   
    RemoteValueConverter.cs
    Implement RemoteValueConverter for JSON serialization       

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs

  • Added a new RemoteValueConverter class for JSON serialization of
    RemoteValue types.
  • Implemented custom logic for reading and writing RemoteValue objects.
  • +48/-0   
    RealmInfo.cs
    Define RealmInfo class and derived types                                 

    dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs

  • Added a new RealmInfo class and its derived types for representing
    realm information.
  • Implemented various derived types like WindowRealmInfo,
    WorkerRealmInfo, and ServiceWorkerRealmInfo.
  • +36/-0   
    PerformActionsCommand.cs
    Define PerformActionsCommand and action types                       

    dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs

  • Added a new PerformActionsCommand class and its parameters for
    performing input actions.
  • Implemented various action types like KeyDownAction, KeyUpAction, and
    KeyPauseAction.
  • +74/-0   
    WebSocketTransport.cs
    Implement WebSocketTransport for WebSocket communication 

    dotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs

  • Added a new WebSocketTransport class for managing WebSocket
    connections.
  • Implemented methods for connecting, receiving, and sending messages.
  • Included disposal logic for cleaning up resources.
  • +62/-0   
    BrowsingContextScriptModule.cs
    Introduce BrowsingContextScriptModule for script operations

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextScriptModule.cs

  • Added a new BrowsingContextScriptModule class for managing script
    operations within a browsing context.
  • Implemented methods for evaluating scripts and calling functions.
  • Included methods for managing preload scripts and getting realms.
  • +57/-0   
    PrintCommand.cs
    Define PrintCommand and print options                                       

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs

  • Added a new PrintCommand class and its parameters for printing a
    browsing context.
  • Implemented options for configuring print settings like margins,
    orientation, and scale.
  • +68/-0   
    GetCookiesCommand.cs
    Define GetCookiesCommand and options                                         

    dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs

  • Added a new GetCookiesCommand class and its parameters for retrieving
    cookies.
  • Implemented options for filtering cookies and specifying partitions.
  • +59/-0   
    SessionModule.cs
    Introduce SessionModule for session management                     

    dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs

  • Added a new SessionModule class for managing session-related
    operations.
  • Implemented methods for getting status, subscribing, and unsubscribing
    to events.
  • Included methods for creating and ending sessions.
  • +49/-0   
    Locator.cs
    Define Locator class and derived types                                     

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/Locator.cs

  • Added a new Locator class and its derived types for locating elements.
  • Implemented various locator types like CssLocator, XPathLocator, and
    InnerTextLocator.
  • +49/-0   
    Request.cs
    Introduce Request class for network requests                         

    dotnet/src/webdriver/BiDi/Modules/Network/Request.cs

  • Added a new Request class for managing network requests.
  • Implemented methods for continuing, failing, and providing responses
    to requests.
  • Included methods for handling authentication.
  • +51/-0   
    StorageModule.cs
    Introduce StorageModule for storage operations                     

    dotnet/src/webdriver/BiDi/Modules/Storage/StorageModule.cs

  • Added a new StorageModule class for managing storage-related
    operations.
  • Implemented methods for getting, setting, and deleting cookies.
  • +45/-0   
    CaptureScreenshotCommand.cs
    Define CaptureScreenshotCommand and options                           

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs

  • Added a new CaptureScreenshotCommand class and its parameters for
    capturing screenshots.
  • Implemented options for configuring screenshot settings like origin,
    format, and clip.
  • +52/-0   
    RealmInfoConverter.cs
    Implement RealmInfoConverter for JSON serialization           

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RealmInfoConverter.cs

  • Added a new RealmInfoConverter class for JSON serialization of
    RealmInfo types.
  • Implemented custom logic for reading and writing RealmInfo objects.
  • +33/-0   
    EventHandler.cs
    Define EventHandler class and derived types                           

    dotnet/src/webdriver/BiDi/Communication/EventHandler.cs

  • Added a new EventHandler class and its derived types for handling
    events.
  • Implemented asynchronous and synchronous event handlers.
  • +39/-0   
    EvaluateCommand.cs
    Define EvaluateCommand and result types                                   

    dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs

  • Added a new EvaluateCommand class and its parameters for evaluating
    scripts.
  • Implemented result types for successful and exceptional evaluations.
  • +35/-0   
    BrowserModule.cs
    Introduce BrowserModule for browser operations                     

    dotnet/src/webdriver/BiDi/Modules/Browser/BrowserModule.cs

  • Added a new BrowserModule class for managing browser-related
    operations.
  • Implemented methods for closing the browser and managing user
    contexts.
  • +32/-0   
    BrowsingContextStorageModule.cs
    Introduce BrowsingContextStorageModule for storage operations

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextStorageModule.cs

  • Added a new BrowsingContextStorageModule class for managing storage
    operations within a browsing context.
  • Implemented methods for getting, setting, and deleting cookies.
  • +38/-0   
    RealmTypeConverter.cs
    Implement RealmTypeConverter for JSON serialization           

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmTypeConverter.cs

  • Added a new RealmTypeConverter class for JSON serialization of
    RealmType enum.
  • Implemented custom logic for reading and writing RealmType values.
  • +32/-0   
    UrlPattern.cs
    Define UrlPattern class and derived types                               

    dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs

  • Added a new UrlPattern class and its derived types for representing
    URL patterns.
  • Implemented various pattern types like UrlPatternPattern and
    UrlPatternString.
  • +31/-0   
    CallFunctionCommand.cs
    Define CallFunctionCommand and options                                     

    dotnet/src/webdriver/BiDi/Modules/Script/CallFunctionCommand.cs

  • Added a new CallFunctionCommand class and its parameters for calling
    functions.
  • Implemented options for configuring function call settings.
  • +32/-0   
    ProxyConfiguration.cs
    Define ProxyConfiguration class and derived types               

    dotnet/src/webdriver/BiDi/Modules/Session/ProxyConfiguration.cs

  • Added a new ProxyConfiguration class and its derived types for
    configuring proxies.
  • Implemented various proxy types like ManualProxyConfiguration and
    PacProxyConfiguration.
  • +32/-0   
    Subscription.cs
    Introduce Subscription class for event management               

    dotnet/src/webdriver/BiDi/Subscription.cs

  • Added a new Subscription class for managing event subscriptions.
  • Implemented methods for unsubscribing and disposing subscriptions.
  • +43/-0   
    LogEntry.cs
    Define LogEntry class and derived types                                   

    dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs

  • Added a new LogEntry class and its derived types for representing log
    entries.
  • Implemented various log entry types like ConsoleLogEntry and
    JavascriptLogEntry.
  • +25/-0   
    ContinueResponseCommand.cs
    Define ContinueResponseCommand and options                             

    dotnet/src/webdriver/BiDi/Modules/Network/ContinueResponseCommand.cs

  • Added a new ContinueResponseCommand class and its parameters for
    continuing responses.
  • Implemented options for configuring response continuation settings.
  • +32/-0   
    ProvideResponseCommand.cs
    Define ProvideResponseCommand and options                               

    dotnet/src/webdriver/BiDi/Modules/Network/ProvideResponseCommand.cs

  • Added a new ProvideResponseCommand class and its parameters for
    providing responses.
  • Implemented options for configuring response settings.
  • +32/-0   
    ContinueRequestCommand.cs
    Define ContinueRequestCommand and options                               

    dotnet/src/webdriver/BiDi/Modules/Network/ContinueRequestCommand.cs

  • Added a new ContinueRequestCommand class and its parameters for
    continuing requests.
  • Implemented options for configuring request continuation settings.
  • +32/-0   
    LogEntryConverter.cs
    Implement LogEntryConverter for JSON serialization             

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/LogEntryConverter.cs

  • Added a new LogEntryConverter class for JSON serialization of LogEntry
    types.
  • Implemented custom logic for reading and writing LogEntry objects.
  • +27/-0   
    ContinueWithAuthCommand.cs
    Define ContinueWithAuthCommand and options                             

    dotnet/src/webdriver/BiDi/Modules/Network/ContinueWithAuthCommand.cs

  • Added a new ContinueWithAuthCommand class and its parameters for
    continuing with authentication.
  • Implemented options for configuring authentication continuation
    settings.
  • +24/-0   
    EvaluateResultConverter.cs
    Implement EvaluateResultConverter for JSON serialization 

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/EvaluateResultConverter.cs

  • Added a new EvaluateResultConverter class for JSON serialization of
    EvaluateResult types.
  • Implemented custom logic for reading and writing EvaluateResult
    objects.
  • +27/-0   
    SetCookieCommand.cs
    Define SetCookieCommand and options                                           

    dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs

  • Added a new SetCookieCommand class and its parameters for setting
    cookies.
  • Implemented options for configuring cookie settings.
  • +31/-0   
    MessageConverter.cs
    Implement MessageConverter for JSON serialization               

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/MessageConverter.cs

  • Added a new MessageConverter class for JSON serialization of Message
    types.
  • Implemented custom logic for reading and writing Message objects.
  • +27/-0   
    LocateNodesCommand.cs
    Define LocateNodesCommand and options                                       

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs

  • Added a new LocateNodesCommand class and its parameters for locating
    nodes.
  • Implemented options for configuring node location settings.
  • +26/-0   
    AddInterceptCommand.cs
    Define AddInterceptCommand and options                                     

    dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs

  • Added a new AddInterceptCommand class and its parameters for adding
    intercepts.
  • Implemented options for configuring intercept settings.
  • +29/-0   
    AddPreloadScriptCommand.cs
    Define AddPreloadScriptCommand and options                             

    dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs

  • Added a new AddPreloadScriptCommand class and its parameters for
    adding preload scripts.
  • Implemented options for configuring preload script settings.
  • +26/-0   
    WebDriver.Extensions.cs
    Add WebDriver extension methods for BiDi protocol               

    dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs

  • Added extension methods for IWebDriver to support BiDi protocol.
  • Implemented methods for converting WebDriver to BiDi and
    BrowsingContext.
  • +27/-0   
    Enhancement
    61 files
    InternalIdConverter.cs
    Add InternalIdConverter for JSON serialization.                   

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/InternalIdConverter.cs

  • Added a new InternalIdConverter class for JSON serialization.
  • Implemented Read and Write methods for InternalId.
  • +28/-0   
    ChannelConverter.cs
    Add ChannelConverter for JSON serialization.                         

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/ChannelConverter.cs

  • Added a new ChannelConverter class for JSON serialization.
  • Implemented Read and Write methods for Channel.
  • +28/-0   
    HandleConverter.cs
    Add HandleConverter for JSON serialization.                           

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/HandleConverter.cs

  • Added a new HandleConverter class for JSON serialization.
  • Implemented Read and Write methods for Handle.
  • +28/-0   
    RealmConverter.cs
    Add RealmConverter for JSON serialization.                             

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/RealmConverter.cs

  • Added a new RealmConverter class for JSON serialization.
  • Implemented Read and Write methods for Realm.
  • +28/-0   
    RequestConverter.cs
    Add RequestConverter for JSON serialization.                         

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/RequestConverter.cs

  • Added a new RequestConverter class for JSON serialization.
  • Implemented Read and Write methods for Request.
  • +28/-0   
    GetRealmsCommand.cs
    Add GetRealmsCommand and related records.                               

    dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs

  • Added GetRealmsCommand class and related records for command
    parameters, options, and results.
  • +22/-0   
    GetTreeCommand.cs
    Add GetTreeCommand and related records.                                   

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs

  • Added GetTreeCommand class and related records for command parameters,
    options, and results.
  • +22/-0   
    Message.cs
    Add Message records for communication.                                     

    dotnet/src/webdriver/BiDi/Communication/Message.cs

  • Added abstract Message record and derived records for success, error,
    and event messages.
  • +21/-0   
    SetViewportCommand.cs
    Add SetViewportCommand and related records.                           

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/SetViewportCommand.cs

  • Added SetViewportCommand class and related records for command
    parameters, options, and viewport structure.
  • +21/-0   
    LogModule.cs
    Add LogModule for log entry subscriptions.                             

    dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs

  • Added LogModule class with methods for subscribing to log entry
    events.
  • +18/-0   
    NavigateCommand.cs
    Add NavigateCommand and related records.                                 

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs

  • Added NavigateCommand class and related records for command
    parameters, options, and results.
  • +24/-0   
    NewCommand.cs
    Add NewCommand and related records.                                           

    dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs

  • Added NewCommand class and related records for command parameters,
    options, and results.
  • +18/-0   
    PreloadScript.cs
    Add PreloadScript class for managing preload scripts.       

    dotnet/src/webdriver/BiDi/Modules/Script/PreloadScript.cs

  • Added PreloadScript class implementing IAsyncDisposable for managing
    preload scripts.
  • +27/-0   
    NavigationConverter.cs
    Add NavigationConverter for JSON serialization.                   

    dotnet/src/webdriver/BiDi/Communication/Json/Converters/NavigationConverter.cs

  • Added a new NavigationConverter class for JSON serialization.
  • Implemented Read and Write methods for Navigation.
  • +21/-0   
    HandleUserPromptCommand.cs
    Add HandleUserPromptCommand and related records.                 

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/HandleUserPromptCommand.cs

  • Added HandleUserPromptCommand class and related records for command
    parameters and options.
  • +19/-0   
    UserContext.cs
    Add UserContext class for managing user contexts.               

    dotnet/src/webdriver/BiDi/Modules/Browser/UserContext.cs

  • Added UserContext class implementing IAsyncDisposable for managing
    user contexts.
  • +27/-0   
    ReloadCommand.cs
    Add ReloadCommand and related records.                                     

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ReloadCommand.cs

  • Added ReloadCommand class and related records for command parameters
    and options.
  • +19/-0   
    ResponseData.cs
    Add ResponseData record for network responses.                     

    dotnet/src/webdriver/BiDi/Modules/Network/ResponseData.cs

    • Added ResponseData record for network response details.
    +20/-0   
    SetCookieHeader.cs
    Add SetCookieHeader record for cookies.                                   

    dotnet/src/webdriver/BiDi/Modules/Network/SetCookieHeader.cs

    • Added SetCookieHeader record for setting cookie headers.
    +18/-0   
    SubscribeCommand.cs
    Add SubscribeCommand and related records.                               

    dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs

  • Added SubscribeCommand class and related records for command
    parameters and options.
  • +16/-0   
    BrowsingContextInfo.cs
    Add BrowsingContextInfo record for context info.                 

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInfo.cs

  • Added BrowsingContextInfo record for browsing context information.
  • +12/-0   
    Initiator.cs
    Add Initiator record and enum for network requests.           

    dotnet/src/webdriver/BiDi/Modules/Network/Initiator.cs

  • Added Initiator record and InitiatorType enum for network request
    initiators.
  • +20/-0   
    DeleteCookiesCommand.cs
    Add DeleteCookiesCommand and related records.                       

    dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs

  • Added DeleteCookiesCommand class and related records for command
    parameters, options, and results.
  • +16/-0   
    BrowsingContextInputModule.cs
    Add BrowsingContextInputModule for input actions.               

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextInputModule.cs

  • Added BrowsingContextInputModule class for performing input actions in
    a browsing context.
  • +17/-0   
    UserPromptOpenedEventArgs.cs
    Add UserPromptOpenedEventArgs and UserPromptType enum.     

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptOpenedEventArgs.cs

  • Added UserPromptOpenedEventArgs record for user prompt opened events.
  • Defined UserPromptType enum for different prompt types.
  • +18/-0   
    BaseParametersEventArgs.cs
    Add BaseParametersEventArgs for network events.                   

    dotnet/src/webdriver/BiDi/Modules/Network/BaseParametersEventArgs.cs

  • Added BaseParametersEventArgs abstract record for network event
    arguments.
  • +13/-0   
    BytesValue.cs
    Add BytesValue and derived records.                                           

    dotnet/src/webdriver/BiDi/Modules/Network/BytesValue.cs

  • Added BytesValue abstract record and derived records for string and
    base64 values.
  • +15/-0   
    Target.cs
    Add Target and derived records.                                                   

    dotnet/src/webdriver/BiDi/Modules/Script/Target.cs

  • Added Target abstract record and derived records for realm and context
    targets.
  • +19/-0   
    CapabilityRequest.cs
    Add CapabilityRequest class for session capabilities.       

    dotnet/src/webdriver/BiDi/Modules/Session/CapabilityRequest.cs

    • Added CapabilityRequest class for session capability requests.
    +16/-0   
    ScriptEvaluateException.cs
    Add ScriptEvaluateException class.                                             

    dotnet/src/webdriver/BiDi/Modules/Script/ScriptEvaluateException.cs

  • Added ScriptEvaluateException class for handling script evaluation
    exceptions.
  • +14/-0   
    FetchTimingInfo.cs
    Add FetchTimingInfo record for network timings.                   

    dotnet/src/webdriver/BiDi/Modules/Network/FetchTimingInfo.cs

  • Added FetchTimingInfo record for network fetch timing information.
  • +15/-0   
    Cookie.cs
    Add Cookie record and SameSite enum.                                         

    dotnet/src/webdriver/BiDi/Modules/Network/Cookie.cs

  • Added Cookie record for network cookies.
  • Defined SameSite enum for cookie same-site policies.
  • +17/-0   
    BeforeRequestSentEventArgs.cs
    Add BeforeRequestSentEventArgs record.                                     

    dotnet/src/webdriver/BiDi/Modules/Network/BeforeRequestSentEventArgs.cs

  • Added BeforeRequestSentEventArgs record for before request sent
    events.
  • +7/-0     
    ITransport.cs
    Add ITransport interface for communication.                           

    dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs

    • Added ITransport interface for communication transport.
    +15/-0   
    ResponseCompletedEventArgs.cs
    Add ResponseCompletedEventArgs record.                                     

    dotnet/src/webdriver/BiDi/Modules/Network/ResponseCompletedEventArgs.cs

  • Added ResponseCompletedEventArgs record for response completed events.

  • +7/-0     
    SerializationOptions.cs
    Add SerializationOptions class and ShadowTree enum.           

    dotnet/src/webdriver/BiDi/Modules/Script/SerializationOptions.cs

  • Added SerializationOptions class and ShadowTree enum for serialization
    options.
  • +17/-0   
    FetchErrorEventArgs.cs
    Add FetchErrorEventArgs record.                                                   

    dotnet/src/webdriver/BiDi/Modules/Network/FetchErrorEventArgs.cs

    • Added FetchErrorEventArgs record for fetch error events.
    +7/-0     
    ResponseStartedEventArgs.cs
    Add ResponseStartedEventArgs record.                                         

    dotnet/src/webdriver/BiDi/Modules/Network/ResponseStartedEventArgs.cs

  • Added ResponseStartedEventArgs record for response started events.
  • +7/-0     
    TraverseHistoryCommand.cs
    Add TraverseHistoryCommand and related records.                   

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs

  • Added TraverseHistoryCommand class and related records for command
    parameters, options, and results.
  • +11/-0   
    AuthCredentials.cs
    Add AuthCredentials and derived records.                                 

    dotnet/src/webdriver/BiDi/Modules/Network/AuthCredentials.cs

  • Added AuthCredentials abstract record and derived record for basic
    authentication.
  • +12/-0   
    EventArgs.cs
    Add EventArgs and derived records.                                             

    dotnet/src/webdriver/BiDi/EventArgs.cs

  • Added EventArgs abstract record and derived record for browsing
    context events.
  • +13/-0   
    RemovePreloadScriptCommand.cs
    Add RemovePreloadScriptCommand and related records.           

    dotnet/src/webdriver/BiDi/Modules/Script/RemovePreloadScriptCommand.cs

  • Added RemovePreloadScriptCommand class and related records for command
    parameters and options.
  • +9/-0     
    RemoveUserContextCommand.cs
    Add RemoveUserContextCommand and related records.               

    dotnet/src/webdriver/BiDi/Modules/Browser/RemoveUserContextCommand.cs

  • Added RemoveUserContextCommand class and related records for command
    parameters and options.
  • +9/-0     
    AuthRequiredEventArgs.cs
    Add AuthRequiredEventArgs record.                                               

    dotnet/src/webdriver/BiDi/Modules/Network/AuthRequiredEventArgs.cs

  • Added AuthRequiredEventArgs record for authentication required events.

  • +6/-0     
    RemoveInterceptCommand.cs
    Add RemoveInterceptCommand and related records.                   

    dotnet/src/webdriver/BiDi/Modules/Network/RemoveInterceptCommand.cs

  • Added RemoveInterceptCommand class and related records for command
    parameters and options.
  • +9/-0     
    DisownCommand.cs
    Add DisownCommand and related records.                                     

    dotnet/src/webdriver/BiDi/Modules/Script/DisownCommand.cs

  • Added DisownCommand class and related records for command parameters.
  • +8/-0     
    GetUserContextsCommand.cs
    Add GetUserContextsCommand and related records.                   

    dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs

  • Added GetUserContextsCommand class and related records for command
    options and results.
  • +10/-0   
    ChannelValue.cs
    Add ChannelValue and ChannelProperties records.                   

    dotnet/src/webdriver/BiDi/Modules/Script/ChannelValue.cs

  • Added ChannelValue record and ChannelProperties record for channel
    values.
  • +13/-0   
    RemoteReference.cs
    Add RemoteReference and derived records.                                 

    dotnet/src/webdriver/BiDi/Modules/Script/RemoteReference.cs

  • Added RemoteReference abstract record and derived records for shared
    and remote object references.
  • +13/-0   
    UserPromptClosedEventArgs.cs
    Add UserPromptClosedEventArgs record.                                       

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/UserPromptClosedEventArgs.cs

  • Added UserPromptClosedEventArgs record for user prompt closed events.
  • +10/-0   
    ReleaseActionsCommand.cs
    Add ReleaseActionsCommand and related records.                     

    dotnet/src/webdriver/BiDi/Modules/Input/ReleaseActionsCommand.cs

  • Added ReleaseActionsCommand class and related records for command
    parameters and options.
  • +9/-0     
    FailRequestCommand.cs
    Add FailRequestCommand and related records.                           

    dotnet/src/webdriver/BiDi/Modules/Network/FailRequestCommand.cs

  • Added FailRequestCommand class and related records for command
    parameters and options.
  • +9/-0     
    ActivateCommand.cs
    Add ActivateCommand and related records.                                 

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/ActivateCommand.cs

  • Added ActivateCommand class and related records for command parameters
    and options.
  • +9/-0     
    CloseCommand.cs
    Add CloseCommand and related records.                                       

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CloseCommand.cs

  • Added CloseCommand class and related records for command parameters
    and options.
  • +9/-0     
    InternalId.cs
    Add InternalId class.                                                                       

    dotnet/src/webdriver/BiDi/Modules/Script/InternalId.cs

    • Added InternalId class for internal identifiers.
    +14/-0   
    Handle.cs
    Add Handle class.                                                                               

    dotnet/src/webdriver/BiDi/Modules/Script/Handle.cs

    • Added Handle class for script handles.
    +14/-0   
    Realm.cs
    Add Realm class.                                                                                 

    dotnet/src/webdriver/BiDi/Modules/Script/Realm.cs

    • Added Realm class for script realms.
    +14/-0   
    Channel.cs
    Add Channel class.                                                                             

    dotnet/src/webdriver/BiDi/Modules/Script/Channel.cs

    • Added Channel class for script channels.
    +14/-0   
    RequestData.cs
    Add RequestData record for network requests.                         

    dotnet/src/webdriver/BiDi/Modules/Network/RequestData.cs

    • Added RequestData record for network request details.
    +5/-0     
    CapabilitiesRequest.cs
    Add CapabilitiesRequest class.                                                     

    dotnet/src/webdriver/BiDi/Modules/Session/CapabilitiesRequest.cs

  • Added CapabilitiesRequest class for session capabilities requests.
  • +10/-0   
    StatusCommand.cs
    Add StatusCommand and related records.                                     

    dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs

  • Added StatusCommand class and related records for command options and
    results.
  • +9/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link
    Contributor

    codiumai-pr-agent-pro bot commented Jul 29, 2024

    PR Reviewer Guide 🔍

    (Review updated until commit ac6f188)

    ⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Code Complexity
    The BrowsingContextModule class contains a large number of methods and responsibilities. Consider breaking it down into smaller, more focused classes to improve maintainability and readability.

    Error Handling
    The error handling in the ReceiveMessagesAsync method could be improved. Consider adding more specific exception handling and logging to better diagnose and handle potential issues.

    Type Conversion
    The ConvertTo method uses a switch statement for type conversion. This approach might not be extensible enough for future types. Consider implementing a more flexible conversion strategy.

    Copy link
    Contributor

    codiumai-pr-agent-pro bot commented Jul 29, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Robustness
    Add error handling in DisposeAsync to ensure robust resource cleanup

    Implement error handling for DisposeAsync to manage exceptions that might occur
    during the disposal process, ensuring all resources are cleaned up properly.

    dotnet/src/webdriver/BiDi/BiDi.cs [84]

    -await EndAsync().ConfigureAwait(false);
    +try
    +{
    +    await EndAsync().ConfigureAwait(false);
    +}
    +catch (Exception ex)
    +{
    +    // Log the exception or handle it accordingly
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    Why: Implementing error handling in DisposeAsync is critical for ensuring that all resources are cleaned up properly, even if an exception occurs, thus improving the robustness of the code.

    10
    Add exception handling for the command execution in the 'CreateAsync' method

    In the CreateAsync method, consider handling exceptions that may occur during the
    execution of Broker.ExecuteCommandAsync. This can improve the robustness of the
    method by allowing it to gracefully handle scenarios where the command execution
    fails.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs [21]

    -var createResult = await Broker.ExecuteCommandAsync<CreateResult>(new CreateCommand(@params), options).ConfigureAwait(false);
    +CreateResult createResult;
    +try
    +{
    +    createResult = await Broker.ExecuteCommandAsync<CreateResult>(new CreateCommand(@params), options).ConfigureAwait(false);
    +}
    +catch (Exception ex)
    +{
    +    // Handle exception (e.g., log the error, modify the response)
    +    throw new InvalidOperationException("Failed to create browsing context.", ex);
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Adding exception handling enhances the robustness of the method by allowing it to handle failures gracefully. This is a valuable improvement for error management.

    8
    Bug fix
    Correct the syntax for initializing collections

    Replace the array initializer with a proper collection initializer to avoid syntax
    errors.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs [13]

    -interceptOptions.Contexts = [context];
    +interceptOptions.Contexts = new List<BrowsingContext> { context };
     
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    Why: This suggestion fixes a syntax error, which is essential for the code to compile and run correctly.

    10
    Possible bug
    Add null checks to prevent exceptions when text is null

    Add null checks for the text parameter in the Press method to prevent
    NullReferenceException when iterating over the characters of a null string.

    dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs [24]

     public static KeySourceActions Press(string text)
    +{
    +    if (text == null) throw new ArgumentNullException(nameof(text));
     
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    Why: Adding null checks is crucial to prevent potential runtime exceptions, making this a highly valuable suggestion for improving code robustness.

    10
    Enhancement
    Add validation for the 'url' parameter to ensure it is a well-formed URL

    Consider validating the url parameter in the NavigateAsync method to ensure it is a
    well-formed URL before proceeding with the navigation command. This can prevent
    potential errors or security issues related to malformed URLs.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs [28]

    +if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
    +    throw new ArgumentException("The URL provided is not a valid absolute URL.", nameof(url));
     var @params = new NavigateCommandParameters(context, url);
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion adds a crucial validation step to ensure the URL is well-formed, which can prevent potential runtime errors and security issues. It is a significant improvement for robustness and security.

    9
    Improve URL validation by using Uri.TryCreate

    Consider using Uri.TryCreate instead of new Uri to handle potential exceptions from
    invalid URLs gracefully.

    dotnet/src/webdriver/BiDi/BiDi.cs [25]

    -var uri = new Uri(url);
    +if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
    +{
    +    throw new ArgumentException("Invalid URL provided.", nameof(url));
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: This suggestion improves the robustness of the code by handling potential exceptions from invalid URLs gracefully, which is crucial for preventing runtime errors.

    9
    ✅ Use null instead of default for clearer default parameter values
    Suggestion Impact:The commit changed the default parameter value of duration in the Pause method to null, which aligns with the suggestion. However, it also changed the type from ulong? to long?.

    code diff:

    -    public KeySourceActions Pause(ulong? duration = default)
    +    public KeySourceActions Pause(long? duration = null)

    Replace the default parameter value of duration in Pause method with null instead of
    default to make the intent clearer and align with common C# practices.

    dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs [53]

    -public KeySourceActions Pause(ulong? duration = default)
    +public KeySourceActions Pause(ulong? duration = null)
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: This suggestion enhances code clarity and aligns with common C# practices, although it is a minor improvement.

    7
    Implement a timeout mechanism for the 'ReloadAsync' method to handle long-running reloads

    In the ReloadAsync method, consider adding a timeout option to the NavigateOptions
    and implement a timeout mechanism in the navigation process. This can prevent the
    method from waiting indefinitely if the page reload does not complete.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs [91]

     var @params = new ReloadCommandParameters(context);
    +if (options?.Timeout.HasValue)
    +{
    +    @params.Timeout = options.Timeout.Value;
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Implementing a timeout mechanism is a good enhancement to prevent indefinite waiting during page reloads. However, it is a less critical improvement compared to the others.

    6
    Possible issue
    Replace mutable default value with an immutable one to avoid side effects

    Replace the mutable default value for Actions in PerformActionsOptions with a more
    appropriate immutable default. Using mutable default values can lead to unintended
    side effects if the same instance is reused.

    dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs [17]

    -public IEnumerable<SourceActions>? Actions { get; set; } = [];
    +public IEnumerable<SourceActions>? Actions { get; set; } = Enumerable.Empty<SourceActions>();
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: The suggestion correctly identifies a potential issue with using a mutable default value and provides a more appropriate immutable default, which can prevent unintended side effects.

    9
    Validate the 'Clip' property to ensure it is within the viewport bounds in 'CaptureScreenshotAsync'

    For the CaptureScreenshotAsync method, consider checking if the Clip property of the
    options is within the bounds of the current viewport. This can prevent runtime
    errors or undefined behavior when the clipping region is out of the viewport bounds.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextModule.cs [63]

     var @params = new CaptureScreenshotCommandParameters(context);
    +if (options?.Clip != null && !IsValidClip(options.Clip))
    +{
    +    throw new ArgumentException("Clip parameters are out of the viewport bounds.", nameof(options));
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: This suggestion adds a validation step to ensure the Clip property is within the viewport bounds, which can prevent potential runtime errors. It is a useful improvement for preventing undefined behavior.

    7
    Best practice
    Implement IDisposable to manage resource cleanup

    Implement IDisposable to properly dispose of Lazy fields if they hold unmanaged
    resources or need explicit disposal.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs [23-27]

    -private readonly Lazy<BrowsingContextLogModule> _logModule;
    -private readonly Lazy<BrowsingContextNetworkModule> _networkModule;
    -private readonly Lazy<BrowsingContextScriptModule> _scriptModule;
    -private readonly Lazy<BrowsingContextStorageModule> _storageModule;
    -private readonly Lazy<BrowsingContextInputModule> _inputModule;
    +public void Dispose()
    +{
    +    if (_logModule.IsValueCreated) _logModule.Value.Dispose();
    +    if (_networkModule.IsValueCreated) _networkModule.Value.Dispose();
    +    if (_scriptModule.IsValueCreated) _scriptModule.Value.Dispose();
    +    if (_storageModule.IsValueCreated) _storageModule.Value.Dispose();
    +    if (_inputModule.IsValueCreated) _inputModule.Value.Dispose();
    +}
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Implementing IDisposable is a best practice for managing resource cleanup, especially if the Lazy<T> fields hold unmanaged resources or need explicit disposal.

    8
    Use IReadOnlyList to ensure immutability of the Actions list

    Consider using IReadOnlyList instead of List for the Actions property in
    KeySourceActions to ensure immutability and to prevent external modifications.

    dotnet/src/webdriver/BiDi/Modules/Input/PerformActionsCommand.cs [44]

    -public List<KeySourceAction> Actions { get; set; } = [];
    +public IReadOnlyList<KeySourceAction> Actions { get; private set; } = new List<KeySourceAction>();
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: This suggestion improves code safety by ensuring the Actions list is immutable, which is a best practice for preventing unintended modifications.

    8
    Use named constants instead of magic numbers

    Replace magic numbers with named constants to improve code readability and
    maintainability.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs [78-83]

    -return TraverseHistoryAsync(-1, options);
    -return TraverseHistoryAsync(1, options);
    +const int BACK = -1;
    +const int FORWARD = 1;
    +return TraverseHistoryAsync(BACK, options);
    +return TraverseHistoryAsync(FORWARD, options);
     
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Replacing magic numbers with named constants improves code readability and maintainability. However, the improvement is minor and does not address any critical issue.

    6
    Performance
    ✅ Use ConfigureAwait(false) for better performance in asynchronous operations

    Utilize ConfigureAwait(false) on all awaited operations within ConnectAsync to
    ensure the context is not captured, improving performance in environments that do
    not require the context.

    dotnet/src/webdriver/BiDi/BiDi.cs [58]

    -await bidi._broker.ConnectAsync(default);
    +await bidi._broker.ConnectAsync(default).ConfigureAwait(false);
     

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    Why: This suggestion enhances performance in asynchronous operations by ensuring the context is not captured, which is beneficial in environments that do not require the context.

    8
    Maintainability
    Use a factory method to initialize Lazy fields

    Consider using a factory method to initialize the Lazy fields to reduce redundancy
    and improve maintainability. This will help centralize the creation logic and make
    the code cleaner.

    dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContext.cs [14-18]

    -_logModule = new Lazy<BrowsingContextLogModule>(() => new BrowsingContextLogModule(this, _bidi.Log));
    -_networkModule = new Lazy<BrowsingContextNetworkModule>(() => new BrowsingContextNetworkModule(this, _bidi.Network));
    -_scriptModule = new Lazy<BrowsingContextScriptModule>(() => new BrowsingContextScriptModule(this, _bidi.ScriptModule));
    -_storageModule = new Lazy<BrowsingContextStorageModule>(() => new BrowsingContextStorageModule(this, _bidi.Storage));
    -_inputModule = new Lazy<BrowsingContextInputModule>(() => new BrowsingContextInputModule(this, _bidi.InputModule));
    +_logModule = CreateLazyModule<BrowsingContextLogModule>(_bidi.Log);
    +_networkModule = CreateLazyModule<BrowsingContextNetworkModule>(_bidi.Network);
    +_scriptModule = CreateLazyModule<BrowsingContextScriptModule>(_bidi.ScriptModule);
    +_storageModule = CreateLazyModule<BrowsingContextStorageModule>(_bidi.Storage);
    +_inputModule = CreateLazyModule<BrowsingContextInputModule>(_bidi.InputModule);
     
    +private Lazy<T> CreateLazyModule<T>(IModule module) where T : IModule
    +{
    +    return new Lazy<T>(() => (T)Activator.CreateInstance(typeof(T), new object[] { this, module }));
    +}
    +
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves maintainability by reducing redundancy and centralizing the creation logic. However, it introduces additional complexity with the factory method.

    7

    @YevgeniyShunevych
    Copy link
    Contributor

    Looks great.

    @nvborisenko
    Copy link
    Member Author

    /review

    Copy link
    Contributor

    Persistent review updated to latest commit ac6f188

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants