Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access web browser dev tools from a separate application

I have an program that displays content on web browsers via a localhost address. My program is cross-platform and I need to know what OS the browser is running on Windows for my program to operate correctly. I can do that by entering the following command into the browser's dev-tools console:

if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";

How can I automate this in my program? I don't know what browser users will be using, or even what OS they'll be on. The reason I can't know what the OS is ahead of time is because of the Windows build. This is done on the Windows Subsystem for Linux which means that the user's browser could be in Ubuntu or (more likely) in Windows. I need to know which one it is to save files correctly.

like image 818
Alex Avatar asked Feb 13 '26 09:02

Alex


2 Answers

If I understood correctly - you are basically developing a web application which operates differently on different browsers.

You do not need to use the browser's dev-tools in order to understand which browser is currently being used. In fact, there are several ways to detect user's browser:

  1. Server Side User agent - 'User-Agent' is an HTTP header specifying which browser, version, and OS the user is using. If you control the server application, just extract this header and parse it.
  2. Client Side User Agent - You can use the navigator.userAgent property to retrieve the user agent string via JS.
  3. Browser functionality - Please read this comment.

Of course, there are other, more complicated methods of understanding which browser is being used, but I don't think you will actually need to use them, as the user agent string will probably suffice here.

like image 167
Walter White Avatar answered Feb 17 '26 17:02

Walter White


I can recommend that you write a small add-on to a browser that will make the identification simple and easy, would you like to have an example?

like image 34
Sagi Nadav Avatar answered Feb 17 '26 15:02

Sagi Nadav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!