Skip to content

Commit

Permalink
fix: get extra headers from Fetch.requestPaused event (#8162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Junyan committed Mar 28, 2022
1 parent e31b8e6 commit 37ede68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/common/NetworkManager.ts
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/requestinterception.spec.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 37ede68

Please sign in to comment.