admin管理员组

文章数量:1327945

Firefox 62.0.2 (64 bit). Windows 7 x64. Write code from this in firebase-messaging-sw.js of our site:

self.addEventListener('notificationclick', event => {
    event.waitUntil(async function() {
        throw "1";//this line for debug only
    }());
});

Code raise exception "InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable" in Firefox on the event.waitUntil(). In Chrome work normally. Why? How I can fix it?

P.S. I am looking for the answer of the second day. :(

Firefox 62.0.2 (64 bit). Windows 7 x64. Write code from this in firebase-messaging-sw.js of our site:

self.addEventListener('notificationclick', event => {
    event.waitUntil(async function() {
        throw "1";//this line for debug only
    }());
});

Code raise exception "InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable" in Firefox on the event.waitUntil(). In Chrome work normally. Why? How I can fix it?

P.S. I am looking for the answer of the second day. :(

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Sep 30, 2018 at 7:11 Alexandr ShchetininAlexandr Shchetinin 931 silver badge9 bronze badges 3
  • so this is in a service worker, correct? – Jaromanda X Commented Sep 30, 2018 at 7:45
  • Yes, it is service worker – Alexandr Shchetinin Commented Sep 30, 2018 at 7:48
  • Did you find a fix? Getting this issue with a Vimeo player. – Alex Lacayo Commented Nov 8, 2018 at 8:51
Add a ment  | 

1 Answer 1

Reset to default 6

Had this problem in Firefox 63. And in Chrome everything is working fine. My service-worker code was:

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

firebase.initializeApp({
    'messagingSenderId': '...'
});
var messaging = firebase.messaging();

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

I accidentally found this: stopImmediatePropagation in firebase-messaging.js. I moved my event-listener in the beginning of my service-worker (before importScripts):

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

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

And the handler started working in Firefox.

P.S. Handler started working fine, but after this manipulation the error was thrown by firebase-messaging library. event.stopImmediatePropagation() helped:

self.addEventListener('notificationclick', function (event) {
    event.stopImmediatePropagation();
...
}

本文标签: