7
7
* - Please do NOT modify this file.
8
8
*/
9
9
10
- const PACKAGE_VERSION = '2.10 .2'
11
- const INTEGRITY_CHECKSUM = 'f5825c521429caf22a4dd13b66e243af '
10
+ const PACKAGE_VERSION = '2.11 .2'
11
+ const INTEGRITY_CHECKSUM = '4db4a41e972cec1b64cc569c66952d82 '
12
12
const IS_MOCKED_RESPONSE = Symbol ( 'isMockedResponse' )
13
13
const activeClientIds = new Set ( )
14
14
@@ -71,11 +71,6 @@ addEventListener('message', async function (event) {
71
71
break
72
72
}
73
73
74
- case 'MOCK_DEACTIVATE' : {
75
- activeClientIds . delete ( clientId )
76
- break
77
- }
78
-
79
74
case 'CLIENT_CLOSED' : {
80
75
activeClientIds . delete ( clientId )
81
76
@@ -94,6 +89,8 @@ addEventListener('message', async function (event) {
94
89
} )
95
90
96
91
addEventListener ( 'fetch' , function ( event ) {
92
+ const requestInterceptedAt = Date . now ( )
93
+
97
94
// Bypass navigation requests.
98
95
if ( event . request . mode === 'navigate' ) {
99
96
return
@@ -110,23 +107,29 @@ addEventListener('fetch', function (event) {
110
107
111
108
// Bypass all requests when there are no active clients.
112
109
// Prevents the self-unregistered worked from handling requests
113
- // after it's been deleted (still remains active until the next reload).
110
+ // after it's been terminated (still remains active until the next reload).
114
111
if ( activeClientIds . size === 0 ) {
115
112
return
116
113
}
117
114
118
115
const requestId = crypto . randomUUID ( )
119
- event . respondWith ( handleRequest ( event , requestId ) )
116
+ event . respondWith ( handleRequest ( event , requestId , requestInterceptedAt ) )
120
117
} )
121
118
122
119
/**
123
120
* @param {FetchEvent } event
124
121
* @param {string } requestId
122
+ * @param {number } requestInterceptedAt
125
123
*/
126
- async function handleRequest ( event , requestId ) {
124
+ async function handleRequest ( event , requestId , requestInterceptedAt ) {
127
125
const client = await resolveMainClient ( event )
128
126
const requestCloneForEvents = event . request . clone ( )
129
- const response = await getResponse ( event , client , requestId )
127
+ const response = await getResponse (
128
+ event ,
129
+ client ,
130
+ requestId ,
131
+ requestInterceptedAt ,
132
+ )
130
133
131
134
// Send back the response clone for the "response:*" life-cycle events.
132
135
// Ensure MSW is active and ready to handle the message, otherwise
@@ -204,7 +207,7 @@ async function resolveMainClient(event) {
204
207
* @param {string } requestId
205
208
* @returns {Promise<Response> }
206
209
*/
207
- async function getResponse ( event , client , requestId ) {
210
+ async function getResponse ( event , client , requestId , requestInterceptedAt ) {
208
211
// Clone the request because it might've been already used
209
212
// (i.e. its body has been read and sent to the client).
210
213
const requestClone = event . request . clone ( )
@@ -255,6 +258,7 @@ async function getResponse(event, client, requestId) {
255
258
type : 'REQUEST' ,
256
259
payload : {
257
260
id : requestId ,
261
+ interceptedAt : requestInterceptedAt ,
258
262
...serializedRequest ,
259
263
} ,
260
264
} ,
0 commit comments