Skip to content

[πŸš€ Feature]: [dotnet] Road to be AOT friendlyΒ #14480

Open

Description

@nvborisenko

Feature and motivation

Any consumer of Selenium library in .NET cannot use it within publishing his application as Native AOT Deployment.

The detailed affected parts are coming...

Selenium Manager βœ… v4.26

W3C WebDriver βœ… v4.26

W3C BiDi βœ… v4.28

CDP (DevTools)

Fine tuning

  • Address all analyzer warnings
  • ...

Usage example

Create console app, publish as native AOT, it fails at runtime.

Activity

  1. added
    A-needs-triagingA Selenium member will evaluate this soon!
    and removed
    A-needs-triagingA Selenium member will evaluate this soon!
    on Sep 9, 2024
  2. github-actions commented on Sep 9, 2024

    @github-actions
    Contributor

    @nvborisenko, thank you for creating this issue. We will troubleshoot it as soon as we can.


    Info for maintainers

    Triage this issue by using labels.

    If information is missing, add a helpful comment and then I-issue-template label.

    If the issue is a question, add the I-question label.

    If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

    If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

    After troubleshooting the issue, please add the R-awaiting answer label.

    Thank you!

  3. nvborisenko commented on Sep 9, 2024

    @nvborisenko
    MemberAuthor
  4. RenderMichael commented on Sep 10, 2024

    @RenderMichael
    Contributor

    I’m interested in this feature for running Selenium. Often times, the roads to AOT compatibility leads to improvements across the board, even for non-AOT scenarios.

  5. NCLnclNCL commented on Sep 26, 2024

    @NCLnclNCL

    Blocked by bazelbuild/rules_dotnet#443

    when it will be fixed

  6. nvborisenko commented on Oct 4, 2024

    @nvborisenko
    MemberAuthor

    Blocked by bazel-contrib/rules_dotnet#443

    Fixed, waiting release soon.

    Often times, the roads to AOT compatibility leads to improvements across the board, even for non-AOT scenarios.

    Who knows potential issues... , I cannot prepare decomposed tasks to archive the goal. Our mission here is to adopt existing codebase to be ready for AOT.

    The technical enabler is resolved, so the list of impacted areas will be be growing so fast soon.

  7. nvborisenko commented on Oct 17, 2024

    @nvborisenko
    MemberAuthor

    @RenderMichael are you able to test the preview version of Selenium which seems is compatible with AOT (excepting CDP)? Your input would be valuable. I can share nuget package file here (built locally).

  8. RenderMichael commented on Oct 17, 2024

    @RenderMichael
    Contributor

    @nvborisenko I would be happy to test out the AOT compatibility of Selenium :)

  9. nvborisenko commented on Oct 17, 2024

    @nvborisenko
    MemberAuthor

    Selenium.WebDriver.4.26.0-nightly202409202352.zip

    @RenderMichael This is zip, which contains nupkg inside. I built it locally, and hoping you know what to do with it.

  10. nvborisenko commented on Oct 18, 2024

    @nvborisenko
    MemberAuthor

    @RenderMichael @NCLnclNCL please don't forget to share results. Thanks guys.

  11. RenderMichael commented on Oct 20, 2024

    @RenderMichael
    Contributor

    @nvborisenko Unfortunately the app crashed as soon as I tried running the native .exe file:

    image

    I can't give more detailed feedback without building the library locally. Are there any instructions I can follow to build the .NET bindings locally? A while back I tried to do so following this guide but ran into some blockers (I no longer remember what they were).

    Edit: it was my error

  12. RenderMichael commented on Oct 20, 2024

    @RenderMichael
    Contributor

    This was my program for the above. Completely ideomatic, no obscure Selenium features or anything.

    using OpenQA.Selenium.Firefox;
    
    var options = new FirefoxOptions
    {
        AcceptInsecureCertificates = true,
    };
    
    using (var driver = new FirefoxDriver(options))
    {
        await driver.Navigate().GoToUrlAsync("https://www.google.com");
    
        string url = driver.Url;
        if (!url.Contains("google"))
        {
            throw new Exception("URL does not contain google: " + url);
        }
    }
    
    Console.ReadKey();
  13. 10 remaining items

  14. nvborisenko commented on Nov 18, 2024

    @nvborisenko
    MemberAuthor

    I received a lot of issues privately related to json serialization. In major cases users used custom class and they provided an instance of it as object. Object is expected according API, and they got JsonTypeInfo metadata for type '*' was not provided by TypeInfoResolver of type 'OpenQA.Selenium.CommandJsonSerializerContext' exception. @RenderMichael provided elegant fix (will be in 4.27). Seems we will forget about this issue for "classic" WebDriver commands. Thank you, Michael, great job!

  15. RenderMichael commented on Nov 18, 2024

    @RenderMichael
    Contributor

    Happy to contribute!

    I have a PR addressing every AOT concern aside from JSON. It was a lot simpler than I thought. #14637

  16. NCLnclNCL commented on Nov 19, 2024

    @NCLnclNCL

    Happy to contribute!

    I have a PR addressing every AOT concern aside from JSON. It was a lot simpler than I thought. #14637

    Hi,do you know anything about python, i want to convert python nodriver library to c#

  17. larsbloch commented on Nov 21, 2024

    @larsbloch

    Hi

    My current goal is to migrate my selenium project into a Native Aot application.

    I get errors when i start a new DevToolsSessions

    OpenQA.Selenium.WebDriverException: 'Unexpected error creating WebSocket DevTools session.'
    InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.

            var driver = new ChromeDriver();
            var devToolsSession = driver.GetDevToolsSession(); <- Error here
    

    I am not familie with the internals of Selenium but maybe you can tell me if my project is a lost cause or if the problems are going to be handled by some of the hard work you seem to be doing in regards to AOT ?

  18. nvborisenko commented on Nov 22, 2024

    @nvborisenko
    MemberAuthor

    GetDevToolsSession is not compatible with AOT yet, please track CDP section in the original post.

  19. nvborisenko commented on Feb 27, 2025

    @nvborisenko
    MemberAuthor

    @RenderMichael do you want to invest into CDP (DevTools) AOT compatibility? I don't want, BiDi is a priority for me.

  20. RenderMichael commented on Feb 27, 2025

    @RenderMichael
    Contributor

    @nvborisenko Per the tracking issue for depreciating CDP #13994:

    We'll still allow access to lower level CDP functionality (see #13990), but the high level approach will be removed.

    I interpret this to mean we will still keep the SendCommand method which takes a string commandName, and JsonNode commandParameters, with the JsonElement? response. Basically remove the strongly typed commands.

    For that reason, we shouldn't unnecessarily block AOT, especially since supporting it is so simple: #15159

  21. github-actions commented on Jan 12, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 14 days.

  22. added
    J-staleApplied to issues that become stale, and eventually closed.
    on Jan 12, 2026
  23. github-actions commented on Jan 26, 2026

    @github-actions
    Contributor

    This issue was closed because it has been stalled for 14 days with no activity.

  24. removed
    J-staleApplied to issues that become stale, and eventually closed.
    on Jan 26, 2026
  25. flucas1 commented on Jun 7, 2026

    @flucas1

    For my projects, I have found the flag JsonSerializerIsReflectionEnabledByDefault quite useful

    		<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
    

    Even if there are parts of the code using reflection, at lest I know the Json part is reflection free... and therefore AOT and trimming safe

  26. nvborisenko commented on Nov 7, 2026

    @nvborisenko
    MemberAuthor

    TLC proposed CDP is out of scope, even if PR provided.

    So this feature request will alive forever. Crossfingers we will be able to move on somehow.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions