From f00e5515e41fd72b84382350605c50ed4a938448 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Thu, 4 Jun 2020 14:49:39 -0300 Subject: [PATCH] FIX: Service Worker URL was broken Behavior was changed in #9966, which made the URL be relative. If the user landed in a topic, for example, the browser was given a service worker URL under that specific topic URL, which was a 404. Fixes broken PWA install and broken push notifications --- .../discourse/app/initializers/register-service-worker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/initializers/register-service-worker.js b/app/assets/javascripts/discourse/app/initializers/register-service-worker.js index c22b7e98fff..6b5927d5114 100644 --- a/app/assets/javascripts/discourse/app/initializers/register-service-worker.js +++ b/app/assets/javascripts/discourse/app/initializers/register-service-worker.js @@ -1,5 +1,5 @@ import { isAbsoluteURL } from "discourse-common/lib/get-url"; -import getURL from "discourse-common/lib/get-url"; +import getAbsoluteURL from "discourse-common/lib/get-url"; export default { name: "register-service-worker", @@ -33,7 +33,7 @@ export default { }); navigator.serviceWorker - .register(`${getURL(Discourse.ServiceWorkerURL)}`) + .register(getAbsoluteURL(`/${Discourse.ServiceWorkerURL}`)) .catch(error => { // eslint-disable-next-line no-console console.info(`Failed to register Service Worker: ${error}`);