【问题标题】:Firefox. InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable火狐。 InvalidStateError:尝试使用不可用或不再可用的对象
【发布时间】:2019-03-05 15:26:36
【问题描述】:

Firefox 62.0.2(64 位)。视窗 7 x64。在我们网站的 firebase-messaging-sw.js 中从this 编写代码:

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

在 Firefox 的 event.waitUntil() 中,代码引发异常“InvalidStateError:尝试使用不可用或不再可用的对象”。在 Chrome 中正常工作。为什么?我该如何解决?

附:我正在寻找第二天的答案。 :(

【问题讨论】:

  • 所以这是在服务人员中,对吗?
  • 是的,是服务人员
  • 您找到解决方法了吗?使用 Vimeo 播放器遇到此问题。

标签: javascript firefox push-notification web-push


【解决方案1】:

在 Firefox 63 中遇到了这个问题。在 Chrome 中一切正常。我的服务人员代码是:

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

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

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

我无意中发现了这个:stopImmediatePropagation in firebase-messaging.js。 我在我的 service-worker 的开头(在 importScripts 之前)移动了我的事件监听器:

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

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

处理程序开始在 Firefox 中工作。

附:处理程序开始正常工作,但在此操作之后,firebase-messaging 库引发了错误。 event.stopImmediatePropagation() 帮助:

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

【讨论】:

    猜你喜欢
    • 2016-04-30
    • 2014-05-21
    • 2013-09-24
    • 2014-05-19
    • 2013-12-08
    • 2013-10-08
    • 2022-08-18
    • 2013-06-17
    • 2013-12-01
    相关资源
    最近更新 更多