-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug + fix: Push Notification handlers not called after webViewWebContentProcessDidTerminate #6676
Comments
I investigated the bug a little further and I think the fix is quite easy: adding this code in
Note: as this problem may occur with every plugin, I think it makes sense to not just tackle it with the push notifications plugin. As all event listeners are dead anyway after reloading the webview, I think it makes sense to clear them completely on the native side as well. |
I was experiencing this problem for a long time. It is not until today I realized it's caused by webview crash. And the fix looks really simple and promising! Testing it now and hope it works. |
I tried this but it does not work reliably. I think the problem might be So I added the some code to test and retry self.plugin?.bridge?.webView?.evaluateJavaScript("void window.Capacitor.fromNative", completionHandler: {(_, error) in
if let error = error {
CAPLog.print("⚡️ Failed to test webview (crashed?)")
CAPLog.print("⚡️ Error: " + error.localizedDescription)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.didReceive(response: response)
}
} else {
self.plugin?.notifyListeners("pushNotificationActionPerformed", data: data, retainUntilConsumed: true)
}
}) Ideally this should be added to Update: it seems that this approach is neither stable, still needs some improvement. |
@vilic interesting idea! Do you use it in combination with my fix or just yours?
when I tested it as described in my initial post, it worked reliably for me. How did you test it? On a simulator or real device? And which ios / iphone version did you use? |
@hermitdemschoenenleben Just mine. I test it by waiting till the second day and click the morning notification. 😂 I tried to simulate the situation by deliberately creating out of memory situation to crash Safari, but as the app is still active, the behavior seems different. As I don't know how long is long enough, I just wait for a whole night... And I tested on a real device with latest stable iOS 16. |
I can confirm that although progress on this issue appears to have reached a plateau, it's still an important issue. As it stands, push notification handlers are intermittently broken, with actions not notified to the app if it's not in a "fresh enough" state in the background. |
Seeing this also. In our case a reliable reproduction (without any artificial process killing) is to leave the app overnight. In the morning, the first notification fails to invoke the pushNotificationActionPerformed listener. |
This is a fundamental and frequent use case - and it's been broken for almost a year. I would urge it's given some attention, as I'm at a loss for how the issue can be worked around. |
Bug Report
In our ios app we found that a click on a push message sometimes doesn't execute the javascript push message handlers. We found out that this happens after the webview process has been shut down in background (see also #5488 and #2379) which may happen due to memory pressure. This shutdown calls
webViewWebContentProcessDidTerminate
which reloads the app. After this reload, push notification handlers aren't executed.This issue can be reproduced reliably (see code reproduction below).
Update: I now think this problem isn't specific to the push notifications plugin. I think it's a general problem caused by not clearing plugins' event listeners after reloading the webview. See my comment for a suggested fix.
Capacitor Version
Platform(s)
ios
Current Behavior
After
webViewWebContentProcessDidTerminate
, a tap on a push message just opens the app but doesn't callpushNotificationActionPerformed
.Expected Behavior
After app-reload following
webViewWebContentProcessDidTerminate
, push messages that were delivered to the native layer in the meantime should be replayed such that the web app may handle them.Code Reproduction
test-push-message.apns
to the simulator to simulate a push messagekill $(pgrep -P $(pgrep launchd_sim) 'com.apple.WebKit.WebContent')
to kill the webview process (taken from https://stackoverflow.com/a/73609765/5895643 ). This simulates what happens under memory pressure.test-push-message.apns
to the simulator againAdditional Context
The text was updated successfully, but these errors were encountered: