Skip to content

How to listen XHR logs of later opened new window #3782

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

Closed
muffinweb opened this issue May 29, 2025 · 1 comment
Closed

How to listen XHR logs of later opened new window #3782

muffinweb opened this issue May 29, 2025 · 1 comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@muffinweb
Copy link

muffinweb commented May 29, 2025

I use raw_xhr_sb.py sample to listen xhr logs but in specific scenario a new window pop-up comes in and i need to listen xhr logs of new window (pop-up)

Pop-up window occurs when search button is clicked in related website. Any instantly start xhr request background

i can switch pop-up window using sb.switch_to_newest_window() method but can't listen it. I wonder is it possible?

@mdmintz mdmintz added question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels May 29, 2025
@mdmintz
Copy link
Member

mdmintz commented May 29, 2025

As in the raw_xhr_sb.py example you have to call listenXHR(tab) on the new window after switching to it.

The only issue that might arise from that is if all the XHR data is sent before you've had a chance to switch to the new window and listen for the XHR data. In that case, you could attempt to go offline the moment the pop-up window appears (or directly before triggering the action that opens the pop-up). This would allow time to set up the listener for XHR requests. There are a few different ways to control online status. Eg: https://github.com/SeleniumHQ/seleniumhq.github.io/blob/93f5c83c59316c244e4a2fa8c616c9a4cf1b1f1c/examples/python/tests/browsers/test_chrome.py#L129-L135, using sb.driver.set_network_conditions() with the right parameters, or by using the Chrome Devtools Protocol: cdp.Network.emulateNetworkConditions.

@mdmintz mdmintz closed this as completed May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants