fix: get extra headers from Fetch.requestPaused event (#8162)

This commit is contained in:
Junyan 2022-03-28 15:54:24 +08:00 committed by GitHub
parent e31b8e6d39
commit 37ede68770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -268,6 +268,7 @@ export class NetworkManager extends EventEmitter {
this._networkEventManager.getRequestPaused(networkRequestId);
if (requestPausedEvent) {
const { requestId: fetchRequestId } = requestPausedEvent;
this._patchRequestEventHeaders(event, requestPausedEvent);
this._onRequest(event, fetchRequestId);
this._networkEventManager.forgetRequestPaused(networkRequestId);
}
@ -345,12 +346,24 @@ export class NetworkManager extends EventEmitter {
})();
if (requestWillBeSentEvent) {
this._patchRequestEventHeaders(requestWillBeSentEvent, event);
this._onRequest(requestWillBeSentEvent, fetchRequestId);
} else {
this._networkEventManager.storeRequestPaused(networkRequestId, event);
}
}
_patchRequestEventHeaders(
requestWillBeSentEvent: Protocol.Network.RequestWillBeSentEvent,
requestPausedEvent: Protocol.Fetch.RequestPausedEvent
): void {
requestWillBeSentEvent.request.headers = {
...requestWillBeSentEvent.request.headers,
// includes extra headers, like: Accept, Origin
...requestPausedEvent.request.headers,
};
}
_onRequest(
event: Protocol.Network.RequestWillBeSentEvent,
fetchRequestId?: FetchRequestId

View File

@ -40,6 +40,7 @@ describe('request interception', function () {
}
expect(request.url()).toContain('empty.html');
expect(request.headers()['user-agent']).toBeTruthy();
expect(request.headers()['accept']).toBeTruthy();
expect(request.method()).toBe('GET');
expect(request.postData()).toBe(undefined);
expect(request.isNavigationRequest()).toBe(true);