-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[🚀 Feature]: BiDi: Add low-level helper method to subscribe/unsubscribe from events #14201
Comments
@Mr0grog, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
I'm not sure I'm following your concern. The BiDi classes are all private API (I thought I'd marked them as such, need to add that). The plan is to provide nice wrapper methods to access everything. That means we are assuming that the driver is the source of truth and storing state. Users should never need to call Subscribing/unsubscribing happens automatically when you use the API:
So we'll probably have something like (domains and method names tbd):
|
Ah, I guess this was my fundamental misunderstanding:
I assumed the low-level API was meant to be available for cases the high-level stuff does not (yet) cover, or when new BiDi stuff eventually shows up in various drivers before high-level wrappers show up, or as a general escape hatch from the way something is handled in the high-level wrappers (calling the wrappers "high-level API" all over the place also implied to me that there is meant low-level API to drop down to in this way). Seeing all the discussion around deprecating devtools, etc. (both here and from vendors, e.g. https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/) suggested to me that I should be getting started with BiDi. Since there is hardly any high-level coverage, I thought I was supposed to be using the low-level stuff for now. Is the actual intent that I should just not use BiDi yet? (Excepting very narrow use cases that have been covered.) |
This is also true! We want the classes to be available if someone wants to dig in and do interesting things (and then tell us that their use case should have a high-level API to make it easier). So, with that in mind, if there is something we can make easier in the low-level API as we build it out, we should do so. We've only got one implementation so far, so I'm assuming there are going to be some additional abstractions we'll be able to make to share patterns, and I just don't know them, yet. |
@Mr0grog would love to discuss more on Slack/Matrix/IRC - https://www.selenium.dev/support/#ChatRoom |
This issue is stale because it has been open 280 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 14 days with no activity. |
I should have commented earlier here, but one of the sticking points is that this area of the spec has been under pretty active revision (for example, this PR just landed in the past day: w3c/webdriver-bidi#867). There have been several PRs and changes around event subscription in the spec over the past month or two, so it seems like there is a lot of instability in this area right now. I think there’s plenty that could be done given the original way it worked (which I think is still supported in the spec and I assume will continue to be now that there are multiple shipping implementations of it), although now there are things like subscription IDs that you can subscribe and unsubscribe to. Those subscription IDs may take care of some aspects of this issue, but I’m not 100% clear on how it works if you have multiple subscription IDs involving the same (context/navigable + event). I am also not clear on what implementors are doing/planning, given the active spec changes in this area. 🤷 |
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs. |
Feature and motivation
I’ve started playing around with the BiDi support in the Ruby webdriver, and have noticed that subscribing to and unsubscribing from events is fairly complicated: you need to keep track of the event callbacks that have been added to the session (including by other actors) so you know whether to send a
session.subscribe
/session.unsubscribe
command alongside adding/removing your callback.For example, the Ruby
LogHandler
does this:selenium/rb/lib/selenium/webdriver/bidi/log_handler.rb
Lines 44 to 59 in 164bf79
The Python source follows a similar pattern in
Script
:selenium/py/selenium/webdriver/common/bidi/script.py
Lines 38 to 52 in 164bf79
I don’t know if this is a pattern that has crept in or a standard design/set of interfaces that are expected to exist across all the languages. Either way, having the subscriber need to keep track of who else might be subscribed seems like a problem — it adds a bit of complexity everywhere events are used and it’s easy to mess up if a user needs to listen to events that aren’t currently handled by a higher-level wrapper.
It would be really helpful if there were a
subscribe
orlisten_to_event
or some similar method (plus the corresponding unsubscribe method) on the low-level BiDi API that adds your callback and callssession.subscribe
/session.unsubscribe
as appropriate, e.g:(
BiDi
seems like the obvious place to put this level of abstraction in Ruby, but the Python library currently has nothing sitting in-between the higher-level APIs likeScript
and the actual websocket connection. I have not looked at the other language packages.)Usage example
Currently, subscribing/unsubscribing to BiDi events requires code like (this is Ruby, but it’s similar in Python and maybe other languages):
Ideally, subscribing/unsubscribing would be one-liners without any conditionals:
Even nicer if allows filtering by context, but maybe not as critical?
The text was updated successfully, but these errors were encountered: