Using the Android Turbolinks Framework, how do I mitigate Bridge Injection Failures

46 views Asked by At

I asked this question on the Turbolinks GitHub page last week as I kept experiencing this bridge injection failure issue.

The issue is extremely intermittent and is very challenging to reproduce, but the code of the problem is that on some devices, we we see the Turbolinks Bridge Injection Failed error and our page subsequently fails to load properly.

There's too much code to post here (not to mention NDA restrictions), but suffice it to say that the page is being loaded on the majority of devices and on the ones that fail, we notice a 401 exception from our server due to bad authentication details and then this callback fires off.

Does anyone know why a Bridge Injection issue would occur on some devices, but not on others?

1

There are 1 answers

0
PGMacDesign On

As it turns out, the issue lies not anywhere in my code nor in turbolinks, but is directly correlated to users having the Chrome Browser installed.

I ran countless data logs and tests to confirm, but the upshot is this:

Turbolinks will not work properly if the device:

1) Does not have Chrome installed

2) Has Chrome Disabled

3) Has an outdated version of Chrome that requires an update (no specific minimum version from what I could find, more just a generic, an update needs to happen after X versions).

In any of the 3 situations, this Bridge Injection Error will fire off and that is unquestionably the cause.

The solution is to redirect the user to the Play store via their device and instruct them to either download, enable, or update 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);
    }
}

Why this is required when neither Turbolinks nor my forked version use the WebChromeClient is not something I fully understand.

As a quick disclaimer : I am sure you can get Turbolinks to work fine in some situations that do not do all that we were doing server-side, but in our situation, this was the lynchpin that was causing issues.