Javascript 该网站已在后台Chrome-Firebase中更新

Javascript 该网站已在后台Chrome-Firebase中更新,javascript,google-chrome,firebase,firebase-cloud-messaging,Javascript,Google Chrome,Firebase,Firebase Cloud Messaging,当我在chrome上推送通知时,messaging.onMessage()不起作用(当我在页面上时),并且我看不到任何通知(当我离开页面时)。唯一显示的是一个弹出窗口,上面写着该网站已经在后台更新了,但我在firefox中没有这个问题。我环顾了一下这个问题,发现它是一个半常见的问题,但我无法修改代码以使其正常工作 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="U

当我在chrome上推送通知时,
messaging.onMessage()
不起作用(当我在页面上时),并且我看不到任何通知(当我离开页面时)。唯一显示的是一个弹出窗口,上面写着
该网站已经在后台更新了
,但我在firefox中没有这个问题。我环顾了一下这个问题,发现它是一个半常见的问题,但我无法修改代码以使其正常工作

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Notifications</title>
</head>
<body>

<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script src="app.js"></script>
</body>
</html>
firebase-messaging-sw.js

/**
 * Created by nikos on 13/7/2017.
 */
console.log('SW');
importScripts('https://www.gstatic.com/firebasejs/4.1.3/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.1.3/firebase-messaging.js');

var config = {
    apiKey: "AIz..",
    authDomain: "....firebaseapp.com",
    databaseURL: "https://....firebaseio.com",
    projectId: "locpushweb",
    storageBucket: "locpushweb.appspot.com",
    messagingSenderId: "..."
};
firebase.initializeApp(config);

const messaging = firebase.messaging();

// messaging.setBackgroundMessageHandler(function (payload) {
//     var data = JSON.parse(payload);
//     self.registration.showNotification(data.title, {
//         body: data.body,
//         icon: data.icon,
//         click_action: data.click_action,
//         time_to_live: data.time_to_live,
//         data: data.data,
//         tag: data.tag
//     });
// });
最后,这是curl命令:

curl -X POST -H "Authorization: key=AAAAZGd...." -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "http://localhost:8081"
  },
  "to": "cxfoMyjwsOY:APA91bFnOQlYxw3iPlbcc714wI5BFWLfEXvmT1FRTL0SJNuy1AOTfah4EKTdvoi1SvnX8SpD9CUD1D-I8GdKcIb-M1l65NFc8xhJNF2iBffERN9yWSNnN2_CHqodcpMMSyC_IDKZJ0GH"
}' "https://fcm.googleapis.com/fcm/send"
curl -X POST -H "Authorization: key=AAAAZGd...." -H "Content-Type: application/json" -d '{
  "notification": {
    "title": "Portugal vs. Denmark",
    "body": "5 to 1",
    "icon": "firebase-logo.png",
    "click_action": "http://localhost:8081"
  },
  "to": "cxfoMyjwsOY:APA91bFnOQlYxw3iPlbcc714wI5BFWLfEXvmT1FRTL0SJNuy1AOTfah4EKTdvoi1SvnX8SpD9CUD1D-I8GdKcIb-M1l65NFc8xhJNF2iBffERN9yWSNnN2_CHqodcpMMSyC_IDKZJ0GH"
}' "https://fcm.googleapis.com/fcm/send"