What I’m trying to do:
I am trying to use the OneSignal javascript library along with anvil’s background tasks to enable push messaging in my app. I have imported the javascript libraries in ‘Native Libraries’. My requests are logged in the server with code 200, indicating that everything is working fine on OneSignal’s end. The notifications permissions popup also works fine.
But, the web worker is not registering properly. The problem arises when trying to get the push notifications client-side.
When debugging I get an error that Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://anvil.works’) does not match the recipient window’s origin (‘https://xxxxx.anvil.app’).
I am not having any luck getting this to work. Can you provide a little more clarity? The only options I see in the OneSignal.com settings are:
“Path to service worker files”
“Service worker registration scope”
Did you ever get OneSignal properly integrated with your app again? I am having the same error as @chad63e which appears to stem from multiple service workers, and since we don’t have access to the Anvil SW, I cannot merge them.
I didn’t try it out again. I started using Firebase which I found to answer my needs better.
I created a library for it - Push Notifications Dependency. However, while it still works, the current version of the library is outdated as per Google changes.
You can try this one out if you want to use Firebase. It uses the current supported version from Google.
Do you know it works with native push on iOS / Android? I think if there is no .p12 file used for registering on iOS you won’t be able to send push notifications when the app is closed.