Skip to content

[Feature] Support predicate receiving Request interface to match while routing in page.route(url, handler)  #6243

@Kremliovskyi

Description

@Kremliovskyi

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions