commit 455079d3374cb999cf084283b4b13624c2d9a955
parent a47d39273b6ef4834e5351ef28be836e0a86d9a2
Author: Julian Descottes <jdescottes@mozilla.com>
Date: Thu, 16 Oct 2025 08:10:38 +0000
Bug 1992210 - [bidi] Support network.getData for requests using the data scheme r=webdriver-reviewers,Sasha
Adds support for retrieving the response body of requests using the data scheme via WebDriver BiDi data collection.
This closes a gap with the current spec, and with the chromium implementation. Implementation wise, the approach is similar to DevTools and we just process the data url to extract the body.
Differential Revision: https://phabricator.services.mozilla.com/D267404
Diffstat:
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/remote/shared/NetworkResponse.sys.mjs b/remote/shared/NetworkResponse.sys.mjs
@@ -100,6 +100,10 @@ export class NetworkResponse {
return this.#fromServiceWorker;
}
+ get isDataURL() {
+ return this.#isDataURL;
+ }
+
get mimeType() {
return this.#getComputedMimeType();
}
@@ -247,10 +251,11 @@ export class NetworkResponse {
toJSON() {
return {
decodedBodySize: this.decodedBodySize,
- headers: this.headers,
- headersTransmittedSize: this.headersTransmittedSize,
encodedBodySize: this.encodedBodySize,
fromCache: this.fromCache,
+ headers: this.headers,
+ headersTransmittedSize: this.headersTransmittedSize,
+ isDataURL: this.isDataURL,
mimeType: this.mimeType,
protocol: this.protocol,
serializedURL: this.serializedURL,
diff --git a/remote/webdriver-bidi/modules/root/network.sys.mjs b/remote/webdriver-bidi/modules/root/network.sys.mjs
@@ -9,6 +9,9 @@ import { RootBiDiModule } from "chrome://remote/content/webdriver-bidi/modules/R
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
+ NetworkHelper:
+ "resource://devtools/shared/network-observer/NetworkHelper.sys.mjs",
+
assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
CacheBehavior: "chrome://remote/content/shared/NetworkCacheManager.sys.mjs",
error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
@@ -2185,13 +2188,12 @@ class NetworkModule extends RootBiDiModule {
return;
}
- if (!(response instanceof lazy.NetworkResponse)) {
+ if (!(response instanceof lazy.NetworkResponse) && !response.isDataURL) {
lazy.logger.trace(
`Network data not collected for request "${request.requestId}" and data type "${DataType.Response}"` +
- `: unsupported response (data scheme or cached resource)`
+ `: unsupported response (read from memory cache)`
);
// Cached stencils do not return any response body.
- // TODO: Handle response body for data URLs.
collectedData.pending = false;
collectedData.networkDataCollected.resolve();
this.#collectedNetworkData.delete(
@@ -2247,10 +2249,26 @@ class NetworkModule extends RootBiDiModule {
// body. Since this is handled by the DevTools NetworkResponseListener, so
// here we wait until the response content is set.
try {
- const bytesOrNull = await response.readResponseBody();
- if (bytesOrNull !== null) {
- bytes = bytesOrNull;
- size = response.encodedBodySize;
+ if (response.isDataURL) {
+ // Handle data URLs as a special case since the response is not provided
+ // by the DevTools ResponseListener in this case.
+ const url = request.serializedURL;
+ const body = url.substring(url.indexOf(",") + 1);
+ const isText =
+ response.mimeType &&
+ lazy.NetworkHelper.isTextMimeType(response.mimeType);
+ // TODO: Reuse a common interface being introduced in Bug 1988955.
+ bytes = {
+ getDecodedResponseBody: () => body,
+ encoding: isText ? null : "base64",
+ };
+ size = body.length;
+ } else {
+ const bytesOrNull = await response.readResponseBody();
+ if (bytesOrNull !== null) {
+ bytes = bytesOrNull;
+ size = response.encodedBodySize;
+ }
}
} catch {
// Let processBodyError be this step: Do nothing.