Service worker not working in when converted website to apk with Capacitor

88 Views Asked by At

I have a Ionic React Capacitor project in which I am using a service worker to upload a file to a server. The service worker gets registered and works as expected on web, but when I convert it to mobile application in .apk then the service worker is not getting registered.

Msg: Service Worker registration failed: TypeError: Failed to register a ServiceWorker for scope ('https://localhost/') with script ('https://localhost/background-worker.js'): An unknown error occurred when fetching the script.

This is the error message that I see in the logcat in android studio.

This is my capacitor.config.js file

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'com.technopolis.aipd',
  appName: 'TherapEZ',
  webDir: 'build',
  bundledWebRuntime: false,
  plugins: {
    Camera: {
      permissions: [
        "camera",
        "microphone"
      ]
    }
  },
  server: {
    androidScheme: "https"
  }
};

export default config;

I tried changing hostname and androidScheme a couple of times and referred a lot of things on the internet, but nothing seems to workout.

I am expecting the service worker to get registered and work the same way as it works on my browser.

0

There are 0 best solutions below