Skip to content

[🚀 Feature]: [bidi] Multiple scoped event listeners/handlers #16604

@nvborisenko

Description

@nvborisenko

Description

Writing here just to demonstrate how event listeners/handlers work currently and what are hidden stones when dealing with BiDi events (at least in .NET).

I am able to subscribe:

// here I want to listen all network events for specific context
await bidi.Network.OnBeforeRequestSentAsync(Console.WriteLine, new() { Contexts = [context1] });

// here I want to listen all network events for some another context
await bidi.Network.OnBeforeRequestSentAsync(Console.WriteLine, new() { Contexts = [context2] });

It works gracefully in .NET because on client side we filter out events by context, so we know what handler/listener is interested in. Internally we associate a handler with context(s).

It also works when we are in context implicitly:

// here "context" is BrowsingContext type
await context.Network.OnBeforeRequestSentAsync(Console.WriteLine); // this handler will be invoked only when remote-end sends event for this context

Problem 1

This approach is based on assumption that all event params are contextual (might have contextID). But in reality -- NO. For instance LogEntryAdded event never contains context.

Problem 2

We forgot about UserContext!

await bidi.Network.OnBeforeRequestSentAsync(Console.WriteLine, new() { UserContexts = [someUserContext1] });

Here we say that I want to listen to all BeforeRequestSent only for someUserContext1. Then on client side (Selenium) it is impossible, because event params doesn't contain any info about userContext.

Have you considered any alternatives or workarounds?

I proposed a solution to be resolved on remote-end: w3c/webdriver-bidi#1032

Hopefully events will be significantly simplified. Like unsubscribing was already significantly simplified. And we will have an ability to invoke handlers only and only if handler is interested in this event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-dotnet.NET BindingsI-enhancementSomething could be better

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions