Skip to content

[🐛 Bug]: BiDi WebSocket connections are established at different points across Selenium bindings #18258

Open

Description

@nvborisenko

Description

Java: during session creation, when the returned capabilities include webSocketUrl.
Ruby: during session creation when BiDi is enabled.
Python: lazily, when a BiDi-backed feature is first accessed.
JavaScript: lazily, on first BiDi access.
.NET: explicitly via AsBiDiAsync().

Let’s discuss these differences and decide whether the connection lifecycle should be aligned across bindings.

Reproducible Code

var driver = new Chrome(with websocketurl enabled) // establish connection here? if not success then what?
driver.DoSomethingBiDiRequired() // or here?

Activity

  1. added
    I-defect
    A-needs-triaging
    on Oct 28, 2026
  2. selenium-ci commented on Oct 28, 2026

    @selenium-ci
    Member

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

    Selenium Triage Team: remember to follow the Triage Guide

  3. titusfortner commented on Oct 28, 2026

    @titusfortner
    Member

    I think this is an easy one. There are going to be several features that are going to require async handlers or pin scripts that need to run when the session starts, not whenever the first BiDi command happens. So JS & Python should be updated, and we already decided against setting the mode explicitly in #17670

  4. AutomatedTester commented on Oct 28, 2026

    @AutomatedTester
    Member

    How is lazy loading on first command going to be different to eager connection?

  5. nvborisenko commented on Oct 29, 2026

    @nvborisenko
    MemberAuthor

    It depends on use cases..

    1. Eager connection with WebSockerUrl=true
    var driver = new Chrome(bidi_enabled=true); // BOOM if remote end doesn't support bidi
    

    It makes a connection once, no ceremonies around lazy-initialization. Performant. But what to do for remote-ends what doesn't support BiDi. If we go this way, we should raise an exception. Like currently Safari doesn't return correct websocket url when bidi_enabled. It means all users that requested bidi_enabled will be broken. I think it is still good. Users requests capability, remote end doesn't support it, we honestly say about it.

    1. Lazy init
      No attempts to establish a connection at all. User requests bidi_enabled, we are fine. If user uses classic only commands, he is fine.
      But it adds ceremony for us and user's performance:
    driver.DoSomethingWhichRequiresBiDiCommand()
    {
      var bidi = GiveMeBiDiAndConnectIfNotYetConnected(); // this line of code should be thread-safe, and we should put this line into any WebDriver method
      bidi.SendRealCommand();
    }
    

    Personally I feel it is better make a websocket connection once supposing it must be made successfully. And fail fast. It avoids "thread-safe lazy init" on each user's command. For users, who gets an exception like "we tried establish a connection but seems your browser doesn't support it" we can say don't request bidi_enabled capability (UseWebsocketUrl=true).

    Just opinion, I don't see entire picture and further plans.

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

    A-needs-triagingI-defect

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions