Karl Dubost: Get Ready For Three Digits User Agent Strings |
In 2022, Firefox and Chrome will reach a version number with three digits: 100
.
It's time to get ready and extensively test your code, so your code doesn't return null
or worse 10
instead of 100
.
The browser user agent string is used in many circumstances, on the server side with the User-Agent
HTTP header and on the client side with navigator.userAgent
. Browsers lie about it. Web apps and websites detection do not cover all cases. So browsers have to modify the user agent string on a site by site case.
According to the Firefox release calendar, during the first quarter of 2022 (probably February), Firefox will reach version 100.
And Chrome release calendar sets a current date of March 29, 2022.
Dennis Schubert started to test JavaScript Libraries, but this tests only the libraries which are up to date. And we know it, the Web is a legacy machine full of history.
The webcompat team will probably automatically test the top 1000 websites. But this is very rudimentary. It will not cover everything. Sites always break in strange ways.
100
UA stringMozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0
, change it to be Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:100.0) Gecko/20100101 Firefox/100.0
If your web app has a JavaScript Test suite, add a profile with a browser having 100
for its version number and check if it breaks. Test both Firefox and Chrome (mobile and desktop) because the libraries have different code paths depending on the user agent. Watch out for code like:
const ua_string = "Firefox/100.0";
ua_string.match(/Firefox\/(\d\d)/); // ["Firefox/10", "10"]
ua_string.match(/Firefox\/(\d{2})/); // ["Firefox/10", "10"]
ua_string.match(/Firefox\/(\d\d)\./); // null
Compare integer, not string when you have decided to have a minimum version for supporting a browser, because
"80" < "99" // true
"80" < "100" // false
parseInt("80", 10) < parseInt("99", 10) // true
parseInt("80", 10) < parseInt("100", 10) // true
If you have more questions, things I may have missed, different take on them. Feel free to comment…. Be mindful.
Otsukare!
https://www.otsukare.info/2021/04/20/ua-three-digits-get-ready
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |