File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ export function makeFetchTransport(
17
17
method : 'POST' ,
18
18
referrerPolicy : 'origin' ,
19
19
headers : options . headers ,
20
+ // Outgoing requests are usually cancelled when navigating to a different page, causing a "TypeError: Failed to
21
+ // fetch" error and sending a "network_error" client-outcome - in Chrome, the request status shows "(cancelled)".
22
+ // The `keepalive` flag keeps outgoing requests alive, even when switching pages. We want this since we're
23
+ // frequently sending events right before the user is switching pages (eg. whenfinishing navigation transactions).
24
+ // Gotchas:
25
+ // - `keepalive` isn't supported by Firefox
26
+ // - As per spec (https://fetch.spec.whatwg.org/#http-network-or-cache-fetch), a request with `keepalive: true`
27
+ // and a content length of > 64 kibibytes returns a network error. We will therefore only activate the flag when
28
+ // we're below that limit.
29
+ keepalive : request . body . length <= 65536 ,
20
30
...options . fetchOptions ,
21
31
} ;
22
32
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ describe('NewFetchTransport', () => {
44
44
expect ( mockFetch ) . toHaveBeenLastCalledWith ( DEFAULT_FETCH_TRANSPORT_OPTIONS . url , {
45
45
body : serializeEnvelope ( ERROR_ENVELOPE , new TextEncoder ( ) ) ,
46
46
method : 'POST' ,
47
+ keepalive : true ,
47
48
referrerPolicy : 'origin' ,
48
49
} ) ;
49
50
} ) ;
@@ -81,7 +82,7 @@ describe('NewFetchTransport', () => {
81
82
82
83
const REQUEST_OPTIONS : RequestInit = {
83
84
referrerPolicy : 'strict-origin' ,
84
- keepalive : true ,
85
+ keepalive : false ,
85
86
referrer : 'http://example.org' ,
86
87
} ;
87
88
You can’t perform that action at this time.
0 commit comments