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
688 stars 286 forks source link

Cannot repro the demo of twa post message #439

Closed ALiangLiang closed 11 months ago

ALiangLiang 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

I'm not sure it's a bug or not. I can't repro the demo. I can compile it but cannot works correctly.

  1. If I compile and open it directly. Cannot trigger CustomTabsCallback.
  2. So I call validateRelationship after mSession = mClient.newSession(customTabsCallback);. But requestPostMessageChannel return false. I'm sure I've put PostMessageService in AndroidManifest.xml.

To Reproduce Steps to reproduce the behavior:

  1. Clone the repo
  2. cd android-browser-helper/demos/twa-post-message
  3. edit MainActivity.java. Replace URL and TARGET_ORIGIN by localhost site my owned. The site I already has assetlink.json which has correct sha256 of debug keystore and relation. And add following code at line 142. (already imported CustomTabsService)
                            mSession.validateRelationship(CustomTabsService.RELATION_USE_AS_ORIGIN,
                                    TARGET_ORIGIN, new Bundle());
  4. adb logcat | grep PostMessageDemo
  5. ../../gradlew installDebug and open the app by hands.
  6. Following partial logs:
    08-08 00:53:20.868 25893 25893 D PostMessageDemo: Relationship result: true
    08-08 00:53:23.168 25893 25893 D PostMessageDemo: Requested Post Message Channel: false

Expected behavior A clear and concise description of what you expected to happen.

requestPostMessageChannel return false should return true

Did this ever used to work

no

Screenshots

Code Snippets If applicable, add or link to code snippets describing how the API is being used.

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

SayedElabady commented 11 months ago

Thanks for reporting this, may I know the value of SOURCE_ORIGIN you are using?

SayedElabady commented 11 months ago

So that wasn't mentioned in the demo but the SOURCE_ORIGIN has to either start with http:// or https://, please try it and let me know if the issue still persists.

ALiangLiang commented 11 months ago

So that wasn't mentioned in the demo but the SOURCE_ORIGIN has to either start with http:// or https://, please try it and let me know if the issue still persists.

I follow the comment. So I leave it as "my-app-origin-uri". I just tried to changing it to "https://peconn.github.io" and it seems to work. Thanks

SayedElabady commented 11 months ago

Thanks for the confirmation.