-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
#16645 switch DevTools connection between tabs/windows #16647
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
#16645 switch DevTools connection between tabs/windows #16647
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||
Temporarily commit the fixed version of DevTools.java from SeleniumHQ/selenium#16647 which hopefully will be released in Selenium 4.39.0.
Temporarily commit the fixed version of DevTools.java from SeleniumHQ/selenium#16647 which hopefully will be released in Selenium 4.39.0.
1. When `createSessionIfThereIsNotOne(tab1)` is called, CDP session is opened - and attached to the first tab. 2. When `createSessionIfThereIsNotOne(tab2)` is called, we detach connection from the first tab, and attach to the second tab (a new CDP session ID is created). An alternative solution would be holding map of CDP sessions for all existing tabs. But ChatGPT suggested that it's not worth it: operations `attachTarget`/`detachTarget` are very fast (less than 1ms).
…ontains" * windowHandle has form "24426957AC62D8BC83E58C184C38AF2D", while * targetID has form "CDwindow-24426957AC62D8BC83E58C184C38AF2D"
2ca3e71 to
e90c246
Compare
this is a patched version of DevTools.java from SeleniumHQ/selenium#16647
User description
createSessionIfThereIsNotOne(tab1)is called, CDP session is opened - and attached to the first tab.createSessionIfThereIsNotOne(tab2)is called, we detach connection from the first tab, and attach to the second tab (a new CDP session ID is created).🔗 Related Issues
Fixes #16645
🔧 Implementation Notes
Current implementation holds only one CDP session at a time.
When user wants to switch to other tab, the previous CDP session gets closed.
An alternative solution would be holding map of CDP sessions for all existing tabs.
But ChatGPT suggested that it's worth it: every
attachTargetanddetachTargetis very fast (less than 1 ms), so holding multiple sessions would not give any benefit in speed.🔄 Types of changes
PR Type
Bug fix
Description
Switch DevTools CDP session between tabs/windows dynamically
Track current window handle to detect tab switches
Disconnect from previous tab and attach to new tab
Refactor session attachment logic into separate methods
Diagram Walkthrough
File Walkthrough
DevTools.java
Implement dynamic DevTools tab switching with session managementjava/src/org/openqa/selenium/devtools/DevTools.java
windowHandlefield to track current tab/window connectioncreateSessionIfThereIsNotOne()to detect tab switches andreconnect
attachToWindow()andattachToTarget()methods@Nullableand@NonNullannotations for better null-safetywindowHandlewhen disconnecting session