GoogleChrome / GoogleChrome/android-browser-helper
Trusted Web Activity Bubblewrap with PostMessage
- Dominant language
- Java
- Stars
- 832
- Forks
- 370
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
**Is your feature request related to a problem? Please describe.**
I am currently working on a project where I need to manage the sending of post messages to the browser. I have successfully overridden the [getCustomTabsCallback](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java#L245) method in the [LauncherActivity](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java) class to return a custom class extended from the [QualityEnforcer](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/QualityEnforcer.java) class. This extended class contains the logic of CustomTabsCallback as described in the [documentation](https://developer.chrome.com/docs/android/post-message-twa?hl=fr#create_customtabscallback). However, to do this, I need access to the session created in the [onCustomTabsServiceConnected](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java#L318) method of the [TwaCustomTabsServiceConnection](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java#L302) subclass in the [TwaLauncher](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java) class.
**Describe the solution you’d like**
I would like to have a getter method or some other way to access the [mSession](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java#L93) property from the [TwaLauncher](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java) class. Currently, this property is private and there is no getter method to retrieve it.
**Describe alternatives you’ve considered**
As an alternative, I've tried overriding the [createTwaLauncher](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java#L249) method in the [LauncherActivity](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/LauncherActivity.java) class to return an extended custom class from the [TwaLauncher](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java) class to access the mSession property of CustomTabsSession, or overriding the [TwaCustomTabsServiceConnection](https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/TwaLauncher.java#L302) subclass. However, they are still private, so this requires modifying the library's source code, which isn't ideal.
**Additional context**
I have successfully made postal messages work based on the [twa-post-message demo](https://github.com/GoogleChrome/android-browser-helper/tree/main/demos/twa-post-message) and the [documentation](https://developer.chrome.com/docs/android/post-message-twa?hl=fr#create_customtabscallback) without any problem where I was able to communicate between the TWA application and my Web app. The thing is, I use Bubblewrap to generate the project and the structure has nothing to do with that of the demo. I would simply like to add a new class to the project generated by Bubblewrap without having to modify the entire project structure and having to maintain it with each new update of the “android-browser-helper” repo.
If it is possible to find a solution to use post messages in a project generated by Bubblewrap without having to make hacks, it would be greatly appreciated.
Contributor guide
Assessment
This issue has not been assessed yet.