ServiceWorkerRegistration.tsx 471 B

1234567891011121314151617181920
  1. "use client";
  2. import { useEffect } from "react";
  3. export function ServiceWorkerRegistration() {
  4. useEffect(() => {
  5. if ("serviceWorker" in navigator) {
  6. navigator.serviceWorker
  7. .register("/sw.js")
  8. .then((registration) => {
  9. console.log("SW registered: ", registration);
  10. })
  11. .catch((registrationError) => {
  12. console.log("SW registration failed: ", registrationError);
  13. });
  14. }
  15. }, []);
  16. return null;
  17. }