GoogleChrome / GoogleChrome/android-browser-helper

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

Open
#563 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
832
Forks
370
Avg merge
1d 3h
Merged PRs (30d)
6

Description

**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**
```

package="com.myapp.www.twa">









...
```

**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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.