The controlling service worker does not support amp-web-push

Viewed 284

I am working on amp web push notification using FCM and also using custom service worker but sometime i got The controlling service worker does not support amp-web-push error in console.

code of service worker:-

importScripts('https://www.gstatic.com/firebasejs/5.5.9/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.5.9/firebase-messaging.js');
var swScope ="https://www.example.com/" ;
const WorkerMessengerCommand = {
    AMP_SUBSCRIPTION_STATE: 'amp-web-push-subscription-state',
    AMP_SUBSCRIBE: 'amp-web-push-subscribe',
    AMP_UNSUBSCRIBE: 'amp-web-push-unsubscribe',
};
self.addEventListener('message', event => {
    const { command } = event.data;

    switch (command) {
        case WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE:
            onMessageReceivedSubscriptionState();
            break;
        case WorkerMessengerCommand.AMP_SUBSCRIBE:
            onMessageReceivedSubscribe();
            break;
        case WorkerMessengerCommand.AMP_UNSUBSCRIBE:
            onMessageReceivedUnsubscribe();
            break;
    }
});
function onMessageReceivedSubscribe() {
    var _FCMconfig = {
        messagingSenderId: 'xyz'
    };
    firebase.initializeApp(_FCMconfig);
    FCMmessaging = firebase.messaging();
    var dbToken = getTokenDataFromIndexDB();
    dbToken.then(function (indexDbData) {
        FCMmessaging.getToken()
            .then(function (fcmDbToken) { })
            .catch(function (err) { });
    });
};
function onMessageReceivedSubscriptionState() {
};
function onMessageReceivedUnsubscribe() {

};
self.addEventListener('install', function (event) {
    event.waitUntil(self.skipWaiting());
});

self.addEventListener('activate', function (event) {
    event.waitUntil(self.clients.claim());
});
function broadcastReply(command, payload) {

};
function getTokenDataFromIndexDB() {
    return firebase.messaging().tokenDetailsModel.getTokenDetailsFromSWScope(swScope);
};

I have checked my amp pages and getting green signal from amp validation.I searched on google also but didn't find any solution for this issue.

0 Answers
Related