Skip to content

[Bug]: PWA Service Worker Scope Restricts Offline Caching on /pos Route #327

Description

@master-mind-gru

Issue Search Confirmation

  • I have searched existing open and closed issues and this is not a duplicate

Bug Description

The application's Progressive Web App (PWA) initialization fails to cache assets or operate offline when installed directly via the browser's install button due to a strict security directory scope mismatch.
The Problem:
Service Worker Script: Served from /assets/pos_next/pos/sw.js

Target Interface Route: Runs at /pos

Because the service worker file is nested inside the /assets/ directory structure, standard browser security mechanisms limit its operational scope exclusively to that asset subdirectory. As a result, it is blocked from intercepting network requests or orchestrating background sync tasks for the active checkout counter at the root-level /pos path.

This causes offline functionalities to break out of the box on cloud hosting layers (like Frappe Cloud) where custom web server rewrites cannot be easily injected by the user.

Steps to Reproduce

Open the POSNext terminal page at /pos.

Install the application locally using the standard browser address bar prompt.

Simulate network loss or clear cache.

The application fails to mount gracefully offline due to a Service Worker registration restricted scope error in the browser console.

Expected Behavior

Recommended Code Corrections:
To make the PWA architecture truly platform-independent, please implement either adjustment in the codebase core:

Option 1: Adjust the worker registration logic to explicitly enforce a root path target configuration { scope: '/' } and pass down a Service-Worker-Allowed: / response header via the backend controller when delivering the sw.js asset file.

Option 2: Adjust the underlying application directory routing to serve the sw.js asset script dynamically directly from the primary site root environment instead of deep within the static public assets hierarchy.

Actual Behavior

Recommended Code Corrections:
To make the PWA architecture truly platform-independent, please implement either adjustment in the codebase core:

Option 1: Adjust the worker registration logic to explicitly enforce a root path target configuration { scope: '/' } and pass down a Service-Worker-Allowed: / response header via the backend controller when delivering the sw.js asset file.

Option 2: Adjust the underlying application directory routing to serve the sw.js asset script dynamically directly from the primary site root environment instead of deep within the static public assets hierarchy.

Screenshots / Screen Recordings

https://private-user-images.githubusercontent.com/232073080/604979519-13b0a35c-16f1-4e5a-a938-dff9a8749152.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODIzNzg0NjMsIm5iZiI6MTc4MjM3ODE2MywicGF0aCI6Ii8yMzIwNzMwODAvNjA0OTc5NTE5LTEzYjBhMzVjLTE2ZjEtNGU1YS1hOTM4LWRmZjlhODc0OTE1Mi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNjI1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDYyNVQwOTAyNDNaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT04ZWY4N2I0NzAxM2I0M2NmNmVjZjgwNmUzYTUyNjhlNDZlYmViNDQzMjAyMTExZTZkMGRjZjk4ZDI2MDcwNjc3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.zGSmcjQl8-t2AE30QisgjxWmyDXN3ah_pE7jDUcAkFM

Browser Console Errors

POS Next Version

1.13.0 (Latest)

Exact Version (if known)

1.16.0

Frappe Framework Version

15

ERPNext Version

15

Browser

Chrome

Browser Version

149.0.7827.158

Operating System

Windows 11

Deployment Type

Self-hosted (Production)

Bug Frequency

Always (100% reproducible)

Offline Mode

No - Online mode only

Additional Context

No response

Server Logs (if applicable)

Pre-submission Checklist

  • I have provided screenshots showing the issue
  • I have included my application version information
  • I have provided clear steps to reproduce the issue
  • I have checked browser console for errors and included them if present

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions