OneSignal / react-onesignal

React OneSignal Module: Make it easy to integrate OneSignal with your React App!
Other
74 stars 23 forks source link

[Bug]: Safari permissions issue on onesignal permissions prompt #144

Open mramzan18 opened 1 month ago

mramzan18 commented 1 month ago

What happened?

The Safari site URL, icon size, or push certificate is invalid, or Safari is in a private session. whenever OneSignal.Slidedown.promptPush() is executed, prompt shown on safari browser and user click on allow button it instantly show this message 'The Safari site URL, icon size, or push certificate is invalid, or Safari is in a private session.' inside console and do not receive any push notifications. i tried to remove notification icon on onesignal dashboard as well .p12 file as well

import { useEffect, useState } from 'react' import OneSignal from 'react-onesignal' import { useSelector } from './useAppSelector'

const useOneSignalConfig = () => { const { oneSignalExternalId } = useSelector(({ auth }) => auth)

const [isInitialized, setIsInitialized] = useState(false)

useEffect(() => {
    const initOneSignal = async () => {

        try {

            await OneSignal.init({
                appId: import.meta.env.VITE_ONESIGNAL_APP_ID, // Replace with your actual OneSignal App ID
                 allowLocalhostAsSecureOrigin: true, // This line is important for local development
                serviceWorkerPath: '/OneSignalSDKWorker.js', // Ensure this points to the correct service worker file
            })

            await OneSignal.Slidedown.promptPush()

            setIsInitialized(true)
        } catch (error) {

        }
    }

    initOneSignal()
}, [])

useEffect(() => {
    const loginOneSignal = async () => {
        try {
            await OneSignal.login(String(oneSignalExternalId))

        } catch (error) {

        }
    }

    if (isInitialized && oneSignalExternalId) {
        loginOneSignal()
    }
}, [isInitialized, oneSignalExternalId])

return { isInitialized }

}

export { useOneSignalConfig }

What browsers are you seeing the problem on?

Safari

What operating system are you running?

macOS Sonoma 14.4.1

Steps to reproduce?

using "react-onesignal": "^3.0.1",

What did you expect to happen?

Push notifications on safari

Relevant log output

No response

jkasten2 commented 1 month ago

@mramzan18 This could be happening due to a macOS bug that happens some systems. Can you try the repo steps here to isolate the problem? https://forums.developer.apple.com/forums/thread/746498

sanishkr commented 4 weeks ago

I am getting this error on onesignal prompt click as well "The Safari site URL, icon size, or push certificate is invalid, or Safari is in a private session." [safari desktop] v:17.4.1

Its documentation says, no need to add push certificate after safari 15. I am sure, I am not using private session. And other 2 reason, likely not an issue, with same site, I tried on safari ios (after adding site to home screen), it works fine.

Dont know what else to check. At least, some way to find that this browser cant get notification, so I can disable my button on site can help.

jkasten2 commented 3 weeks ago

@sanishkr can you check if this is due to your system being affected by the Apple bug I noted above?

Here is a direct link to the MRE (minimal reproducible example): https://public-mre-macos-window-safari-prompt-bug.glitch.me/

sanishkr commented 3 weeks ago

I tried, it gives this as response in box below: SafariLegacy.subscribe:response:{"deviceToken":null,"permission":"denied"}

mramzan18 commented 2 weeks ago

@sanishkr have you found any solution?

sanishkr commented 2 weeks ago

Nope, not even any workaround yet. It is either with onesignal devs or safari devs from apple to fix this.

mramzan18 commented 2 weeks ago

@jkasten2 Safari Version 17.4.1 (19618.1.15.11.14)

Screenshot 2024-06-10 at 1 25 21 PM
mramzan18 commented 2 weeks ago

@sanishkr if you found any workaround then let me know as well