I have requirement to identify user logged in browser type as Safari/Chrome/Firefox etc..
There are some Pega OOTB functions available as below, but they are returning “true” irrespective of browser type.
BrowserIsFireFoxOrSafari
BrowserIsFireFox
Also, we have coded the below lines to get the browser type. However, there is an output when executed from Chrome but returning a null pointer exception in Safari.
List a = ((com.pega.pegarules.priv.PegaAPI)tools).getHTTPHeaders(“sec-ch-ua”);
@SaiPrakashG Hmm, I came across a function pzGetUserAgentString:
List userAgentHeader = ((com.pega.pegarules.priv.PegaAPI)tools).getHTTPHeaders(“User-Agent”);
It’s derivative, but according to Sec-CH-UA header - HTTP | MDN, it looks like that HTTP header is not supported by Safari anyway. User-Agent is (there’s a big fat warning that says it should be used moderately, but that’s for accessibility reasons).
List b = ((com.pega.pegarules.priv.PegaAPI)tools).getHTTPHeaders(“User-Agent”);
String output = (String)b.get(0);
with the above lines of code, we may not be able to get the exact browser name in “output”. However, when executed these two lines of code in two different browsers like Chrome and Safari, there was a slight difference observed in return value “output” as below.
In Chrome:
output = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
In Safari:
output = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15
using which the below additional code help to differentiate the browser type,