Need Help Placing Service-worker.js' in Root Directory for Shopify Web Push Notifications

Need Help Placing Service-worker.js' in Root Directory for Shopify Web Push Notifications

etersongray
Visitor
3 0 0

I'm facing a problem while trying to implement web push notifications for my Shopify store using the Firebase Cloud Messaging Service. In order to enable this feature, I need to upload the 'Service-worker.js' file to the root directory. However, I'm encountering difficulties in placing the file in the desired location. Has anyone successfully integrated web push notifications on Shopify and managed to upload the 'Service-worker.js' file to the root directory? Any insights or guidance on overcoming this issue would be greatly appreciated! 

 

Replies 5 (5)

etersongray
Visitor
3 0 0

I am not getting any answer. kindly do assist me. 

SonuSantosh
Shopify Partner
4 1 0

hey Etersongray,
you can use app proxy or can use shopify CDN directly for giving a path for your service worker to the online store, after that you need to register that service worker to root path using navigator in JS script , for reference check this .
hope this will help you..

Veronika
Shopify Partner
3 0 0

Hi! Could you, please, explain how to register the service worker? I am implementing an app for web push.

I added it through the assets, but I got an error: "The path of the provided scope ('/') is not under the max scope allowed ('/cdn/shop/t/1/assets/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope."

 

If I have the correct info, currently, it is impossible to edit the header. I tried to solve the issue by adding the following path to the script: {'service-worker': {'relUrl': '{{ 'sw.js' | asset_url }}'} }

I did not receive error then but still the subscribers are not transferred from Shopify to my system. I assume that is because the file was not registered in the root.

randidev1
Shopify Partner
1 0 0

Hi,
have you find the solution?

Veronika
Shopify Partner
3 0 0

Hello! Yes, the possible solution is to serve up service worker from your app proxy sub-path, then the scope will cover only your app and it will allow to use web push. But I haven't implemented it yet.