Skip to content

Conversation

@visagang
Copy link
Contributor

@visagang visagang commented Jul 10, 2025

User description

Add a custom hook, OnLocateElement, to the web browser locate element utility.


PR Type

Enhancement


Description

  • Add OnLocateElement hook to IWebDriverHook interface

  • Implement hook invocation in PlaywrightWebDriver after element location

  • Set service provider in utility function for proper hook access


Changes diagram

flowchart LR
  A["IWebDriverHook Interface"] -- "Add method" --> B["OnLocateElement hook"]
  C["PlaywrightWebDriver"] -- "Invoke hooks" --> B
  D["UtilWebLocateElementFn"] -- "Set service provider" --> C
Loading

Changes walkthrough 📝

Relevant files
Enhancement
IWebDriverHook.cs
Add OnLocateElement hook method to interface                         

src/Infrastructure/BotSharp.Abstraction/Browsing/IWebDriverHook.cs

  • Add OnLocateElement method signature to interface
+1/-0     
PlaywrightWebDriver.LocateElement.cs
Implement hook invocation after element location                 

src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs

  • Get all IWebDriverHook services from DI container
  • Invoke OnLocateElement hook for each registered hook after successful
    element location
  • +5/-0     
    UtilWebLocateElementFn.cs
    Set service provider for browser instance                               

    src/Plugins/BotSharp.Plugin.WebDriver/UtilFunctions/UtilWebLocateElementFn.cs

    • Set service provider on browser instance before locating element
    +1/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-merge-pro
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    Hook invocation occurs after successful element location but lacks error handling. If any hook throws an exception, it could cause the entire operation to fail silently or propagate unexpected errors to the caller.

    var hooks = _services.GetServices<IWebDriverHook>();
    foreach (var hook in hooks)
    {
        await hook.OnLocateElement(message, result.Body);
    }
    Service Provider

    The service provider is set on the browser instance but it's unclear if this is necessary or if it creates any side effects. The timing and necessity of this call should be validated.

    browser.SetServiceProvider(_services);
    var result = await browser.LocateElement(msg, locatorArgs);

    @qodo-merge-pro
    Copy link

    qodo-merge-pro bot commented Jul 10, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add exception handling for hooks

    Add exception handling around the hook invocation to prevent a single failing
    hook from breaking the entire locate element operation. Consider logging any
    exceptions that occur during hook execution.

    src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs [117-121]

     var hooks = _services.GetServices<IWebDriverHook>();
     foreach (var hook in hooks)
     {
    -    await hook.OnLocateElement(message, result.Body);
    +    try
    +    {
    +        await hook.OnLocateElement(message, result.Body);
    +    }
    +    catch (Exception ex)
    +    {
    +        // Log the exception but don't let it break the operation
    +        _logger?.LogError(ex, "Error executing OnLocateElement hook");
    +    }
     }
    • Apply / Chat
    Suggestion importance[1-10]: 8

    __

    Why: This is a valuable suggestion for robustness, as an exception in one hook implementation would currently halt the execution of other hooks and potentially fail the entire operation.

    Medium
    • Update

    @iceljc iceljc merged commit 5d1c1c1 into SciSharp:master Jul 10, 2025
    4 checks passed
    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