Skip to content

Conversation

hbenl
Copy link
Contributor

@hbenl hbenl commented Aug 29, 2025

Fixes #37218 and (at least) the following tests in Firefox:

  • tests/library/browsercontext-base-url.spec.ts:
    • "should be able to match a URL relative to its given URL with urlMatcher"
  • tests/library/browsercontext-credentials.spec.ts:
    • "should return resource body"
  • tests/library/browsercontext-har.spec.ts:
    • "should update extracted har.zip for page"
    • "should update har.zip for context"
    • "should update har.zip for page"
    • "should update har.zip for page with different options"
  • tests/library/browsertype-connect.spec.ts:
    • "launchServer > should fulfill with global fetch result"
    • "run-server > should fulfill with global fetch result"
  • tests/library/har.spec.ts:
    • "should attach content"
    • "should contain http2 for http2 requests"
    • "should include content smoke"
    • "should use attach mode for zip extension"
  • tests/page/frame-goto.spec.ts:
    • "should return matching responses"
  • tests/page/page-event-request.spec.ts:
    • "should return response body when Cross-Origin-Opener-Policy is set"
  • tests/page/page-history.spec.ts:
    • "page.reload should not resolve with same-document navigation"
  • tests/page/page-network-response.spec.ts:
    • "should return text"
    • "should return uncompressed text"
    • "should wait until response completes"
    • "should return json"
    • "should return body"
    • "should return body with compression"
    • "should return body for prefetch script"
  • tests/page/page-request-fallback.spec.ts:
    • "should not chain fulfill"
    • "should chain once"
  • tests/page/page-request-fulfill.spec.ts:
    • "should fulfill with global fetch result"
    • "should fulfill with fetch result"
    • "should fulfill with fetch result and overrides"
    • "should return body for fulfilled responses"
  • tests/page/page-request-intercept.spec.ts:
    • "should fulfill with any response"
    • "should intercept with url override"
    • "should support fulfill after intercept"
  • tests/page/workers.spec.ts:
    • "should report worker script as network request"
    • "should report worker script as network request after redirect"

This comment has been minimized.

}

async updateNetworkDataCollection() {
await this._networkManager.setDataCollection(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just inline this call as there is only one call site of the method.

if (enable) {
if (!this._dataCollectorId) {
const dataTypes: [bidi.Network.DataType] = [bidi.Network.DataType.Response];
const maxEncodedDataSize = maxSize ?? 10_000_000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it 200Mb to match Chromium constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set it to 20_000_000 as per this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this._dataCollectorId = collector;
}
} else {
if (this._dataCollectorId) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch is never reached, let's drop it.

await this._updateProtocolRequestInterception();
}

async setDataCollection(enable: boolean, maxSize?: number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the method into initialize() and remove all the if checks, we want the resource collection to be be enabled and done so during the setup phase.

Also if we don't have to pass collector to network.getData, there is no need to store in the network manager. Let's keep only the code/data that is actually used.

return;
const getResponseBody = async () => {
throw new Error(`Response body is not available for requests in Bidi`);
const { bytes } = await this._session.send('network.getData', { request: params.request.request, dataType: bidi.Network.DataType.Response });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to also pass collector parameter?

Copy link
Member

@yury-s yury-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up, #37321 is adding the same functionality.

This comment has been minimized.

const dataTypes: [bidi.Network.DataType] = [bidi.Network.DataType.Response];
const maxEncodedDataSize = 20_000_000;
const contexts: [string] = [this._session.sessionId];
await this._session.send('network.addDataCollector', { dataTypes, maxEncodedDataSize, contexts });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we do it per page, rather than initialize once per browser session as in https://github.com/microsoft/playwright/pull/37321/files#diff-8753d59ba95abdc3367549f4caf85cbe4fa7b702d4f94427301bc9eadf4e79e1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, I've updated the PR to do it once per session.

@yury-s yury-s merged commit 4dd1949 into microsoft:main Sep 10, 2025
34 of 37 checks passed
Copy link
Contributor

Test results for "tests 1"

5 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1079 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node18`
⚠️ [firefox-library] › library/inspector/cli-codegen-pick-locator.spec.ts:35 › should update locator highlight `@firefox-ubuntu-22.04-node18`
⚠️ [chromium-library] › library/chromium/oopif.spec.ts:374 › should allow to re-connect to OOPIFs with CDP when iframes were there already `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:80 › should show console messages for test `@ubuntu-latest-node22-1`
⚠️ [playwright-test] › ui-mode-trace.spec.ts:637 › should indicate current test status `@ubuntu-latest-node24-1`

45357 passed, 816 skipped


Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Implement fetching response bodies for WebDriver BiDi
2 participants