Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

302 redirected not response body --->throw Can only get response body on requests captured after headers received. #3

Open
huanshiwushuang opened this issue Sep 11, 2020 · 4 comments

Comments

@huanshiwushuang
Copy link

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' });
}
@JoshZA
Copy link

JoshZA commented Oct 14, 2020

👍 Happening to me too

@liweiting
Copy link

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.

@cqq626
Copy link

cqq626 commented Jan 18, 2021

same to me

@JZL
Copy link

JZL commented Jan 27, 2021

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:

if (!event.responseStatusCode) {

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants