puppeteer-interceptor
puppeteer-interceptor copied to clipboard
302 redirected not response body --->throw Can only get response body on requests captured after headers received.
302 redirect not have response body,throw Error "Can only get response body on requests captured after headers received" Maybe you need a ---> try catch
try {
const responseCdp = (await client.send('Fetch.getResponseBody', {
requestId,
}));
const response = {
body: responseCdp.base64Encoded ? atob_1.default(responseCdp.body) : responseCdp.body,
headers: event.responseHeaders,
errorReason: event.responseErrorReason,
statusCode: event.responseStatusCode,
};
newResponse = await this.eventHandlers.onResponseReceived({ response, request });
} catch (e) {
console.log(e);
newResponse = await this.eventHandlers.onResponseReceived({ test: 'test' });
}
👍 Happening to me too
Happening to me too。
[2020-12-20T15:33:41.167Z] (node:69971) UnhandledPromiseRejectionWarning: Error: Protocol error (Fetch.getResponseBody): Can only get response body on requests captured after headers received.
same to me
For anyone else who is looking, I think an easier way could be to just add in check for 200 responseStatusCode
.
So right below the check in line 130: https://github.com/jsoverson/puppeteer-interceptor/blob/1ba312fcdfa82a329a48dd613d726a8a966e5be5/src/index.ts#L130 add something like
else if(event.responseStatusCode!=200){
console.log(event.request.url+" => non 200 status: " + event.responseStatusCode)
}
At least in my short tests, this works great. No errors and after a 301 redirect, it just intercepts the actual url