Reputation: 47739
I'm using CDP4J, though I expect this question relates directly to Google Chrome DevTools Protocol.
I want to get a list of the HTTP requests made for a webpage and response codes. So that would include the initial request in the main frame and subsequent requests, either made via 3xx redirects or JavaScript-originated navigation.
It's not clear how to do this reliably.
I have tried the following:
io.webfolder.cdp.session.Session.getFrameId
addEventListener
, record every event of type io.webfolder.cdp.event.Event.NetworkResponseReceived
io.webfolder.cdp.type.page.ResourceType.Document
I have a URL that I know returns a HTTP 303. But looking at the Events, don't see the original URL, but instead see only the final destination of the redirects. Every single NetworkResponseReceived has a status of 200.
How can I capture the chain of redirects?
Upvotes: 2
Views: 1249
Reputation: 2134
I've been using the ResponseReceived event for this purpose. This seems to work to get the document URL from the event:
if (session.getTargetId().equals(responseReceived.getFrameId()) && ResourceType.Document.equals(responseReceived.getType())) {
String url = responseReceived.getResponse().getUrl();
...
}
Upvotes: 0
Reputation: 47739
I found the answer. The io.webfolder.cdp.event.network.RequestWillBeSent
event has getRedirectResponse
, which contains a response if it's a redirect.
Upvotes: 2