Commit 83e7397
committed
use simple OS detection in JavaScript
In commit f9bbd2d a then-current version
of the JavaScript library from https://github.com/codejoust/session.js
(in minified form) was added to the Git LFS home page in order to help
provide detection of the user's operating system and thus suggest the
appropriate release package of Git LFS to download.
This JS library is no longer up-to-date, and the upstream project
does not appear to be actively maintained. It also provides a lot
of additional client detection capabilities which the Git LFS home page
does not require.
We can simplify our home page to instead perform a basic form of
OS detection using the same technique as the session.js library,
namely a search for the specific strings "Mac" or "Linux" in the
navigator.platform variable. While this variable's use is deprecated
in current JavaScript documentation, it remains the most straightforward
way of performing the basic and limited OS detection we require.
See, for reference:
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
https://developer.chrome.com/en/docs/privacy-sandbox/user-agent/
In future we may choose to replace this with another approach,
such as the User-Agent Client Hints API, but this is not yet supported
by some major Web clients:
https://developer.mozilla.org/en-US/docs/Web/API/WorkerNavigator/userAgentData
Both the legacy version of the session.js library and the most
recent update to that library (from 2019) pass the "navigator" object
to the library's session_fetch() function, which calls the library's
search() function to set the "os" variable we check, passing an internal
"data.os" array containing the possible OS types and their identifying
strings. The search() function then tests for a match with one of these
array elements, and in the case of the two checks we perform (for MacOS
and Linux) this is just a search for a given string ("Mac" or "Linux")
in the string returned by navigator.platform.
Thus we can just perform these simple checks ourselves, which will
suffice for our purposes, and avoid the need to use a legacy JS library
entirely.1 parent 1f05c3f commit 83e7397
3 files changed
+3
-5
lines changedThis file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
0 commit comments