Skip to content

Change request url path by RequestHook doesn't work #8409

@JakubMaz

Description

@JakubMaz

What is your Scenario?

I want to change request url path by RequestHook. I need to add extra query param.

What is the Current behavior?

When I set event.requestOptions.path in RequestHook with the new value, I still see the old url in the browser network.

What is the Expected behavior?

In browser network I'd like to see updated request url

What is your TestCafe test code?

// custom hook
class ExtraParamHook extends RequestHook {
    async onRequest(event) {
        const url = new URL(event.requestOptions.url);
        if (url.pathname.includes('/drm/')) {
            url.searchParams.set('test', Date.now().toString());

            event.requestOptions.path = `${url.pathname}${url.search}`;
        }
    }
    onResponse() { /* empty */ }
}

const addExtraParams = new ExtraParamHook();

// in fixture:
fixture`...`
    .page(...)
    .requestHooks(addExtraParams)

TestCafe version

3.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    TYPE: bugThe described behavior is considered as wrong (bug).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions