gpt4 book ai didi

android - PWA 与 TWA : How to force Chrome instead of default browser

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:02:28 29 4
gpt4 key购买 nike

我已经按照此处的官方 Google 指南使用 TWA 构建了 PWA 并生成了 APK - https://developers.google.com/web/updates/2019/02/using-twa

发生的事情是,当将 Chrome 以外的其他浏览器设置为默认浏览器时,行为是不可预测的。例如:在默认使用 MI 浏览器的小米手机上,我的应用程序就像一个快捷方式一样工作,页面只是加载到浏览器的一个选项卡中。这部手机安装了 Chrome,但我的应用程序仍然使用默认浏览器来呈现我的 PWA。

官方文档说明如下:

Today, if the user's version of Chrome doesn't support Trusted Web activities, Chrome will fall back to a simple toolbar using a Custom Tab. It is also possible for other browsers to implement the same protocol that Trusted Web activities use. While the host app has the final say on what browser gets opened, we recommend the same policy as for Custom Tabs: use the user's default browser, so long as that browser provides the required capabilities.

虽然指南有这一段,但我找不到任何关于如何为我的 PWA 设置首选浏览器的文档

最佳答案

不建议强制 Chrome 作为浏览器来处理受信任的 Web Activity ,因为 number of browsers that support Trusted Web Activity is growing并且开发人员应该尝试尽可能地尊重用户的浏览器选择

implementationandroid-browser-helper中选择浏览器将:

  1. 寻找支持 TWA 的浏览器,如果找到,请选择它。
  2. 否则,寻找支持自定义标签的浏览器,如果找到,请选择它。
  3. 否则启动到默认浏览器。

或者,开发人员可以选择将数字 2 和 3 替换为 WebView fallback implementation ,即使在支持的功能集上存在权衡。

关于以下内容:

on a Xiaomi phone where MI Browser is the default, my app works just as a shortcut & the page just loads in one of the tabs of the browser. This phone had Chrome installed, but my app still used the default browser to render my PWA.

这里可能会发生一些事情:

  1. 安装的 Chrome 版本不是最新的并且不支持 Trusted Web Activity,因此退回到 (2)
  2. MI 浏览器声明支持 Trusted Web Activity,但实际上并不支持。这似乎是the case on Kindle Fire devices .
  3. 选择浏览器的逻辑可能存在错误。

对于 1,解决方案是更新 Chrome,一切正常。否则,启用 WebView 回退。

对于 2,听起来需要的是一个“禁止列表”,以避免使用已知声明支持但不支持的浏览器。我建议在 https://github.com/GoogleChrome/android-browser-helper/ 提交功能请求

对于 3,请在 https://github.com/GoogleChrome/android-browser-helper/ 提交错误

更新:我安装了MI Browser通过 Bubblewrap 生成的项目. MI Browser 未声明对 Trusted Web Activity 的支持,并且 Chrome 按预期打开。我倾向于与上述 (1) 相关的问题。

最后,可以为 Trusted Web Activity 实现您自己的提供商选择器,您可以在其中维护一个“禁止列表”,而在 Android 浏览器帮助程序中未实现自动方式。参见 this sample了解详情。

关于android - PWA 与 TWA : How to force Chrome instead of default browser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55531080/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com