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
[Feature] Intercepting responses #1774
Comments
Response interception is not currently available. This is something we can add in the future - no fundamental problems with having it. Could you share more about your use case? |
it would be useful for mock.
|
@hollligan does that code work in puppeteer? |
@Nisthar I didn't check it, I took it from the puppeteer documentation. for a playwright, here's the working code - |
It will be useful to troubleshoot scenario that pages are not fully loaded while running multiple tests in parallel in headless mode. |
Is it still not implemented ? |
Can't you just use: page.waitForResponse? I'm able to intercept responses for XHR requests (and parse it to JSON) like so: |
@onno-amsterdam correct me if I'm wrong but response = await page.waitForResponse will return the finalized response, while the question refers to modifying the response prior to it's consumption by the web app. |
This would definitely be helpful to use fixtures for repeating network requests. ⬆️ upvote from me. |
Playwright allows for route interception and mocking/stubbing.
|
Wow thanks @ThompsonJonM , think I'm pretty much sold on choosing Playwright over Cypress now. |
Upvote for this! |
Happened to meet a use case for this requirement. Our app makes a network call to get user settings, and certain other information as well. We need to modify only one setting out of the many returned by this call. We don't want to mock the entire response because It'll leave the other account details (returned as part of response) to be stale, over a period of time. So we were curious if there could be a way in which we can intercept the response and modify parts of it, before the web app consumes it. |
Any idea if this will be able to intercept responses from redirected requests? Hard blocked in my transition from puppeteer to playwright as I need to be able to intercept the request or response from a redirect. Use case is: Hit login screen => redirected to main entry page => I need to intercept that entry bundle to change some entry points to test different branches of code |
This feature is very useful ,hope to see it soon. |
I have a similar use case to @AnkitKSinha. Our use case would be to intercept that response and return only a few of the desired configs differently so we can automate different user scenarios. This would be a very useful feature for us. |
Same case as @AnkitKSinha mention, I would like to have the ability to intercept the response and just modify parts of that response |
Been poking through these commits - is there anything usable I can try out yet? I need to modify responses for the project I'm working on - if this is not available yet (or anytime soon) I might go ahead with a temporary solution, e.g. launching a built-in proxy server and connecting to that, which is kind of yuck. 🙂 |
You can give it try, see these tests for examples. The API is not final yet, so expect it to change but the functionality should be there. |
Fixed with the Fetch API that'll be released in 1.16 Docs: |
Hi, Did Modify Response feature support Java yet? I wonder that because the documentation isn't available for Java now. |
Does anybody know (or can point me in the right direction) on how to mock server side requests. I'm working on a next JS app and I would like to mock getServerSideProps requests. |
Note from maintainers: request interception and response mocking work in Playwright. See here for details.
Hey, I was wondering whether it is possible to intercept the response to a network request. I did notice the possibility of using routes to intercept the requests, but is it possible to get the response without re-sending the request manually? If so how? and would it work for HTTP data streams?
I've skimmed through the API docs but couldn't really find any specifics regarding intercepting the response.
The text was updated successfully, but these errors were encountered: