Skip to content

Commit

Permalink
fix: Fix ServiceWorker scope when Nextcloud installed in subfolder
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
  • Loading branch information
Koc committed Dec 6, 2024
1 parent ad045d6 commit 2e1cd23
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apps/files/src/services/ServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { generateUrl } from '@nextcloud/router'
import { generateUrl, getRootUrl } from '@nextcloud/router'
import logger from '../logger.ts'

export default () => {
Expand All @@ -11,7 +11,8 @@ export default () => {
window.addEventListener('load', async () => {
try {
const url = generateUrl('/apps/files/preview-service-worker.js', {}, { noRewrite: true })
const registration = await navigator.serviceWorker.register(url, { scope: '/' })
const scope = getRootUrl()
const registration = await navigator.serviceWorker.register(url, { scope })
logger.debug('SW registered: ', { registration })
} catch (error) {
logger.error('SW registration failed: ', { error })
Expand Down

0 comments on commit 2e1cd23

Please sign in to comment.