Windows 11 不支持 User Agent?

LMS
4.1K+ 22

心血来潮,给博客的评论添加了个评论之星奖牌和评论者操作系统显示。

这不 Windows 11 出来了么,所以,为了研究 Windows 11 的 User Agent 信息,特意把许久未用的 Windows 系统打开,还废了老鼻子的劲把系统升级了一下。

然后这扯淡的,再次证明 Windows 11 其实就是 Windows 10 换了个皮,User Agent 信息和 Windows 10 一模一样:

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

这是 chrome 浏览器“标头”内的信息,不死心,还自己本地评论了一下,然后打开 mysql 数据库去对照,一模一样……

然后没办法,用 bing 英文版搜索怎么检测 Windows 11 的 User Agent 信息,找到了微软官方的介绍,地址:

https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11

官网开篇介绍:

Websites can use user agent information sent from the browser to detect brand, version, device platform, and more. There are two approaches for sites to access user agent information:

  • User-Agent strings (legacy).
  • User-Agent Client Hints (recommended).

User-Agent strings won't be updated to differentiate between Windows 11 and Windows 10. We don't recommend using User-Agent strings to retrieve user agent data. Browsers that do not support User-Agent Client Hints will not be able to differentiate between Windows 11 and Windows 10.

这鸟毛意思是不是说 User-Agent “停用”了?

停用你就都停用吧,又搞了个 User-Agent Client Hints (UA-CH) 的“推荐”,什么个鬼,这么折腾有意思么?

看里面介绍,要通过 js 来获取 CH-UA-Platform 的 Version 数值来判断是不是 Windows 11,Version 值在 13+ 的都是 Windows 11,真的是 shit!!!

然后我看了一下浏览器的标头,只有 sec-ch-ua-platform: "Windows" 这个信息,并没又 Version 信息,我 chrome 版本 97.0.4692.99 难道还不支持么?

通过其他检测 UA 的网站,确实有返回 Sec-CH-UA-Platform-Version: "15.0.0" 这个信息,但是自己浏览器不知道藏在哪里。

微软给的检测的例子:

navigator.userAgentData.getHighEntropyValues(["platformVersion"])
 .then(ua => {
   if (navigator.userAgentData.platform === "Windows") {
     const majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
     if (majorPlatformVersion >= 13) {
       console.log("Windows 11 or later");
      }
      else if (majorPlatformVersion > 0) {
        console.log("Windows 10");
      }
      else {
        console.log("Before Windows 10");
      }
   }
   else {
     console.log("Not running on Windows");
   }
 });

不管怎么样,Wordpress 原来的记录评论者 UA 信息到数据库,然后通过 PHP 来判断操作系统的传统模式,已经不适合垃圾 Windows 11 了,不知道网上的大佬们是怎么搞定的。

THE END

评论 22

  1. Kei
    🏅

    解答一下为什么你没有得到Version 信息。这是因为需要在服务端添加 Header “Accept-CH: Sec-CH-UA-Platform-Version” ,这样客户端才会在后续请求提供 Sec-CH-UA-Platform-Version。

    1. 那如何在服务端添加 Header “Accept-CH: Sec-CH-UA-Platform-Version”呢。 :roll:

      1. 如果你是Nginx服务器,修改配置文件,添加一行
        add_header Accept-CH 'Sec-CH-UA-Platform-Version';
        就可以了。

  2. 好像还没搞定,是不是放弃了?

  3. 好像没有记录这些信息,没留意数据库。

    1. 有的,有的,wp 和 typecho 都有记录 ua 和 ip。

  4. 我用的win11,果然留言记录的是win10

  5. 记着岂不是增加数据库容量么

    1. wp 默认数据库就有记录这些,typecho好像也有。

  6. 这个好像已经有不少主题都解决了呀!

  7. 我就是11……懒得弄了

    1. 啥意思,是你的主题能显示11了?

      1. 不是,我意思是你看我ua显示的还是10。但已经用11了。懒得搞了。。。

        1. 我还想开电脑去你那里试一下评论,没想到昨天升级完微软推送的升级后,今天打开老是重启。。。

  8. 不要搞定了。11和10没啥大区别。。。。

  9. 哈哈,也许是没来的及改吧,不过我感觉 win11 比 win10 外观上用起来舒服多了……
    测试看看系统准不准!

      1. 哈哈,要加就加全,把使用的啥浏览器也搞上去才好……

发表评论

Submit