Web push: Browser behavior and unsubscribes
Learn how to unsubscribe from notifications and understand how browsers handle web push subscriptions
Web browsers can handle push subscriptions in multiple ways, allowing users to unsubscribe by changing their browser settings, or to create a new subscription by clearing their cache. This guide explains how different user actions can affect their push subscriptions, as well as listing the way that different browsers handle notifications received while the browser is closed.
How to Unsubscribe from Web Notifications
Each browser manages push notification subscriptions a little differently, but in most cases you can easily turn off push notifications aka unsubscribe or opt-out with these options:
Unsubscribe within Browser Settings
All browsers allow you to unsubscribe from individual or all sites within the Browser Settings. Usually you can search for "notifications" and it will guide you to the right page. You can copy-paste the following URLs based on the browser, to get you there faster:
- Chrome:
chrome://settings/content/notifications
(Learn more on Chrome's docs) - Edge:
edge://settings/content/notifications
(Learn more on Microsoft's docs) - Firefox:
about:preferences#privacy
scroll to Permissions > Notifications > Settings (Learn more on Mozilla's docs) - Safari: Settings > Websites > Notifications (Learn more on Safari's docs)
On these pages, just click the options to remove or block the website(s) you don't want notifications from.
Unsubscribe while on the Website
Most browsers have a "lock" or "settings" icon to the left of the URL. When on the site that sends you notifications, you can usually click these to see the Push Permissions you enabled and disable it.
If the website contains the OneSignal Bell Prompt or Custom Link prompt like the images below, you can click these to unsubscribe directly.
Clearing Cookies
What happens when subscriptions clear their browser cache and cookies?
Browsers have implemented the Web Push Standard in a way that when subscribers clear their browser cookies and cache, they get unsubscribed from notifications. This is because subscription data, such as the subscription_id, is stored in the browser's IndexedDB storage. Removing that data makes the browser "forget" that subscription.
However, clearing this data does not remove the permissions that have already been granted by the subscription to receive notifications in that browser.
If you are using an HTTPS site and did not select "My site is not fully https" in your OneSignal dashboard settings, then you can automatically re-subscribe users that return to your site after they clear their browser cache and cookies by making sure Auto Resubscribe is turned on in the configuration. If you are using a Custom Code setup, also make sure that autoRegister
is not in the init
call.
Due to the previous onesignal_id
being deleted from the browser, there is no reference to the user (previous onesignal_id
) so you will lose tag and other data unless you set up Aliases & External ID to persist the user within OneSignal and all relevant data.
However, users will not be auto-resubscribed if they change their Browser's Notification Permissions to "Ask" or "Block":
Users will also not be auto-resubscribed if they clear notifications from the Browser's Notification Settings.
How to Test the "Auto-Resubscribe" function
On your site, subscribe to receive notifications.
You can open up your browser's developer console and type:
OneSignal.User.PushSubscription._id;
- This will log your OneSignal subscription ID.
If a subscription ID was not logged in the console, then you are not successfully subscribed. Please see Troubleshooting Web Push for assistance if needed.
Next, in the browser settings, you can clear your browser history, or:
- Select the Lock button on your site next to the URL
- Select Cookies
- Select your site
- Click "Remove"
- Click "Done"
Refresh the page. You will not be prompted to resubscribe.
Open the browser console and input:
OneSignal.User.PushSubscription._id;
- This will be create a new OneSignal subscription ID for you.
If a new subscription ID is logged, then you have successfully resubscribed to your site after clearing your browser cache. If not, please see Troubleshooting Web Push for assistance.
Receiving Notifications When the Browser is Closed
Browsers behave differently across platforms. Please refer to the table below for support for receiving notifications even when the browser is closed.
Browser Name | Android | Windows | macOS |
---|---|---|---|
Chrome / Chromium | Yes | Yes | No |
Firefox | Yes | Yes | No |
Safari | N/A | N/A | Yes |
Opera | Yes | Yes | No |
Edge | Yes | Yes | No |
Chrome - Chrome runs as a background process by default even when all the windows are closed. As long as the background process is running, notifications will still be received. If the Chrome background process is not running, notifications will not be received.
Firefox - On Mac OS X, the process still exists even if windows are closed, and a notification can be received if all windows are closed (as long as there is still a dot in the dock showing Firefox is still running). On Windows, the process exits after all windows are closed so notifications cannot be received unless a Firefox window is still open.
Safari - Safari does not have to be running to receive notifications, as they are sent directly to the operating system. The user still has to sign up for Safari web notifications, but after that they will be received even when Safari is completely closed.
Subscribers have up to 3 days to retrieve the last known missing notification before messages expire permanently.
For example, suppose a subscriber was supposed to receive a Firefox web push notification, but Firefox was closed. If the subscriber opens Firefox within 3 days, the subscriber will receive only the last known web push notification that didn't expire. If the subscriber opens Firefox after 3 days, the web push notification sent more than 3 days ago will not be received.
Updated 2 months ago