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

[Question] CDP sessions with other targets #4286

Closed
Altneuj opened this issue Oct 29, 2020 · 3 comments
Closed

[Question] CDP sessions with other targets #4286

Altneuj opened this issue Oct 29, 2020 · 3 comments

Comments

@Altneuj
Copy link

Altneuj commented Oct 29, 2020

Hello! I am working on some E2E tests using playwright transitioning over from puppeteer.

In the puppeteer test we find the service worker target via page.browser().targets() and find by type. After finding the service worker target we open a CDPSession with it serviceWorkerTarget.createCDPSession and can then send different protocols directly to it such as a Network.emulateNetworkConditions.

With playwright I am able to create a CDPSession with the playwright page and can see the service worker target and targetId when sending Target.getTargets, however I am unable to set up a session directly with the service worker after this. I have tried Target.AttachToTarget with the service worker targetid but don't see a way to use that session directly. Any idea how I could set up a CDP session directly with service worker?

I have also tried using WebSocket directly via this guide https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md however I am getting a target closed error when attempting to Target.getTargets am not sure if playwright chromium instance is doing some sort of blocking there.

Thank you!

@arjunattam
Copy link
Contributor

Thanks for the report @Altneuj. Playwright APIs are different to accommodate cross-browser support. I would encourage not using CDP, since it is a moving target and incompatible with other browsers.

We could consider Playwright API support for the protocol messages. Emulating network conditions was discussed in #3393. If this sounds valuable, it would be useful to know what protocol messages are sent over CDP and find Playwright API equivalents.

If using CDP is a hard requirement, we would need to explore accepting targetId in addition to pages.

@Altneuj
Copy link
Author

Altneuj commented Oct 29, 2020

Wow, thank you for such a quick response. CDP was just the easiest as that is how we had it with puppeteer. I will look into other options as it makes sense not to have something that isn't supported by all browsers. Thanks!

@Altneuj Altneuj closed this as completed Oct 29, 2020
@muhqu
Copy link
Contributor

muhqu commented Sep 12, 2023

@Altneuj I'm having the same problem. I like to establish a CDPSession with a service worker in order to send Network.emulateNetworkConditions. Did you find a workaround? …throttling via Charles proxy or other HTTP proxies brings additional complexity which I like to avoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants