mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: get extra headers from Fetch.requestPaused event (#8162)
This commit is contained in:
parent
e31b8e6d39
commit
37ede68770
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user