[Feature] Implement Modify responses
See original GitHub issueImplement Modify responses as available for Node.js https://playwright.dev/docs/network#modify-responses
Tried to ran below code with intent update response body and status only after request is completed but before it rendered on UI. The updated response was never served with below code. If I remove route.resume()
then requests were not triggering so I have to keep route.resume()
Example:
Browser browser = Playwright.create().chromium().launch(
new BrowserType.LaunchOptions().setDevtools(true).setHeadless(false));
Page page = browser.newContext().newPage();
page.onRequestFinished(request -> {
System.out.println("<< " +
request.response().statusText() + " " +
request.response().request().method() + " " +
request.response().url()
);
}
);
page.route("**/*", route -> {
route.resume();
System.out.println("After Route.Resume");
Response response = route.request().response();
route.fulfill(new Route.FulfillOptions()
.setStatus(500)
.setContentType("text/plain")
.setBody("Server Error")
);
System.out.println("After Route.fulfill");
});
page.navigate("https://www.google.com/");
page.fill("input[name='q']", "test");
page.keyboard().press("Enter");
Thread.sleep(3000);
browser.close();
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Modify Response - Requestly
Modify API responses to trigger different error paths in your codebase and test the flows without changing anything on backend.
Read more >Response Editing - Qualtrics
Editing Individual Responses · Click on the field you'd like to change. · Edit your response. · Click out of the field to...
Read more >Modifying Responses | REST API Handbook
This guide details how to add additional data to the responses of default endpoints using the register_rest_field and register_meta functions. You can use...
Read more >Modify HTTP responses from a Chrome extension
In general, you cannot change the response body of a HTTP request using the standard Chrome extension APIs. This feature is being requested...
Read more >10 Tips to Improve Your Feature Request Responses - Nicereply
Templates are great! We all use them. They're the best way to ensure that you have all of the information needed in response...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No,
apiRequestContext.fetch
that you mentioned is the only way.Thanks for the reply.
Using
page.context().request()
to get APIRequestContext insideroute
closure seems backward.Any way to auto wrap
route.request()
of type Request to APIRequestContext