Updated method for retrieving console value from Chrome console?

So something appears to have change in the latest Chrome release that broke a function that was working before.

We have a function on our web page that allows us to track an internal session ID that we then send to our database so that we can correlate various things with a given user’s session.

Up until this point, I was able to use the following code in order to return the value of this internal parameter to Katalon, but Chrome appears to have cracked down on this and no longer allows this form of value returning:

js_command_string = "_myUtil.sessionID;"
my_session_id = WebUI.executeJavaScript(js_command_string, null)

I have also tried using a return statement with no luck:

js_command_string = "var myCalc = _myUtil.sessionID; return myCalc;"
my_session_id = WebUI.executeJavaScript(js_command_string, null)

Which is a bit frustrating because the following statement does work, so I can’t figure out why one works and the other no longer does:

jsSSL = "var myCalc= ((window.performance.timing.requestStart - window.performance.timing.secureConnectionStart) / 1000).toPrecision(3); return myCalc;"
mySSL = WebUI.executeJavaScript(jsSSL , null)

any ideas what statement format might work with the Chrome changes?

1 Like

Hi,

I will take a look on this and let you know soon

Thank you!

Hi,

Can you please help clarify more on this? Do you receive any warning / error log or just literally the value not returned? It seems like Chrome has tightened security restrictions around accessing certain internal properties. I guess this

jsSSL = "var myCalc= ((window.performance.timing.requestStart - window.performance.timing.secureConnectionStart) / 1000).toPrecision(3); return myCalc;"
mySSL = WebUI.executeJavaScript(jsSSL , null)

work because you do not access to internal ID. Does your ID locate somewhere on the page, try WebUI.findWebElement()?

Not sure what you are referring to by ID, can you clarify please?

As far as the error message, this is what is being returned from the console when I try the call manually, and I suspect it’s the same error Katalon’s getting:
image

Hi,

ID is internal session ID I mean. Illegal return statement means a syntax error or is attempting to return a value from a context where it’s not allowed. Can you please double-check _myUtil.sessionID correctly or able to be called?

I am able to correctly call it in the console and have it return a value with the statement _myUtil.sessionID, but that statement only returns null when used from Katalon, not sure if it’s because Katalon requires a return statement (which apparently Chrome no longer allows) or not.

Additional details:

  1. Here’s where I use the command in the console and get a return value:

image

  1. Code snippet where I’m calling this function in a loop in order to allow time for the page to load the function library:
		def counter;
		def js_command_string;

		def btt_session_id = null
		counter = 0

		while ((btt_session_id==null) && (counter < 5)) {
			KeywordUtil.logInfo("In Session ID Loop")
			counter = counter + 1
			js_command_string = "_bttUtil.sessionID;"
			btt_session_id = WebUI.executeJavaScript(js_command_string, null)
			WebUI.delay(2)
			KeywordUtil.logInfo ('Session ID = ' + btt_session_id)
		}
  1. Execution output response:

image

Hi,

yes it requires a return. If your session ID can be located somewhere on the page, I suggest you should use findwebElement() or read more about the examples of executeJavaScript () here [WebUI] Execute JavaScript | Katalon Docs

Was able to resolve the issue buy uninstalling and reinstalling Chrome, then updating to the latest ChromeDriver. Appreciate everyone who was working with me on this!

2 Likes