Skip to content

Commit 83e7397

Browse files
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

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

js/_lib/session.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

js/_scripts/main.coffee

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
$ ->
2-
os = window.session.browser.os.toLowerCase()
3-
if os == 'mac'
2+
platform = window.navigator.platform
3+
if (platform.indexOf 'Mac') != -1
44
$('.js-mac').removeClass('visually-hidden')
5-
else if os == 'linux'
5+
else if (platform.indexOf 'Linux') != -1
66
$('.js-linux').removeClass('visually-hidden')
77
else
88
$('.js-windows').removeClass('visually-hidden')

js/application.coffee

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# Libs
55
`{% include_relative _lib/jquery-3.7.1.min.js %}`
6-
`{% include_relative _lib/session.min.js %}`
76

87
# Coffeescripts
98
{% include_relative _scripts/main.coffee %}

0 commit comments

Comments
 (0)