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.
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:
navigator.userAgent property to retrieve the user agent string via JS.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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With