@@ -26,7 +26,7 @@ import {
2626 */
2727export async function captureFetchBreadcrumbToReplay (
2828 breadcrumb : Breadcrumb & { data : FetchBreadcrumbData } ,
29- hint : FetchHint ,
29+ hint : Partial < FetchHint > ,
3030 options : ReplayNetworkOptions & {
3131 textEncoder : TextEncoderInternal ;
3232 replay : ReplayContainer ;
@@ -50,12 +50,12 @@ export async function captureFetchBreadcrumbToReplay(
5050 */
5151export function enrichFetchBreadcrumb (
5252 breadcrumb : Breadcrumb & { data : FetchBreadcrumbData } ,
53- hint : FetchHint ,
53+ hint : Partial < FetchHint > ,
5454 options : { textEncoder : TextEncoderInternal } ,
5555) : void {
5656 const { input, response } = hint ;
5757
58- const body = _getFetchRequestArgBody ( input ) ;
58+ const body = input ? _getFetchRequestArgBody ( input ) : undefined ;
5959 const reqSize = getBodySize ( body , options . textEncoder ) ;
6060
6161 const resSize = response ? parseContentLengthHeader ( response . headers . get ( 'content-length' ) ) : undefined ;
@@ -70,12 +70,13 @@ export function enrichFetchBreadcrumb(
7070
7171async function _prepareFetchData (
7272 breadcrumb : Breadcrumb & { data : FetchBreadcrumbData } ,
73- hint : FetchHint ,
73+ hint : Partial < FetchHint > ,
7474 options : ReplayNetworkOptions & {
7575 textEncoder : TextEncoderInternal ;
7676 } ,
7777) : Promise < ReplayNetworkRequestData > {
78- const { startTimestamp, endTimestamp } = hint ;
78+ const now = Date . now ( ) ;
79+ const { startTimestamp = now , endTimestamp = now } = hint ;
7980
8081 const {
8182 url,
@@ -106,10 +107,10 @@ async function _prepareFetchData(
106107
107108function _getRequestInfo (
108109 { networkCaptureBodies, networkRequestHeaders } : ReplayNetworkOptions ,
109- input : FetchHint [ 'input' ] ,
110+ input : FetchHint [ 'input' ] | undefined ,
110111 requestBodySize ?: number ,
111112) : ReplayNetworkRequestOrResponse | undefined {
112- const headers = getRequestHeaders ( input , networkRequestHeaders ) ;
113+ const headers = input ? getRequestHeaders ( input , networkRequestHeaders ) : { } ;
113114
114115 if ( ! networkCaptureBodies ) {
115116 return buildNetworkRequestOrResponse ( headers , requestBodySize , undefined ) ;
@@ -130,16 +131,16 @@ async function _getResponseInfo(
130131 } : ReplayNetworkOptions & {
131132 textEncoder : TextEncoderInternal ;
132133 } ,
133- response : Response ,
134+ response : Response | undefined ,
134135 responseBodySize ?: number ,
135136) : Promise < ReplayNetworkRequestOrResponse | undefined > {
136137 if ( ! captureDetails && responseBodySize !== undefined ) {
137138 return buildSkippedNetworkRequestOrResponse ( responseBodySize ) ;
138139 }
139140
140- const headers = getAllHeaders ( response . headers , networkResponseHeaders ) ;
141+ const headers = response ? getAllHeaders ( response . headers , networkResponseHeaders ) : { } ;
141142
142- if ( ! networkCaptureBodies && responseBodySize !== undefined ) {
143+ if ( ! response || ( ! networkCaptureBodies && responseBodySize !== undefined ) ) {
143144 return buildNetworkRequestOrResponse ( headers , responseBodySize , undefined ) ;
144145 }
145146
@@ -163,7 +164,8 @@ async function _getResponseInfo(
163164 }
164165
165166 return buildNetworkRequestOrResponse ( headers , size , undefined ) ;
166- } catch {
167+ } catch ( error ) {
168+ __DEBUG_BUILD__ && logger . warn ( '[Replay] Failed to serialize response body' , error ) ;
167169 // fallback
168170 return buildNetworkRequestOrResponse ( headers , responseBodySize , undefined ) ;
169171 }
0 commit comments