Skip to content

Notify.requestPermission() in PWA not being overridden/intercepted by android-browser-helper to ask for native Notification permission? #563

@greglearns

Description

@greglearns

Describe the bug
Notification.requestPermission() in the PWA is not triggering the Android app / TWA to change Notificaition permission from "blocked" to "granted".

To Reproduce
Steps to reproduce the behavior:

Using the most recent version of Google Bubblewrap, I created a Trusted Web Activity (TWA) Android wrapper for my PWA (Progressive Web App) created using SolidJS. My Android code uses:

public class DelegationService extends com.google.androidbrowserhelper.trusted.DelegationService
so that when the PWA requests Notification.requestPermission(), the TWA should pass the request up to the TWA android wrapper and enable the app's Notifications instead of just the browser's notifications.

However, when the PWA calls Notification.requestPermission() and the user selects "Allow", the PWA returns "granted", but the application's notifications permission is still "blocked".

I've verified that I'm following all of the instructions for gradle, etc. and I've tried a 100 variations, but it's still happening. This seems like this should be straightforward and common: enable a PWA to enable notifications in the TWA android wrapper, and yet I'm stumped.

The steps I using to run it is:

  1. Using both the most recent PWABuilder and google's BubblePack to create an android TWA wrapper. Following all of the directions there exactly. Verified that assetlinks.json is deployed correctly with the correct keys (triple checked this).
  2. I'm extending: https://github.com/GoogleChrome/android-browser-helper/blob/main/androidbrowserhelper/src/main/java/com/google/androidbrowserhelper/trusted/DelegationService.java
  3. On a fresh install, click in the TWA in the javascript PWA "Enable Notifications button" that calls the javascript Notification.requestPermission().
  4. The browser permission box appears, but not the TWA native permission box. User clicks "Allow".
  5. Embedded chrome browser reports that Notification permission is "granted".
  6. Native Notification permission does not report "granted" (Notifications are still "blocked").

There are no logs in adb logcat since during the actual clicking and Notification.requestPermission step because it appears that the override isn't being called.

Expected behavior
Clicking to trigger Notification.requestPermission() in javascript in the PWA should be intercepted by the TWA handler and the Native Notification permission widget should be shown.

Did this ever used to work
Hasn't worked for me yet.

Screenshots

Code Snippets

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    package="com.myapp.www.twa">
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
    <application
...
        <service
            android:name=".DelegationService"
            android:enabled="true"
            android:exported="true">
            <meta-data
                android:name="android.support.customtabs.trusted.SMALL_ICON"
                android:resource="@drawable/ic_notification_icon" />
            <intent-filter>
                <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </service>
        <activity android:name="com.google.androidbrowserhelper.trusted.NotificationPermissionRequestActivity" />
...

Smartphone (please complete the following information):

  • Device: Galaxy A16 5G
  • OS: Android 16, One UI version 8.0
  • Browsers Installed Chrome
  • Browser Versions 142.0.7444.171
  • implementation 'com.google.androidbrowserhelper:androidbrowserhelper:2.6.2'

Additional context
compileSdkVersion 36
namespace "com.myapp.www.twa"
defaultConfig {
applicationId "com.myapp.www.twa"
minSdkVersion 23
targetSdkVersion 35

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions