8

I want to test OneSignal push notifications on localhost before I deploy my app to a remote server.

I followed the instructions provided by the documentation. When I enter http://localhost as the site url I get an error message that says:

localhost is already taken. Please enter a different name.

Is there a way to use OneSignal on localhost ?

Abdelaziz Mokhnache
  • 4,269
  • 3
  • 25
  • 35

6 Answers6

9

It should be https://localhost not http://localhost. OneSignal treats localhost as secure connections.

Abdelaziz Mokhnache
  • 4,269
  • 3
  • 25
  • 35
  • This may not be related, but I assume you got localhost working. Did you get the same issue like I get here: https://github.com/OneSignal/OneSignal-Website-SDK/issues/281. If yes, how do you solved it? – natterstefan Nov 15 '17 at 10:46
  • sorry @StefanN. I got localhost working but I didn't get your an issue similar to your one .. I followed the official docs and it was fine – Abdelaziz Mokhnache Nov 16 '17 at 22:11
  • It's not working form me, my url is: `localhost:3000` (react) – Md. A. Apu Nov 04 '22 at 11:05
3

Besides configuring OneSignal via dashboard, your OneSignal.init in your browser call must have the allowLocalhostAsSecureOrigin option:

OneSignal.init({
  allowLocalhostAsSecureOrigin: true,
  ...
})

More at https://documentation.onesignal.com/docs/web-push-setup-faq#section-how-do-i-test-my-site-on-a-local-environment

Tomás Lima
  • 313
  • 2
  • 9
1

read in this doc https://documentation.onesignal.com/docs/web-push-setup-faq#section-how-do-i-test-my-site-on-a-local-environment- and localhost must run in port 8000

Muhammad Rosyid
  • 178
  • 3
  • 7
1

You may use Postman. Just follow this steps, found at: One Signal documentation

Surprisingly, simple. Enjoy.

Nowdeen
  • 1,401
  • 14
  • 20
0

For anyone else struggling with this, the answer is to add 'http://localhost' but when the configurator comes back with a message similar to 'localhost is already taken. Please enter a different name.' jut scroll down and type in a different subdomain. It's not very intuitive but that worked for me.

belzebu
  • 810
  • 7
  • 25
0

In order to test onesignal push notifications over localhost, you should enable https://localhost on your test environment. The following great post help me to setup it on macos, but I think you could implement it in other operative systems:

https://medium.com/@jonsamp/how-to-set-up-https-on-localhost-for-macos-b597bcf935ee

When you are able to start your web server at https://localhost:8080 , you should configure on OneSignal App the following:

Site Url :  https://localhost:8080
Check "My site not fully HTTPS"
CHOOSE A LABEL :  your-test-env.OS.TC

By completing the setup suggested by Onesignal documentation, you will be able to test push notifications on your test environment.

Jorge Valvert
  • 927
  • 1
  • 11
  • 20