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

[🐛 Bug]: Using CDP in multiple tabs #13300

Closed
grayglj opened this issue Dec 13, 2023 · 8 comments
Closed

[🐛 Bug]: Using CDP in multiple tabs #13300

grayglj opened this issue Dec 13, 2023 · 8 comments

Comments

@grayglj
Copy link

grayglj commented Dec 13, 2023

What happened?

Hi,To inspect network traffic, i use AttachToTarget to switch session between multiple tabs in chome, but the newly created session
always be bound with the last opened tab.

How can we reproduce the issue?

//fist: open google manually
//second:open manual stackoverflow
public void Test(ChromeDriver currentDriver)
{
    DevToolsSession originalSession = currentDriver.GetDevToolsSession();

    //google's taregetId xxxxxx1(ex) 
    //stackoverflow targetId: xxxxxx2(ex) 
    var allTargets = originalSession.Domains.Target.GetTargets().Result.Where(t => t.Type == "page").ToList();

    foreach (var target in allTargets)
    {
        currentDriver.CloseDevToolsSession();

        //newSession's ActiveSessionId and attachedTargetid are null now.
        var newSession = currentDriver.GetDevToolsSession();

        var attachResult = newSession.Domains.Target.AttachToTarget(target.TargetId).Result;

        //here,newSession's ActiveSessionId and attachedTargetid have value.
        //but the attachedTargetid always be same as xxxxxx2 which last opened in Chrome.
        string fordebug = "";
    }
}

Relevant log output

no logs.

Operating System

Windows 10

Selenium version

4.16.2

What are the browser(s) and version(s) where you see this issue?

Chrome 120.0.6099.71 (Official Build) (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 120.0.6099.71

Are you using Selenium Grid?

no

Copy link

@grayglj, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol
Copy link
Member

diemol commented Dec 13, 2023

I know that you need to create a new DevTools session per tab, I just do not know how to do that in C#.

@nvborisenko do you know how to do that?

@nvborisenko
Copy link
Member

Session implementation supposed to be initialized before creating new tabs in the browser. Behind of scene it attaches some unpredictable target (probably the latest one, hopefully the active one), and use auto-attach CDP feature. So then Session can "track" newly created targets.

More details about initialization: https://github.com/SeleniumHQ/selenium/blob/5b1b4490979a579716381a42f77ac5e4cf8f5e7b/dotnet/src/webdriver/DevTools/DevToolsSession.cs#L367C9-L367C9

                var targets = await this.domains.Target.GetTargets().ConfigureAwait(false);
                foreach (var target in targets)
                {
                    if (target.Type == "page")
                    {
                        this.attachedTargetId = target.TargetId;
                        LogTrace("Found Target ID {0}.", this.attachedTargetId);
                        break;
                    }
                }

@EdwinVanVliet tries to improve it, especially your case (network event monitoring for different tabs #10603).

@titusfortner titusfortner changed the title [🐛 Bug]: Session switch failed in multiple tag [🐛 Bug]: Using CDP in multiple tabs Dec 13, 2023
@titusfortner
Copy link
Member

@nvborisenko does #13330 fix this, then?

@nvborisenko
Copy link
Member

Potentially, not 100% sure. That PR brings a possibility to "pause" newly opened tab in browser. Will see.

@titusfortner
Copy link
Member

@nvborisenko is there something we know we want to do here beyond what we've done for 4.17?

@diemol
Copy link
Member

diemol commented Feb 28, 2024

The referenced PR was merged, and if something is still needed we can always reopen this issue.

@diemol diemol closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
Copy link

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.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants