fix: iOS push subscription gets lost #1802
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Partial (final) fix of #756, 1: (push notifications continue to be lost #411)
Sometimes an
await showNotification
can be considered as an hidden push notification (like those spam websites), when 3 of those gets recognized as 'hidden' consecutively, Apple revokes the subscription.We need to tell the service worker that the work is finished (sending a notification) and we could do this by using
event.waitUntil
1 instead ofawait
This PR aligns showNotification calls with Apple's recommended way, which is
event.waitUntil(showNotification)
.Screenshots
n/a
Additional Context
This measure aligns our service worker with Apple's vision of how push notifications should work and it should be cross-platform. Not having Android I would need some test on it to see if notifications get sent correctly (Chrome didn't have problems)
This is part of a series of fixes tracked on #1794
Edit: I just found this comment, which is correct but weirdly enough
return await showNotification
sometimes creates a notification without telling the service worker that it happened, causing a 'silent notification'.event.waitUntil
tells the service worker that work is happening and doesn't return a Promise1I can be incorrect in evaluating what is happening here
Passing
event
fromonPush
tomergeAndShowNotification
should ensure thatshowNotification
gets done within the same context not violating Apple's requirementChecklist
Are your changes backwards compatible? Please answer below:
Yesnt, I need to test with Android
On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
6, tested only on iOS, so far no lost push subscription in a 2-day test environment.
For frontend changes: Tested on mobile, light and dark mode? Please answer below:
n/a
Did you introduce any new environment variables? If so, call them out explicitly here:
No
Footnotes
The ExtendableEvent.waitUntil() method tells the event dispatcher that work is ongoing. It can also be used to detect whether that work was successful. In service workers, waitUntil() tells the browser that work is ongoing until the promise settles, and it shouldn't terminate the service worker if it wants that work to complete.
waitUntil specification ↩ ↩2