Skip to content
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

[User model] [Fix] macOS Safari prompting and subscribing #1062

Merged

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Jul 26, 2023

Description

1 Line Summary

Fix macOS Safari error "Push notification prompting can only be done from a user gesture." when prompting for notification permission and registering for push.

Details

  • Safari's legacy prompting API (window.safari.pushNotification.requestPermission()) doesn't allow awaiting for any I/O which was causing the prompting error. Commits:
  • After prompting was fixed Safari wasn't registering for push due to a few changes that didn't come over correctly from PR Feat/safari vapid #1002. Commits:

Validation

Tests

  • Tested with Safari 16.4 on macOS 13.3.1, ensured prompting worked and a subscription record was created on OneSignal's server.
  • Tested end-to-end with iOS 16.5, ensuring notifications display as well.
    • Unsure if this was working before this PR, since it works different from macOS Safari
  • Tested refreshing the page to ensure no behavior changes with session counts. (referring to changes in commit b724a62)
  • Automated tests were not added since it isn't feasible to cover all I/O Promises that could happen in the chain. Additionally Legacy Safari will be deprecated in the future.

Info

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets



This change is Reviewable

This check is no longer needed as the session manager and model repo
handle these checks.

The original motivation to remove this is to address a macOS Safari
notification permission prompting issue where you can't await on I/O,
otherwise the prompting is flagged not done from an end-user
interaction. The isPushNotificationsEnabled() does disk I/O which we
removed in this commit.
Since we no longer support the os.tc workaround there is no need to
check the the indexDb for user preferences. Native notification
permission status is checked later making this unnecessary as well from
normal HTTPS setups.
Corrected missing logic changes that PR #1002 introduced in main but
were not accounted for in the last rebase.

Tested on masOS 13.3.1 with Safari 16.4 to confirm the browser
subscribes to push correctly with the backend.
Copy link
Contributor

@rgomezp rgomezp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally approved

/*
Within the same page navigation (the same session), do not register for
push if the user is already subscribed, otherwise the user will have its
session count incremented on each page refresh. However, if the user is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you confirm the session count is not incrementing even after the refresh? What is the impact on other browsers? From first glance it doesn't appear this code was Safari-specific.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the "Tests" section in this PR to provide more details on this.

Base automatically changed from user-model/fix-user-property-updates-before-subscription-create to user-model/v1 July 28, 2023 18:38
@jkasten2 jkasten2 merged commit f1306e9 into user-model/v1 Jul 28, 2023
2 checks passed
@jkasten2 jkasten2 deleted the user-model/fix-macos-safari-prompting-and-subscribing branch July 28, 2023 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants