JavaScript onesignal error: window.OneSignal already defined as 'object'!

I am getting this error when I am trying to subscribe someone to notifications on localhost with xampp (with a custom domain:

window.OneSignal already defined as ‘object’!
Please make sure to define as 'window.OneSignal = window.OneSignal || ;

And I am also getting another error saying:

Installing service worker failed SecurityError: Failed to register a ServiceWorker for scope ( with script ( An SSL certificate error occurred when fetching the script.

Here is my js code:

window.OneSignal = window.OneSignal || [];

  OneSignal.push(function() {


      appId: "key",

      notifyButton: {

        enable: true,


      promptOptions: {

        slidedown: {

          enabled: true,

          autoPrompt: true,

          timeDelay: 20,

          pageViews: 3,

          actionMessage: "We'd like to show you notifications for the latest news and updates.",

        acceptButtonText: "ALLOW",

        cancelButtonText: "BLOCK",





And I did remember to put in:

<script src="" async=""></script>

Can you help me?

The error says that you need an SSL certificate for your custom domain.
I think that the people in our Server Config forum might have some help for you there.

Thanks!! After i fixed the certificate/ssl problem it fixed it! A long time ago, I was trying to get it working but I couldn’t. Now, I took the same tutorial, and it woks!