PWA inn appgyver web app

I had to create a javascript file and add the ref to manifest to head of all pages after next loads page, like this:

document.addEventListener('DOMContentLoaded', function() {
  function updateThemeColor(color) {
    var metaTag = document.querySelector('meta[name="theme-color"]');
    if (metaTag) {
      metaTag.setAttribute('content', color);
    }
  }

  function handleDarkMode() {
    var darkMode = localStorage.getItem('darkMode');

    if (darkMode === 'true') {
      updateThemeColor('#121212');
      console.log('darkMode'); 
    } else {
      updateThemeColor('#ffffff');
      console.log('lightMode'); 
    }
  }

  handleDarkMode();

  window.addEventListener('storage', function(event) {
    if (event.storageArea === localStorage && event.key === 'darkMode') {
      handleDarkMode();
    }
  });
});

function addManifestLink() {
  var link = document.createElement('link');
  link.rel = 'manifest';
  link.href = 'manifest.json';
  document.head.appendChild(link);
}
addManifestLink();

if ('serviceWorker' in navigator) {
  window.addEventListener('load', function() {
    navigator.serviceWorker.register('sw.js')
      .then(function(registration) {
        console.log('Service worker registered with scope:', registration.scope);
      })
      .catch(function(error) {
        console.log('Service worker registration failed:', error);
      });
  });
}

along with other things, this is how i got the service worker to register and the manifest to apply

my service worker is a minimum, with no attempt yet to apply offline cache:

self.addEventListener('fetch', function(event) {
    event.respondWith(fetch(event.request));
  });
  
  self.addEventListener('beforeinstallprompt', function(event) {
    event.preventDefault();
    var deferredPrompt = event;
  
    // Display your custom install prompt here
    // Example: Show a button or a custom UI to prompt the user to install the app
    
    // Handle the user's choice to install
    yourInstallButton.addEventListener('click', function() {
      deferredPrompt.prompt();
      deferredPrompt.userChoice.then(function(choiceResult) {
        if (choiceResult.outcome === 'accepted') {
          console.log('User accepted the install prompt');
        } else {
          console.log('User dismissed the install prompt');
        }
        deferredPrompt = null;
      });
    });
  });