简体   繁体   English

无法从 Web 浏览器安装 PWA

[英]Can't install PWA from web browser

I'm working on a React PWA and I've successfully installed it as an app in both iOS (using Safari) and android (using Chrome) but I am facing troubles installing it through a browser (Chrome) on my PC.我正在开发 React PWA 并且我已经在 iOS(使用 Safari)和 android(使用 Chrome)中成功地将它安装为应用程序,但是我在我的 PC 上通过浏览器(Chrome)安装它时遇到了麻烦。

As far as I know, there should be a install prompt on load or an add icon on the right in address bar which will allow the user to install the PWA in PC as an app, but there is no option displayed to install PWA when I open my React web app on browser.据我所知,加载时应该有安装提示或地址栏右侧的添加图标,这将允许用户将 PWA 作为应用程序安装在 PC 中,但是当我没有显示安装 PWA 的选项时在浏览器上打开我的 React Web 应用程序。

This is my manifest.JSON:这是我的 manifest.JSON:

{
  "short_name": "React App",
  "name": "Create React App Sample",
  "icons": [
    {
      "src": "icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "icon-512x512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ],
  "start_url": "/",
  "display": "standalone",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}

and this is my service-worker.JS:这是我的 service-worker.JS:

// Flag for enabling cache in production
var doCache = true;
var CACHE_NAME = "pwa-app-cache";
// Delete old caches
self.addEventListener("activate", event => {
  const currentCachelist = [CACHE_NAME];
  event.waitUntil(
    caches.keys().then(keyList =>
      Promise.all(
        keyList.map(key => {
          if (!currentCachelist.includes(key)) {
            return caches.delete(key);
          }
        })
      )
    )
  );
});
// This triggers when user starts the app
self.addEventListener("install", function(event) {
  if (doCache) {
    console.log("install");
    event.waitUntil(
      caches.open(CACHE_NAME).then(function(cache) {
        fetch("asset-manifest.json")
          .then(response => {
            console.log(response.json());
            response.json();
          })
          .then(assets => {
            console.log("installs");
            // We will cache initial page and the main.js
            // We could also cache assets like CSS and images
            const urlsToCache = ["/", assets["main.js"]];
            cache.addAll(urlsToCache);
          });
      })
    );
  }
});
// Here we intercept request and serve up the matching files
self.addEventListener("fetch", function(event) {
  if (doCache) {
    event.respondWith(
      caches.match(event.request).then(function(response) {
        return response || fetch(event.request);
      })
    );
  }
});

使用 PC,我相信您最接近的是“添加到主屏幕”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM