Custom Service Worker?

Is it possible to create my own service worker? I can create a js file under Public and point to it but I am getting console errors and as far as I can tell these files are hosted externally on a static site, which means it’s not useful for a service worker that needs to be on the main domain (and preferably in root).

Is there another way for me to incorporate this?

Thanks

p.s.
console error: “Uncaught (in promise) TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.”

Hi Jay,
How do you try to point to it and where from?
Roi.

1 Like

I’ve placed it in push-worker.js under the Public folder. Then in my snippet which i put in the head using the custom tracking and analytics, i reference it with workerUrl: '/public/push-worker.js':

// 86acbd31cd7c09cf30acb66d2fbedc91daa48b86:1530568822.7 !function(n,t,c,e,u){function r(n){try{f=n(u)}catch(n){return h=n,void i(p,n)}i(s,f)}function i(n,t){for(var c=0;c<n.length;c++)d(n[c],t); }function o(n,t){return n&&(f?d(n,f):s.push(n)),t&&(h?d(t,h):p.push(t)),l}function a(n){return o(!1,n)}function d(t,c){ n.setTimeout(function(){t(c)},0)}var f,h,s=[],p=[],l={then:o,catch:a,_setup:r};n[e]=l;var v=t.createElement("script"); v.src=c,v.async=!0,v.id="_uasdk",v.rel=e,t.head.appendChild(v)}(window,document,'https://web-sdk.urbanairship.com/notify/v1/ua-sdk.min.js', 'UA', { workerUrl: '/public/push-worker.js', appKey: 'DyydZwJUQI6SMcQu54lJNQ', token: 'MTpEeXlkWndKVVFJNlNNY1F1NTRsSk5ROlJfTmdCMWJqRm94NVZtZ24zV1F1THh0azNKam9ZbUdyenNDaUF6M2pEN3M', vapidPublicKey: 'BAUNn6gLGUxMR89IUux7zByMjhi5FXsqVKcUMo1-eIrHyRqpg6ql_vxnLlRLF78JLI-3A7NHqbopZr7976rdREE=' }); </script> <p>(based on this: <a href="https://docs.urbanairship.com/platform/web/#service-worker" class="inline-onebox-loading">https://docs.urbanairship.com/platform/web/#service-worker</a>)</p>

Any thoughts on this?

Hello Jay,

I see that you are trying to create an element with that code, and this is not possible unfortunately, so this will not work.

Best,
Majd

To put another way, is there anyway for me to incorporate my own service worker?

Hello Jay,

Yes it is possible using the iframe element, however creating/modifying/deleting elements with workers will not work.

Check out this page for developers on how it is implemented.

Best,
Majd

That page keeps prompting: “This page isn’t working
dev.wix.com didn’t send any data.
ERR_EMPTY_RESPONSE”

Old post from 2018 reappearing, closed.