SeleniumHQ / SeleniumHQ/selenium

[🚀 Feature]: [BIDI] Add commands to retrieve req/rsp bodies

Open
#16,514 14 comments 1 reaction 0 assignees View on GitHub
B-devtools I-enhancement
Dominant language
Java
Stars
34.5k
Forks
8.7k
Avg merge
2d 1h
Merged PRs (30d)
92

Description

### Description

**Feature and motivation**
Selenium already has some Network Intercept BiDi APi which is given in the [example of BiDi API](https://www.selenium.dev/documentation/webdriver/bidi/w3c/network/). However, this API can only be used to deal with some meta-data and headers. At the moment I must rely on CDP to inspect the payload.

I would be grateful and it would help me a great deal to have a true cross-browser implementation that makes use of the [WebDriver BiDi spec](https://w3c.github.io/webdriver-bidi/) that can now capture the request/response with header and body.

**Usage example**
Implement something similar to getUrl() or getHeaders(); but to get the payload of a request / response.
e.g. #java
```
// Listener für Request & Response:
network.onBeforeRequestSent(request -> {
System.out.println("REQUEST URL: " + request.getRequest().getUrl());
System.out.println("REQUEST HEADERS: " + request.getRequest().getHeaders());
System.out.println("REQUEST BODY: " + request.getRequest().getBody());
});
network.onResponseStarted(response -> {
System.out.println("RESPONSE URL: " + response.getResponseData().getUrl());
System.out.println("RESPONSE HEADERS: " + response.getResponseData().getHeaders());
System.out.println("RESPONSE BODY: " + response.getResponseData().getBody());
});

```
It is now supported in:

- the sepc: [network.addDataCollector](https://w3c.github.io/webdriver-bidi/#command-network-addDataCollector) and [network.getData](https://w3c.github.io/webdriver-bidi/#command-network-getData)
- Firefox 143:
- - https://bugzilla.mozilla.org/show_bug.cgi?id=1971780
- - https://bugzilla.mozilla.org/show_bug.cgi?id=1971778
- Chrome: https://github.com/GoogleChromeLabs/chromium-bidi/blob/main/src/bidiMapper/modules/network/NetworkStorage.ts#L518

**More information**
https://github.com/SeleniumHQ/selenium/issues/16261
https://github.com/SeleniumHQ/selenium/issues/11872
https://github.com/w3c/webdriver-bidi/issues/958
https://github.com/w3c/webdriver-bidi/pull/877
https://github.com/w3c/webdriver-bidi/pull/1011
fyi: @TamsilAmani @titusfortner

### Have you considered any alternatives or workarounds?

I tried to use `devTools.send` and `devTools.addListener` but was not able to get it to work in Firefox (only Chrome), using BIDI to get the url in both worked but I'm looking for a cross-browser way of inspecting the body of request/responses.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.