Add the below condition inside the try block present in the getTokenFirebase function with this:
try
getTokenFirebase
try { if (typeof window !== 'undefined' && 'serviceWorker' in navigator) { ... } }