flood-io / element

💦Load test your app using real web browsers
https://element.flood.io
Apache License 2.0
350 stars 43 forks source link

Allow Request Interceptors / event listeners to be used on the browser object #593

Closed justinfiore closed 1 year ago

justinfiore commented 1 year ago

Is your feature request related to a problem? Please describe.

In Playwrights Page object (which supposedly the "browser" is a wrapper around in Element 2.x) you can add request interceptors for events request, requestfinished requestfailed.

This is helpful for: a) Logging out request and response info to help debug what is going on b) Manipulating the request before it is sent out. (for example, conditionally adding request headers based on the target domain of the request.

Describe the solution you'd like

Allow usage of the "on" function to register interceptors on the underlying Page. There are many other events besides the 3 I described above. So being able to register listeners on all of them would be great. See Page docs here: https://playwright.dev/docs/api/class-page#page-event-request

Describe alternatives you've considered

I tried to use browser.setExtraHttpHeaders, but since not all of my domains accept the extra HTTP headers, many requests fail. Also, this doesn't help the debugging case.

Additional context In general, allowing access to the underlying page object to access anything that Playwright supports would be awesome, as we already have many selectors written in a format that Playwright supports and we are needing to translate them to Flood's locator syntax.

justinfiore commented 1 year ago

After looking at the code for Browser.ts, it looks like I can do: browser.page.on

justinfiore commented 1 year ago

I was able to figure this out by using browser.page.on and browser.page.route