importScripts('https://www.gstatic.com/firebasejs/10.11.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.11.0/firebase-messaging-compat.js');

firebase.initializeApp({
    apiKey: "{apiKey}",
    projectId: "{projectId}",
    messagingSenderId: "{messagingSenderId}",
    appId: "{appId}",
});

self.addEventListener('notificationclick', function (event) {

    const url = event.notification && event.notification.data && event.notification.data && event.notification.data.FCM_MSG && event.notification.data.FCM_MSG.notification && event.notification.data.FCM_MSG.notification.click_action || null;
    if (url) {
        self.clients.openWindow(url);
    }
});

const messaging = firebase.messaging();