【问题标题】:Manifest: No add to homescreen清单:没有添加到主屏幕
【发布时间】:2019-05-16 02:41:14
【问题描述】:

我正在尝试在主屏幕上显示横幅,我安装了 service-worker 和 manifest,尝试完成 this 但它没有显示横幅。

这是我的代码:

index.php

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="manifest" crossorigin="use-credentials"  href="manifest.json">
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

</body>

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

</html>

manifest.json

{
    "short_name": "BetaPage",
    "name": "BetaPage",
    "theme_color": "#4A90E2",
    "background_color": "#F7F8F9",
    "display": "standalone",
    "icons": [
      {
        "src": "img/apple.png",
        "type": "image/png",
        "sizes": "48x48"
      },
      {
        "src": "img/grapes.png",
        "type": "image/png",
        "sizes": "96x96"
      },
      {
        "src": "img/lemon.png",
        "type": "image/png",
        "sizes": "144x144"
      },
      {
        "src": "img/orange.png",
        "type": "image/png",
        "sizes": "192x192"
      }
    ],
    "start_url": "index.php"
  }

service-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);
        })
      );
    });

但仍然没有显示横幅,我的清单上没有错误。

这是我的服务员

我该如何解决这个问题?我目前正在我的本地主机上执行此操作。

更新 好的,我设法使用本指南 https://codelabs.developers.google.com/codelabs/add-to-home-screen/#0

完成了这项工作

我现在的问题是 Firefox 中没有显示提示。 下面的图片都是firefox,一个工作的和我的本地主机。

工作样本

我的作品

如您所见,另一个有另一个图标,而我的工作没有,但横幅可以在 chrome 上运行

【问题讨论】:

    标签: javascript php manifest service-worker progressive-web-apps


    【解决方案1】:

    看看这个帖子:PWA Tips and Tricks

    【讨论】:

      【解决方案2】:

      将 lighthouse 插件安装到 Chrome 中并在您的页面上运行它并查看结果。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-13
        • 2021-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-05
        • 1970-01-01
        相关资源
        最近更新 更多