WPA添加到主屏幕仅适用于localhost

时间:2017-09-07 13:52:50

标签: javascript android service-worker progressive-web-apps manifest.json

我想"添加到主页按钮"在我的网站上。 它在localhost上运行良好 only

在部署版本上: - 闪屏不起作用 - 独立显示无法正常工作

我的manifest.json:

{
  "name": "my name",
  "short_name": "my name",
  "icons": [{
    "src": "images/web_app_icon/48.png",
    "type": "image/png",
    "sizes": "48x48"
  },
  {
    "src": "images/web_app_icon/72.png",
    "type": "image/png",
    "sizes": "72x72"
  },
  {
    "src": "images/web_app_icon/96.png",
    "type": "image/png",
    "sizes": "96x96"
  },
  {
    "src": "images/web_app_icon/144.png",
    "type": "image/png",
    "sizes": "144x144"
  },
  {
    "src": "images/web_app_icon/168.png",
    "type": "image/png",
    "sizes": "168x168"
  },
  {
    "src": "images/web_app_icon/192.png",
    "type": "image/png",
    "sizes": "192x192"
  },
  {
    "src": "images/web_app_icon/512.png",
    "type": "image/png",
    "sizes": "512x512"
  }],
  "start_url": "/wta/",
  "display": "standalone",
  "background_color": "#ffffff",
  "theme_color": "#1e88e5",
  "orientation": "any"
}

/js/addtohome.js:

if ('serviceWorker' in navigator) {
    console.log("Will the service worker register?");
    navigator.serviceWorker.register(baseContextPath+'service-worker.js')
      .then(function(reg){
        console.log("Yes, it did.");
      }).catch(function(err) {
        console.log("No it didn't. This happened: ", err)
      });
  }

服务worker.js:

self.addEventListener('install', function(event) {
    console.log("installed");
});

self.addEventListener('activate', function(event) {
      // Perform some task
    console.log("activated");
    });

self.addEventListener('fetch', function(event) {
    console.log("fetched");
      event.respondWith(
        fetch(event.request).catch(function() {
          return caches.match(event.request);
        })
      );
    });

似乎eveythings在chrome dev工具中运行良好。 为什么它只适用于localhost?THX

0 个答案:

没有答案