GoogleChrome / android-browser-helper

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.
Apache License 2.0
694 stars 288 forks source link

Post Message - onMessageChannelReady is not getting called #440

Closed onkar-rentomojo closed 1 year ago

onkar-rentomojo commented 1 year ago

Read this First If you have a Trusted Web Activity related question, the best place to ask it is on StackOverflow, on the trusted-web-activity tag, which is also monitored by the team.

Describe the bug

  1. CustomTabsCallback onMessageChannelReady is not getting called even if the validation result is true.
  2. Why do we have !mValidated condition in onNavigationEvent if onRelationshipValidationResult gets triggered only when mSession.requestPostMessageChannel is called from the function.
            @Override
            public void onRelationshipValidationResult(int relation, @NonNull Uri requestedOrigin,
                boolean result, @Nullable Bundle extras) {
                // If this fails:
                // - Have you called warmup?
                // - Have you set up Digital Asset Links correctly?
                // - Double check what browser you're using.
                Log.d(TAG, "==========Relationship result============: " + result);
                mValidated = result;
            }

            // Listens for navigation, requests the postMessage channel when one completes.
            @Override
            public void onNavigationEvent(int navigationEvent, @Nullable Bundle extras) {
                if (navigationEvent != NAVIGATION_FINISHED) {
                    return;
                }

                if (!mValidated) {
                    Log.d(TAG, "Not starting PostMessage as validation didn't succeed.");
                }

                // If this fails:
                // - Have you included PostMessageService in your AndroidManifest.xml?
                boolean result = mSession.requestPostMessageChannel(SOURCE_ORIGIN, TARGET_ORIGIN,
                    new Bundle());
                Log.d(TAG, "Requested Post Message Channel: " + result);

            }

           @Override
            public void onMessageChannelReady(@Nullable Bundle extras) {
                Log.d(TAG, "Message channel ready.");

                int result = mSession.postMessage("First message", null);
                Log.d(TAG, "postMessage returned: " + result);
            }
enex commented 1 year ago

@onkar-rentomojo have you found a solution? I am experiencing the same issue