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] Support predicate receiving Request interface to match while routing in page.route(url, handler)

See original GitHub issue

Continuation of #6199 In my project we use GraphQL where all requests have the same URL but differs only in body. In order to use page.route(url, handler) I have to first retrieve body of request and make some checks if this is the request I am looking for. This function page.route(url, handler) does not support predicate with Request interface which makes impossible to stub requests when using GraphQL.

I envision it like this:

    async routeFindingRequests(stringToSearch) {
        
        // request instead of URL here
        await this.page.route(request => {
           return request.postData().includes(stringToSearch)
        }, route => {
            route.fulfill({
                body: JSON.stringify({
                    someKey: "someValue"
                })
            })
        })
    }

I would like to ask you to add the ability to work with request in addition to URL in page.route(url, handler) as this is blocker for using playwright.

P.S. Initially I thought there is a need to have async predicate but I see almost all functions are synchronous in Request interface. Thus I made a change above.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Kremliovskyicommented, Apr 25, 2021

@dgozman It is working flawlessly. I suggest that you add your example to documents and close this ticket, no need to implement my suggestion.

1reaction
dgozmancommented, Apr 23, 2021

While there are no plans to add support for this, you can just route all the requests and call continue() vs fulfill():

await page.route('**/*', route => {
  if (route.request().postData().includes(stringToSearch))
    route.fulfill({ body: 'Some body' });
  else
    route.continue();
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question] How to wait for several responses that differs only ...
[Feature] Support predicate receiving Request interface to match while routing in page.route(url, handler) #6243.
Read more >
Spring Cloud Gateway
Spring Cloud Gateway matches routes as part of the Spring WebFlux HandlerMapping infrastructure. Spring Cloud Gateway includes many built-in route predicate ...
Read more >
BrowserContext (Playwright - Main Library 1.21.0 API) - javadoc.io
public interface BrowserContext extends AutoCloseable ... Page.route() ) take precedence over browser context routes when request matches both handlers.
Read more >
URL Dispatch — The Pyramid Web Framework v2.0
A route predicate argument specifies that some aspect of the request must be true for the associated route to be considered a match...
Read more >
HTTP route components (proto) - Envoy Proxy
A route is both a specification of how to match a request as well as an indication of what to do next (e.g.,...
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