Function isPWA

  • Detects whether the current app is running as a Progressive Web App (PWA).

    • Development:

      • Uses the NEXT_PUBLIC_IS_PWA environment variable ('true' / 'false').
      • This allows developers to simulate PWA mode locally.
    • Production (client-side):

      • Returns true if the current hostname or pathname contains "pwa".
      • Examples: pwa.localhost:3000, pwa.itoll.com, or /pwa/home.
    • Production (server-side / SSR):

      • Defaults to true since window is not available.

    Returns boolean

    true if running as a PWA, otherwise false.

    // Development mode with NEXT_PUBLIC_IS_PWA=true
    process.env.NODE_ENV = 'development';
    process.env.NEXT_PUBLIC_IS_PWA = 'true';
    console.log(isPWA()); // Output: true

    // Production client-side on https://pwa.itoll.com
    console.log(isPWA()); // Output: true

    // Production client-side on https://itoll.com
    console.log(isPWA()); // Output: false