【问题标题】:Using the Android Turbolinks Framework, how do I mitigate Bridge Injection Failures使用 Android Turbolinks 框架,我如何缓解桥注入失败
【发布时间】:2020-08-08 13:14:35
【问题描述】:

上周我在 Turbolinks GitHub 页面上问了this 问题,因为我一直遇到这个桥注入失败问题。

这个问题非常间歇性,重现起来非常困难,但问题的代码是在一些设备上,我们看到Turbolinks Bridge Injection Failed错误,我们的页面随后无法正确加载.

这里要发布的代码太多(更不用说 NDA 限制),但只要说页面正在加载到大多数设备上以及在失败的设备上就足够了,我们注意到我们的 401 异常服务器由于错误的身份验证详细信息,然后此回调触发。

有谁知道为什么在某些设备上会出现桥接注入问题,而在其他设备上却不会?

【问题讨论】:

    标签: android webchromeclient android-chrome turbolinks-android


    【解决方案1】:

    事实证明,问题不在于我的代码或 turbolinks 的任何地方,而是与安装了 Chrome 浏览器的用户直接相关。

    我跑了无数的数据日志和测试来确认,但结果是这样的:

    Turbolinks 将无法正常工作,如果设备

    1)没有安装Chrome

    2) 已禁用 Chrome

    3) 有一个过时的 Chrome 版本需要更新(我能找到的没有特定的最低版本,更多的是通用版本,需要在 X 版本之后进行更新)。 p>

    在这 3 种情况中的任何一种情况下,Bridge Injection Error 都会触发,这无疑是原因。

    解决方案是通过用户的设备将用户重定向到 Play 商店,并指示他们下载、启用或更新 Chrome。

    /**
     * Open the Google Play store app URL Link
     */
    void openChromeAppPlayStoreLink() {
        //Try catch logic pulled from - https://stackoverflow.com/a/11753070/2480714
        String chromeStr = "com.android.chrome";
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=" + chromeStr));
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            startActivity(intent);
        } catch (android.content.ActivityNotFoundException anfe) {
            //Will fail if play store is disabled or uninstalled for some reason
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + chromeStr));
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
    

    为什么当 Turbolinks 和我的分叉版本都没有使用 WebChromeClient 时需要这样做,我并不完全理解。

    作为一个快速免责声明:我相信您可以让 Turbolinks 在某些情况下正常工作,而这些情况并不能完成我们在服务器端所做的所有事情,但在我们的情况下,这是关键这引起了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-30
      • 2011-05-19
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      相关资源
      最近更新 更多