w3c / webdriver-bidi

Bidirectional WebDriver protocol for browser automation
https://w3c.github.io/webdriver-bidi/
336 stars 35 forks source link

Ability to detect "active" browsing context #585

Open Danp2 opened 8 months ago

Danp2 commented 8 months ago

In Webdriver classic, we have get-window-handle, but there doesn't appear to be an equivalent command in the current BiDi spec. See recent discussion here.

Would it be feasible to add a field to browsingContext.getTree that would indicate the active tab?

jimevans commented 8 months ago

@Danp2 So just to clarify and be a bit pedantic, what do you mean by "active" tab? There is nothing in the WebDriver Classic spec that defines the "active tab" to be the one with the "focus" in the operating system/window manager. All it indicates is the tab against which commands should be directed. While it's true that the window handle returned by the "get window handle" command often is the one with the OS focus, it's not required. In point of fact, it's not even required by the spec to be the "active tab" in a browser that supports tabbed browsing. If you're looking for something to tell you definitively which tab/window has the OS focus, that probably won't be in scope for the WebDriver specification.

Danp2 commented 8 months ago

@jimevans Good point. In WD Classic, Switch to Window includes the following note --

Switching window will select the current top-level browsing context used as the target for all subsequent commands. In a tabbed browser, this will typically make the tab containing the browsing context the selected tab.

I am the maintainer of a set of AutoIt UDFs that I would like to eventually support WD BiDi. For backward compatibility, I was hoping to mimic the above behavior by using the "target" BC for BiDi requests if one isn't specified by the calling routine.

whimboo commented 8 months ago

So I think that we actually have to differentiate about which browsing context we talk about. What the request basically wants is that we can check which of the open tabs (whether in which window) is the active one. And hereby we most likely want to set the flag for that top-level browsing context that is part of the top-most window.

Regarding WebDriver classic we indeed always select and focus the tab that the Switch To Window command switches to. Only for internal Firefox testing we have an option to keep the current tab the focused (active) one. Please remember that if we would run tests in a background tab those would have to cope with throttling, which is not wanted.

If we don't want to have such an optional active flag as part of the BrowsingContext.Info type, it would require at maximum x-amount of script.evaluate commands (one for each open tab) with a check if that tab is selected in the top-most window.