Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
Este método está disponible en un contexto de trabajador de servicio

Estaba tratando de implementar Firebase Web Push Notifications en mi sitio web. He estado tratando de trabajar con firebase (versión web 9)

Estoy usando la versión: 9.8.1

Al implementar onBackgroundMessage, obtuve lo siguiente:

 onBackgroundMessage.ts:33 Uncaught FirebaseError: Messaging: This method is available in a service worker context. (messaging/only-available-in-sw). at onBackgroundMessage$1 (onBackgroundMessage.ts:33:25) at onBackgroundMessage (api.ts:170:10)

alguien puede ayudar

A continuación se muestra lo que he escrito.

 <script type="module"> import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js"; import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-analytics.js"; import { getToken, onMessage } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-messaging.js"; import { getMessaging,onBackgroundMessage } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-messaging-sw.js"; const firebaseConfig = { apiKey: "xxxxxxx", authDomain: "xxxxxxx", projectId: "xxxxxxx", storageBucket: "xxxxxxx", messagingSenderId: "xxxxxxx", appId: "xxxxxxx", measurementId: "xxxxxxx" }; const app = initializeApp(firebaseConfig); const analytics = getAnalytics(app); const messaging = getMessaging(app); getToken(messaging, { vapidKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' }).then((currentToken) => { if (currentToken) { console.log(currentToken); } else { alert('No registration token available. Request permission to generate one'); } }).catch((err) => { console.log('An error occurred while retrieving token. ', err); }); onMessage(messaging, (payload) => { console.log('Message received. ', payload); }); onBackgroundMessage(messaging, (payload) => { console.log('[firebase-messaging-sw.js] Received background message ', payload); if (!(self.Notification && self.Notification.permission === 'granted')) { return; } self.registration.showNotification(payload.data.title, { body: payload.data.body, icon: 'icon-512x512.png', badge: '/favicon.ico', tag: 'renotify', renotify: true, }) .then(() => self.registration.getNotifications()) .then(notifications => { setTimeout(() => notifications.forEach(notification => notification.close()), 3000); }); }); </script>

¿Qué he hecho mal?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!