@@ -12,6 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
1212 generateUUID : "chrome://remote/content/shared/UUID.sys.mjs" ,
1313 NavigableManager : "chrome://remote/content/shared/NavigableManager.sys.mjs" ,
1414 NavigationState : "chrome://remote/content/shared/NavigationManager.sys.mjs" ,
15+ NetworkDataBytes : "chrome://remote/content/shared/NetworkDataBytes.sys.mjs" ,
1516 notifyNavigationStarted :
1617 "chrome://remote/content/shared/NavigationManager.sys.mjs" ,
1718} ) ;
@@ -29,6 +30,7 @@ export class NetworkRequest {
2930 #isDataURL;
3031 #navigationId;
3132 #navigationManager;
33+ #postData;
3234 #postDataSize;
3335 #rawHeaders;
3436 #redirectCount;
@@ -97,9 +99,10 @@ export class NetworkRequest {
9799 this . #contextId = this . #getContextId( ) ;
98100 this . #navigationId = this . #getNavigationId( ) ;
99101
100- // The postDataSize will no longer be available after the channel is closed.
101- // Compute and cache the value, to be updated when `setRequestBody` is used.
102- this . #postDataSize = this . #computePostDataSize( ) ;
102+ // The postData will no longer be available after the channel is closed.
103+ // Compute the postData and postDataSize properties, to be updated later if
104+ // `setRequestBody` is used.
105+ this . #updatePostData( ) ;
103106 }
104107
105108 get alreadyCompleted ( ) {
@@ -159,6 +162,10 @@ export class NetworkRequest {
159162 return this . #navigationId;
160163 }
161164
165+ get postData ( ) {
166+ return this . #postData;
167+ }
168+
162169 get postDataSize ( ) {
163170 return this . #postDataSize;
164171 }
@@ -216,6 +223,19 @@ export class NetworkRequest {
216223 ) ;
217224 }
218225
226+ /**
227+ * Returns the NetworkDataBytes instance representing the request body for
228+ * this request.
229+ *
230+ * @returns {NetworkDataBytes }
231+ */
232+ readAndProcessRequestBody = ( ) => {
233+ return new lazy . NetworkDataBytes ( {
234+ getBytesValue : ( ) => this . #postData. text ,
235+ isBase64 : this . #postData. isBase64 ,
236+ } ) ;
237+ } ;
238+
219239 /**
220240 * Redirect the request to another provided URL.
221241 *
@@ -253,7 +273,7 @@ export class NetworkRequest {
253273 } finally {
254274 // Make sure to reset the flag once the modification was attempted.
255275 this . #channel. requestObserversCalled = true ;
256- this . #postDataSize = this . #computePostDataSize ( ) ;
276+ this . #updatePostData ( ) ;
257277 }
258278 }
259279
@@ -337,6 +357,7 @@ export class NetworkRequest {
337357 initiatorType : this . initiatorType ,
338358 method : this . method ,
339359 navigationId : this . navigationId ,
360+ postData : this . postData ,
340361 postDataSize : this . postDataSize ,
341362 redirectCount : this . redirectCount ,
342363 requestId : this . requestId ,
@@ -348,15 +369,6 @@ export class NetworkRequest {
348369 } ;
349370 }
350371
351- #computePostDataSize( ) {
352- const charset = lazy . NetworkUtils . getCharset ( this . #channel) ;
353- const sentBody = lazy . NetworkHelper . readPostTextFromRequest (
354- this . #channel,
355- charset
356- ) ;
357- return sentBody ? sentBody . length : 0 ;
358- }
359-
360372 /**
361373 * Convert the provided request timing to a timing relative to the beginning
362374 * of the request. Note that https://w3c.github.io/resource-timing/#dfn-convert-fetch-timestamp
@@ -517,4 +529,31 @@ export class NetworkRequest {
517529 ) ;
518530 return ! browsingContext . parent ;
519531 }
532+
533+ #readPostDataFromRequestAsUTF8( ) {
534+ const postData = lazy . NetworkHelper . readPostDataFromRequest (
535+ this . #channel,
536+ "UTF-8"
537+ ) ;
538+
539+ if ( postData === null || postData . data === null ) {
540+ return null ;
541+ }
542+
543+ return {
544+ text : postData . isDecodedAsText ? postData . data : btoa ( postData . data ) ,
545+ isBase64 : ! postData . isDecodedAsText ,
546+ } ;
547+ }
548+
549+ #updatePostData( ) {
550+ const sentBody = this . #readPostDataFromRequestAsUTF8( ) ;
551+ if ( sentBody ) {
552+ this . #postData = sentBody ;
553+ this . #postDataSize = sentBody . text . length ;
554+ } else {
555+ this . #postData = null ;
556+ this . #postDataSize = 0 ;
557+ }
558+ }
520559}
0 commit comments