Google chrome 谷歌浏览器推送通知缓存

Google chrome 谷歌浏览器推送通知缓存,google-chrome,push-notification,push,Google Chrome,Push Notification,Push,我正在使用google chrome推送通知向我的用户发送推送通知。 我制作了如下教程: 它正在工作,但当我更改“sw.js”文件上的“message”时出现问题。它不会立即改变,当我发送推送消息时,用户会收到上一条消息 请帮帮我 sw.js: /* * * Push Notifications codelab * Copyright 2015 Google Inc. All rights reserved. * * Licensed under the Apache License,

我正在使用google chrome推送通知向我的用户发送推送通知。 我制作了如下教程:

它正在工作,但当我更改“sw.js”文件上的“message”时出现问题。它不会立即改变,当我发送推送消息时,用户会收到上一条消息

请帮帮我

sw.js:

/*
*
*  Push Notifications codelab
*  Copyright 2015 Google Inc. All rights reserved.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      https://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License
*
*/

// Version 0.1

'use strict';



console.log('Started', self);



self.addEventListener('install', function(event) {
  self.skipWaiting();
  console.log('Installed', event);
});

self.addEventListener('activate', function(event) {
  console.log('Activated', event);
});

self.addEventListener('push', function(event) {
  console.log('Push ', event);



  var title = 'Head';

  event.waitUntil(
    self.registration.showNotification(title, {
      'body': 'Body!',
      'icon': 'push/images/hergunyeni-push.png'
    }));
});

self.addEventListener('notificationclick', function(event) {
  console.log('Notification click: tag', event.notification.tag);
  // Android doesn't close the notification when you click it
  // See http://crbug.com/463146
  event.notification.close();

  var url = 'https://www.hergunyeni.com/tum-urunler.html?sort=p.date_added&order=DESC&utm_source=Push&utm_medium=push&utm_campaign=Yeniler&utm_content=Yeniler';
  // Check if there's already a tab open with this URL.
  // If yes: focus on the tab.
  // If no: open a tab with the URL.
  event.waitUntil(
    clients.matchAll({
      type: 'window'
    })
    .then(function(windowClients) {
      console.log('WindowClients', windowClients);
      for (var i = 0; i < windowClients.length; i++) {
        var client = windowClients[i];
        console.log('WindowClient', client);
        if (client.url === url && 'focus' in client) {
          return client.focus();
        }
      }
      if (clients.openWindow) {
        return clients.openWindow(url);
      }
    })
  );
});

看起来您正在尝试发送数据,如下所示:

 $fields = array(
    'registration_ids' => $registrationIDs,
    'data' => array( "message" => $message ),
);
这是web推送的错误做法。数据属性特定于GCM,不受Chrome支持。要发送数据,您需要加密有效负载。也许可以看看:

其次,您需要在服务工作者中更改showNotification()代码以使用此数据。(尝试调用
console.log(event.data)

 $fields = array(
    'registration_ids' => $registrationIDs,
    'data' => array( "message" => $message ),
);