@@ -200,6 +200,11 @@ export class CRNetworkManager {
200
200
}
201
201
}
202
202
let frame = requestWillBeSentEvent . frameId ? this . _page . _frameManager . frame ( requestWillBeSentEvent . frameId ) : workerFrame ;
203
+ // Requests from workers lack frameId, because we receive Network.requestWillBeSent
204
+ // on the worker target. However, we receive Fetch.requestPaused on the page target,
205
+ // and lack workerFrame there. Luckily, Fetch.requestPaused provides a frameId.
206
+ if ( ! frame && requestPausedEvent && requestPausedEvent . frameId )
207
+ frame = this . _page . _frameManager . frame ( requestPausedEvent . frameId ) ;
203
208
204
209
// Check if it's main resource request interception (targetId === main frame id).
205
210
if ( ! frame && requestPausedEvent && requestWillBeSentEvent . frameId === ( this . _page . _delegate as CRPage ) . _targetId ) {
@@ -209,32 +214,36 @@ export class CRNetworkManager {
209
214
frame = this . _page . _frameManager . frameAttached ( requestWillBeSentEvent . frameId , null ) ;
210
215
}
211
216
217
+ // CORS options request is generated by the network stack. If interception is enabled,
218
+ // we accept all CORS options, assuming that this was intended when setting route.
219
+ //
220
+ // Note: it would be better to match the URL against interception patterns, but
221
+ // that information is only available to the client. Perhaps we can just route to the client?
222
+ if ( requestPausedEvent && requestPausedEvent . request . method === 'OPTIONS' && this . _page . _needsRequestInterception ( ) ) {
223
+ const requestHeaders = requestPausedEvent . request . headers ;
224
+ const responseHeaders : Protocol . Fetch . HeaderEntry [ ] = [
225
+ { name : 'Access-Control-Allow-Origin' , value : requestHeaders [ 'Origin' ] || '*' } ,
226
+ { name : 'Access-Control-Allow-Methods' , value : requestHeaders [ 'Access-Control-Request-Method' ] || 'GET, POST, OPTIONS, DELETE' } ,
227
+ { name : 'Access-Control-Allow-Credentials' , value : 'true' }
228
+ ] ;
229
+ if ( requestHeaders [ 'Access-Control-Request-Headers' ] )
230
+ responseHeaders . push ( { name : 'Access-Control-Allow-Headers' , value : requestHeaders [ 'Access-Control-Request-Headers' ] } ) ;
231
+ this . _client . _sendMayFail ( 'Fetch.fulfillRequest' , {
232
+ requestId : requestPausedEvent . requestId ,
233
+ responseCode : 204 ,
234
+ responsePhrase : network . STATUS_TEXTS [ '204' ] ,
235
+ responseHeaders,
236
+ body : '' ,
237
+ } ) ;
238
+ return ;
239
+ }
240
+
212
241
if ( ! frame ) {
213
- if ( requestPausedEvent ) {
214
- // CORS options request is generated by the network stack, it is not associated with the frame id.
215
- // If URL matches interception pattern, accept it, assuming that this was intended when setting route.
216
- if ( requestPausedEvent . request . method === 'OPTIONS' && this . _page . _needsRequestInterception ( ) ) {
217
- const requestHeaders = requestPausedEvent . request . headers ;
218
- const responseHeaders : Protocol . Fetch . HeaderEntry [ ] = [
219
- { name : 'Access-Control-Allow-Origin' , value : requestHeaders [ 'Origin' ] || '*' } ,
220
- { name : 'Access-Control-Allow-Methods' , value : requestHeaders [ 'Access-Control-Request-Method' ] || 'GET, POST, OPTIONS, DELETE' } ,
221
- { name : 'Access-Control-Allow-Credentials' , value : 'true' }
222
- ] ;
223
- if ( requestHeaders [ 'Access-Control-Request-Headers' ] )
224
- responseHeaders . push ( { name : 'Access-Control-Allow-Headers' , value : requestHeaders [ 'Access-Control-Request-Headers' ] } ) ;
225
- this . _client . _sendMayFail ( 'Fetch.fulfillRequest' , {
226
- requestId : requestPausedEvent . requestId ,
227
- responseCode : 204 ,
228
- responsePhrase : network . STATUS_TEXTS [ '204' ] ,
229
- responseHeaders,
230
- body : '' ,
231
- } ) ;
232
- } else {
233
- this . _client . _sendMayFail ( 'Fetch.continueRequest' , { requestId : requestPausedEvent . requestId } ) ;
234
- }
235
- }
242
+ if ( requestPausedEvent )
243
+ this . _client . _sendMayFail ( 'Fetch.continueRequest' , { requestId : requestPausedEvent . requestId } ) ;
236
244
return ;
237
245
}
246
+
238
247
let allowInterception = this . _userRequestInterceptionEnabled ;
239
248
if ( redirectedFrom ) {
240
249
allowInterception = false ;
0 commit comments