Jump to content

How To Get The Browser Name And Version Number?


Frederick

Recommended Posts

I am using the following code to try to get the browser name but all I am getting is "Others". It is the same whether I run in Firefox, Chrome, Edge or Opera.

var
   ClientInfo : TUniClientInfos;
begin
   ClientInfo:=UniApplication.ClientInfo;
   if ciIE in ClientInfo then
      Result := 'IE'
   else if (ciFireFox in ClientInfo) or (ciFirefox2 in ClientInfo) or (ciFirefox3 in ClientInfo) then
      Result := 'FireFox'
   else if ciOpera in ClientInfo then
      Result := 'Opera'
   else if ciSafari in ClientInfo then
      Result := 'Safari'
   else if ciChrome in ClientInfo then
      Result := 'Chrome'
   else
      Result  := 'Other';
end;

Additionally, how do I detect the Microsoft Edge browser and the version number of any browser?

--
Frederick
(UniGUI Complete - Professional Edition 1.90.0.1549)
 

Link to comment
Share on other sites

46 minutes ago, Frederick said:

Additionally, how do I detect the Microsoft Edge browser and the version number of any browser?

Hello,

You can improve a little with this function:

function getBrowserName(AUserAgent: string): string;
function TMainForm.getBrowserName(AUserAgent: string): string;
begin
  if AUserAgent = '' then
  begin
    Result := '';
    Exit;
  end;

  AUserAgent := LowerCase(AUserAgent);

  if Pos('edge', AUserAgent) > 0 then Result := 'edge'
  else if Pos('edg', AUserAgent) > 0 then Result := 'chromium based edge (dev or canary)'
  else if Pos('opr', AUserAgent) > 0 then Result := 'opera'
  else if Pos('chrome', AUserAgent) > 0 then Result := 'chrome'
  else if Pos('trident', AUserAgent) > 0 then Result := 'ie'
  else if Pos('firefox', AUserAgent) > 0 then Result := 'firefox'
  else if Pos('safari', AUserAgent) > 0 then Result := 'safari'
  else Result := 'other';
end;

Usage:

procedure TMainForm.UniFormActivate(Sender: TObject);
var
  C : TUniClientInfoRec;
  userAgent: string;
begin
  UniLabel7.Caption:=UniApplication.RemoteAddress;

  C:=UniApplication.ClientInfoRec;

  UniLabel6.Caption:=C.BrowserType;
  UniLabel4.Caption:=IntToStr(C.BrowserVersion);
  UniLabel5.Caption:=C.OSType;

  UniLabel9.Text := getBrowserName(UniSession.UserAgent); //<-----

end;

https://social.msdn.microsoft.com/Forums/en-US/edde0150-9478-4ca6-ba0f-9e084b5a4719/how-to-detect-microsoft-edge-chromium-chrome-ie-browser-using-javascript?forum=iewebdevelopment

Link to comment
Share on other sites

Thanks. The GetBrowserName() function gives me the information I need.

However, the BrowserType, OSType and BrowserVersion properties from UniApplication.ClientInfoRec do not return anything of value since the first two are blank strings and the third is a 0 regardless of the browser I run the app with.

Link to comment
Share on other sites

On 5/5/2021 at 3:40 PM, Frederick said:

Thanks. The GetBrowserName() function gives me the information I need.

However, the BrowserType, OSType and BrowserVersion properties from UniApplication.ClientInfoRec do not return anything of value since the first two are blank strings and the third is a 0 regardless of the browser I run the app with.

+1

Link to comment
Share on other sites

  • 1 month later...

how to get data in mobile?

fWebBrowser is 0 (empty)

procedure TUniMainModule.GetBrowserType;
Var
 cir: TUniClientInfoRec;
begin
  cir := UniSession.UniApplication.ClientInfoRec;
  fWebBrowser := cir.BrowserType + ' ' + cir.BrowserVersion.ToString;
end;

 

UniSession.UniApplication.ClientInfoRec is empty :(

Link to comment
Share on other sites

  • 5 months later...
  • 2 years later...
4 hours ago, MVakili said:

In my opinion, UNIGUI doesn't identify the version of Windows clients correctly and often shows Windows 7/10/11 as Windows 10.

Hello,

Does this happen in all browsers?

Link to comment
Share on other sites

On 6/6/2024 at 10:30 AM, Sherzod said:

Hi,

Can you test on other browsers too?

Hi @Sherzod

I installed my test app in windows server 2016 and I check in client sides.
You can see output of user agent in below with Google Chrome/ Mozilla Firefox / Microsoft edge browsers and all browsers in for windows 10/11/windows server 2016 shows "Windows NT 10.0".

---------------------------------------------------------
output of user agent in Windows edition 11 Enterprise version 22H2 with Mozilla browser:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0

output of user agent in Windows edition 11 Enterprise version 22H2 with Chrome browser:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple WebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36

output of user agent in Windows edition 11 Enterprise version 22H2 with Microsoft edge browser:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple WebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edge/125.0.0.0
---------------------------------------------------------
output of user agent in Windows edition 10 Enterprise with Chrome browser:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple WebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

---------------------------------------------------------
output of user agent in windows server 2016 data center with Mozilla browser:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0

output of user agent in windows server 2016 data center with Chrome browser:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) Apple WebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36

 

Test case

UNIGUI_UserAgent_Vakili.zip

Link to comment
Share on other sites

Hi, 

Actually, Browsers return the same User-Agent string (Windows NT 10.0) for Windows 10, Windows 11, and Windows Server 2016 to ensure compatibility, support legacy applications, simplify identification, and reduce tracking risks. This approach allows websites to handle requests consistently across these similar Windows versions...

Link to comment
Share on other sites

On 6/8/2024 at 8:11 PM, Sherzod said:

Hi, 

Actually, Browsers return the same User-Agent string (Windows NT 10.0) for Windows 10, Windows 11, and Windows Server 2016 to ensure compatibility, support legacy applications, simplify identification, and reduce tracking risks. This approach allows websites to handle requests consistently across these similar Windows versions...

This version correctly identifies the version of Windows on the server side.
But the client side shows wrongly for the Windows server version.

For better test you can run this sample.
I run this code in  windows 11 (http://localhost:8077/) .
and when I call it in windows 10 ( another client 
 in address http://192.168.25.1:8077/) , it shows windows 11 again !

you can find 2 test movie in HELP folder 

Win_ver11_simple11_030324.zip

 

Link to comment
Share on other sites

  • 3 weeks later...
On 6/8/2024 at 8:11 PM, Sherzod said:

Hi, 

Actually, Browsers return the same User-Agent string (Windows NT 10.0) for Windows 10, Windows 11, and Windows Server 2016 to ensure compatibility, support legacy applications, simplify identification, and reduce tracking risks. This approach allows websites to handle requests consistently across these similar Windows versions...

Hi @Sherzod

did you check my test case?

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...