How to retrieve response header of a network request in a browser?

Hello Katalon team,

I have a use case where I need to check the location in response header of a network request, below is the steps I did manually:

  1. Open browser, Press F12
  2. Navigate to a website
  3. Select the request that I want to check response header
  4. Check location.

Is there any way I can use to do this use case?

Thanks for your help.

You can not do this as far as your test script talk to web browser using WebDriver interface. In Katalon Studio v8.2.5, you can only use Selenium 3 = WebUI.* keywords. Therefore you can not retrieve HTTP Response headers.

However, if your test script talk to web browser using Chrome DevTools Protocol, it is possible to retrieve HTTP Response Header. However it requires bunch of custom coding. See the following post for what I have ever done.

sequence

In VisualInspectionOfCssAndJs/Script1643072750293.groovy at master · kazurayam/VisualInspectionOfCssAndJs · GitHub, you can see a code fragment:

// log responses
devTool.addListener(Network.responseReceived(), { event ->
	Integer status = event.getResponse().getStatus()
	URL url = new URL(event.getResponse().getUrl())
	String mimeType = event.getResponse().getMimeType().toString()

        // HERE YOU CAN RETRIEVE HTTP RESPONSE HEADERS OUT OF event.getResponse() 

	ResponseInspected res = new ResponseInspected(status, url, mimeType)
	responses.add(res)
	//
	lastResponseReceivedAt = LocalDateTime.now()
	// log this event in the console to show progress
	println res.toString()
})

You can change the sample code so that you retrieve the HTTP Response Headers out of the object returned by event.getResponse().

1 Like

Katalon Studio v8.2.5 is not ready for Chrome DevTools Protocol.

If you want to perform testing through Chrome DevTools Protocol intensively, Playwright would be the better platform for you.

Many thanks for your response. I’m trying to do exactly steps as you did, but I got below error, I’m using KS version 8.3.0 beta, does Chrome DevTools Protocol support 8.3.0 beta yet?

Katalon Studio v8.3.0 does not bundle Selenium 4. Katalon team once wrote that they aim to support Selenium 4 in the 3rd quarter this year.

Option1: Using kklisura’s CDP library

In my project, please find the following option you have

Playwright + TypeScript will be far easier and stable to work with CDP.

Playwright + TypeScript will be far easier and stable to work with CDP.

I’m using KS to write all scripts for testing, my company also got a Katalon license so now it’s hard to switch from Katalon to Playwright. I would prefer to option 1, but I have a concern, does CDP still work if I test with others browser? (Firefox, IE, Edge Chromium)

No.

Firefox and IE don’t (will never) support CDP.

Edge Chromium? — I haven’t tested it. Might be yes, might be no.

If you want to retrieve HTTP headers with Firefox, IE and all browsers, you should not use CDP.

An alternative is available. See the following post and give it a try:

Many thanks for your support @kazurayam . I’ll try to use BrowserMob to see whether it can resolve my problem or not.