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.

[Feature] Implement Modify responses

See original GitHub issue

Implement 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, Jan 26, 2022

No, apiRequestContext.fetch that you mentioned is the only way.

0reactions
easyreprocommented, Jan 26, 2022

Thanks for the reply.

Using page.context().request() to get APIRequestContext inside route closure seems backward.

Any way to auto wrap route.request() of type Request to APIRequestContext

Read more comments on GitHub >

github_iconTop 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 >

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