question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: CDP - Emulate network condition not applied for more than one browser tab

See original GitHub issue

What happened?

Hi, I wanted use CDP methods in my tests and I faced with command like Network.emulateNetworkConditions. In my tests Im using one chrome/edge instance for two different users - Client/Admin. For example, test opens first tab for client and second tab for admin. I wanted emulate network conditions, but this works only for second(last browser tab).

My expectations was: client(first tab) should has applied Network.emulateNetworkConditions(offline), but it was applied only for second tab(Admin). I tried get all targets and get first tab target and after that use method for AttachToTarget(firstTabTargetId), but this didnt work also.

Its bug or I dont understand how it works?

Thanks

How can we reproduce the issue?

Code for reproduce this issue.

[Test]
        public async Task SeleniumCdpTestForEmulateNetwork()
        {
            _driver.Navigate().GoToUrl("http://www.google.com");
            Thread.Sleep(2000);

            _driver = _driver.SwitchTo().NewWindow(WindowType.Tab);

            _driver.Navigate().GoToUrl("http://stackoverflow.com");
            Thread.Sleep(2000);

            var session = (_driver as IDevTools).GetDevToolsSession();

            var commandParams = new JObject(
                new JProperty("offline", true),
                new JProperty("latency", 0),
                new JProperty("downloadThroughput", -1),
                new JProperty("uploadThroughput", -1));

            await session.Domains.Network.EnableNetwork();
            await session.SendCommand("Network.emulateNetworkConditions", commandParams);

            _driver.SwitchTo().Window(_driver.WindowHandles[0]);
        }

Relevant log output

No logs for this behaviour.

Operating System

Windows 10

Selenium version

Selenium.WebDriver 4.4.0 / netcoreapp3.1

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

Chrome 105.0.5195.102

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

ChromeDriver 105.0.5195.1900

Are you using Selenium Grid?

No

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
titusfortnercommented, Nov 17, 2022

Oops, I mis-tagged this, sorry! Thanks for looking @TamsilAmani

1reaction
diemolcommented, Nov 13, 2022

You are right, @TamsilAmani, the code is .NET.

If you have time, any help triaging issues is appreciated 🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium 4: Chrome DevTools Protocol [What's New]
In this post, we will discuss one of the most anticipated features of Selenium 4 which is the new APIs for CDP (Chrome...
Read more >
Network domain - Chrome DevTools Protocol - GitHub Pages
Network domain allows tracking network activities of the page. It exposes information about http, file, data and other requests and responses, their headers ......
Read more >
Event-driven Testing | BrowserStack Docs
Selenium 4 uses Chrome Debugging Protocol (CDP) to achieve event-driven testing ... Register basic auth; Emulate geolocation; Emulate network conditions ...
Read more >
chromedp - Go Packages
Package chromedp is a high level Chrome DevTools Protocol client that simplifies driving browsers for scraping, unit testing, or profiling ...
Read more >
Chrome DevTools
Learn how to use Chrome DevTools to find and fix JavaScript bugs. ... Open the Network conditions tab, disable Select automatically, and choose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found