Skip to content
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

Add methods for handling tabs in CDP Mode #3579

Closed
mdmintz opened this issue Mar 4, 2025 · 4 comments · Fixed by #3581
Closed

Add methods for handling tabs in CDP Mode #3579

mdmintz opened this issue Mar 4, 2025 · 4 comments · Fixed by #3581
Assignees
Labels
enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@mdmintz
Copy link
Member

mdmintz commented Mar 4, 2025

Add methods for handling tabs in CDP Mode

Up until now, CDP Mode hasn't had direct methods for simplifying the control of browser tabs. That's about to change. (One workaround has been to reconnect() to regular WebDriver to handle situations where tab-control is needed. Another workaround has been to call the async API indirectly.)

The following methods will be added to CDP Mode:

sb.cdp.switch_to_tab(tab)
sb.cdp.switch_to_newest_tab()
sb.cdp.close_active_tab()
sb.cdp.get_active_tab()
sb.cdp.get_tabs()

To prevent confusion, the following methods will also be added as duplicates (because the regular SB naming scheme uses those):

sb.cdp.switch_to_window(window)
sb.cdp.switch_to_newest_window()

Note that with sb.cdp.switch_to_tab(tab), tab can be either an integer representing the list location from sb.cdp.get_tabs(), or it can be the actual Tab object from the list. If the tab you wish to switch to is the newest opened tab, you can just call sb.cdp.switch_to_newest_tab().

Once implemented, it'll be easy to switch tabs if a website opens a new tab after an action is performed.

@mdmintz mdmintz added enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Mar 4, 2025
@mdmintz mdmintz self-assigned this Mar 4, 2025
@SSujitX
Copy link

SSujitX commented Mar 4, 2025

sb.cdp.switch_to_tab(tab)
sb.cdp.switch_to_newest_tab()
sb.cdp.close_active_tab()
sb.cdp.get_active_tab()
sb.cdp.get_tabs()

so we will get the tabs using sb.cdp.get_tabs() and put the tab value to sb.cdp.switch_to_tab(tab) to switch tab? and multiple tab as loop?

@mdmintz
Copy link
Member Author

mdmintz commented Mar 4, 2025

The tab can be the index of the list (integer), or the object itself (an item from sb.cdp.get_tabs())

@SSujitX
Copy link

SSujitX commented Mar 4, 2025

The tab can be the index of the list (integer), or the object itself (an item from sb.cdp.get_tabs())

Thanks <3

@mdmintz
Copy link
Member Author

mdmintz commented Mar 5, 2025

This was resolved in 4.35.3 - https://github.com/seleniumbase/SeleniumBase/releases/tag/v4.35.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making things better UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants