playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Option to set Url on Route.FulfillAsync

Open thomhurst opened this issue 1 year ago • 0 comments

🚀 Feature Request

Route interception doesn't work with redirects, which is causing me some headaches.

I've got a near working solution, where I intercept the request, pass it through a custom HttpClient without automatic redirects, and if it's a redirect status code, I follow it through manually until it's not a redirect and then I fulfill the route with that final response.

The only problem is, as it's a redirect, the URL has changed. But FulfillAsync doesn't have an option to set the URL, so it still thinks its on the original URL before any redirects. There's assertions and waits in our tests for waiting for the URL to change, which are simply broken since it thinks it hasn't navigated to a new URL.

An optional URL property that would update on the browser, and also make sure Page.Url updates to keep all assertions/waits working would be ideal. If left null, just behave as you do currently where the URL doesn't change.

Example

                    var response = await GetResponse();

                    await route.FulfillAsync(new RouteFulfillOptions
                    {
                        // THIS LINE 👇
                        Url = response.RequestMessage?.RequestUri?.ToString(),

                        Status = (int)response.StatusCode,
                        Headers = response.GetHeaders(),
                        BodyBytes = await response.Content.ReadAsByteArrayAsync()
                    });

Motivation

It would enable working around intercepting redirects.

thomhurst avatar Dec 06 '24 11:12 thomhurst