屏幕宽度战:Webview vs Firefox vs Chrome

发布于 2025-01-19 01:51:51 字数 677 浏览 1 评论 0原文

我在 Android 中使用 webview 制作了一个简单的网络浏览器,但由于某种原因,我得到了不一致的像素比。我还得到了一个错误的 UserAgent,但我已经修复了它。

我在 1080x2400 手机上使用 javascript 使用 window.devicePixelRatio (PR)、window.innerWidth (IW)、screen.width (W)、window.innerHeight (IH)、screen.height (H) 对此进行了测试(您可以检查 此处)。这就是我得到的:

Firefox     PR=2.6087 IW=414 W=414 IH=783 H=920
Chrome      PR=2.625  IW=412 W=412 IH=778 H=915 
Webview     PR=2.625  IW=412 W=412 IH=834 H=915

确实 H/W = 2400/1080 = 2.2222。但我对不同的像素比率感到困惑。

对于 Firefox,它似乎正在执行 1080/414,而对于 Chrome,它正在执行 1080/412。

那么,为什么 412 和 414 会有差异呢?应该信任哪一个?

I made a simple web browser with a webview in Android, but for some reason I am getting inconsistent pixelRatios. I also got a wrong UserAgent, but I fixed that already.

I tested this in a 1080x2400 phone with javascript using window.devicePixelRatio (PR), window.innerWidth (IW), screen.width (W), window.innerHeight (IH), screen.height (H) (you can check here). This is what I got:

Firefox     PR=2.6087 IW=414 W=414 IH=783 H=920
Chrome      PR=2.625  IW=412 W=412 IH=778 H=915 
Webview     PR=2.625  IW=412 W=412 IH=834 H=915

Indeed H/W = 2400/1080 = 2.2222. But I am confused with the different pixelRatios.

For Firefox, it seems it is doing 1080/414, while for Chrome it is doing 1080/412.

So, why is the difference 412 vs 414? Which one should be trusted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文