@@ -20,7 +20,7 @@ const makeRequest = (
2020 readonly headers ?: Record < string , string > ;
2121 readonly postData ?: string ;
2222 readonly errorText ?: string ;
23- readonly responseBodySize ?: number ;
23+ readonly responseBodySize ?: number | null ;
2424 } = { } ,
2525) => ( {
2626 url : ( ) => url ,
@@ -29,9 +29,10 @@ const makeRequest = (
2929 headers : ( ) => options . headers ?? { } ,
3030 postDataBuffer : ( ) => ( options . postData === undefined ? null : Buffer . from ( options . postData ) ) ,
3131 failure : ( ) => ( options . errorText === undefined ? null : { errorText : options . errorText } ) ,
32+ // Playwright gives a finished request its sizes; null stands for the call failing.
3233 sizes : async ( ) => {
33- if ( options . responseBodySize === undefined ) throw new Error ( "Unable to fetch sizes" ) ;
34- return { responseBodySize : options . responseBodySize } ;
34+ if ( options . responseBodySize === null ) throw new Error ( "Unable to fetch sizes" ) ;
35+ return { responseBodySize : options . responseBodySize ?? 64 } ;
3536 } ,
3637} ) ;
3738
@@ -269,7 +270,24 @@ describe("NetworkLog", () => {
269270 network . finish ( request ) ;
270271
271272 const { requests } = await network . log . query ( "tab-1" , { requestId : "r1" } ) ;
272- expect ( requests [ 0 ] ?. responseBody ) . toEqual ( { truncated : false , omitted : "unavailable" } ) ;
273+ expect ( requests [ 0 ] ?. responseBody ) . toEqual ( {
274+ sizeBytes : 64 ,
275+ truncated : false ,
276+ omitted : "unavailable" ,
277+ } ) ;
278+ } ) ;
279+
280+ it ( "never reads a body whose size neither the headers nor Chromium report" , async ( ) => {
281+ const network = setup ( ) ;
282+ const request = makeRequest ( "http://localhost:5173/api/unknown" , { responseBodySize : null } ) ;
283+ const response = makeResponse ( request , 200 , { "content-type" : "application/json" } , "{}" ) ;
284+ network . start ( request ) ;
285+ network . respond ( response ) ;
286+ network . finish ( request ) ;
287+
288+ const { requests } = await network . log . query ( "tab-1" , { requestId : "r1" } ) ;
289+ expect ( requests [ 0 ] ?. responseBody ) . toEqual ( { truncated : true , omitted : "unavailable" } ) ;
290+ expect ( response . body ) . not . toHaveBeenCalled ( ) ;
273291 } ) ;
274292
275293 it ( "keeps the newest 200 requests and says when a listed id has aged out" , async ( ) => {
0 commit comments