OneSignal-Website-SDK
OneSignal-Website-SDK copied to clipboard
OneSignal.isPushNotificationsEnabled() does not work in Safari iframe
Description:
code connected to isPushNotificationsEnabled() tries to call IDBFactory.open() which throws a security exception when called inside an iframe in Safari.
Steps to Reproduce Issue:
- a.html:
<html><body><iframe src=b.html></iframe></body></html>
- b.html:
<html><body>
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "...",
});
OneSignal.isPushNotificationsEnabled(function(b) {
console.log ('push enabled: '+b);
});
});
</script>
</body></html>
- Open a.html in Safari. Open developer tools. In debug panel, put a break point for "All Exceptions". Reload.
- Security Exception thrown trying to IDBFactory.open().
Thank you for reporting
Note this prevents the solution recommended on your page:
When user is subscribed to my.example.com, open an iframe to www.example.com. Call OneSignal.isPushNotificationsEnabled() in the iframe, which will return true for this user. Call OneSignal.setSubscription(false) in the iframe to unsubscribe the user from www.example.com, since they are already subscribed to my.example.com.
https://documentation.onesignal.com/docs/web-push-complex-integrations#section-override-subscription-status
Currently we are not sure how to implement OneSignal with a site that uses www1.example.com, www2.example.com, etc. since the recommended solution does not work.
This is what happens when running my app in the Brave browser.
@jones-rr , sorry for the delay. Are you still seeing the issue?
@ejlocop , unfortunately Brave is not currently a supported browser. We hope to add support soon
@rgomezp last time I checked - yes. Our site has www1.example.com, www2.example.com, etc. and we are not sure how to implement web push for this case, since the OneSignal recommendation is iframe but that is not supported for Safari.
@jones-rr , Can you confirm your site is HTTP and not HTTPS?
@rgomezp it's all https
My mistake. Understood. Can you include a full stack trace that includes more than just the database security exception:?
@rgomezp see attached
Howdy, Thanks for the screenshot. Would you be willing to share your site URL so we can take a look ourselves?
Closing due to no response
You can close it if you want, but whether or not I can publish a live link on our site that you can use to investigate does not mean it's not a bug.
Reproduce it yourself using the instructions I gave up above.
Using an iframe to share data between multiple domains an end-user visits isn't going to work any more due to Chrome's CHIPS / Storage Partitioning. Also, Safari already does this as well.
@jones-rr Is this your use case?