简体   繁体   English

如何获取“添加到主屏幕”标语以在我的PWA的移动浏览器中显示?

[英]How to get “add to homescreen” banner to display on mobile browsers for my PWA?

I have been trying to get a very basic PWA that plays with an api to work. 我一直在尝试获得一个非常基本的PWA,它可以使用api来工作。

While the PWA works as expected on my laptop ( including working offline when added to homescreen), no install/add to homescreen prompts/banners are seen on mobile . 虽然PWA 在笔记本电脑上可以正常工作(包括添加到主屏幕后可以脱机工作), 但在移动设备上看不到安装/添加到主屏幕的提示/横幅

The app does not work offline either,on mobile 该应用程序也无法在移动设备上离线运行

This is the service worker code : 这是服务人员代码:

 const cacheName = 'news'; const staticAssets = [ './', './app.js', './styles.css', './fallback.json', ]; self.addEventListener('install', async function () { const cache = await caches.open(cacheName); cache.addAll(staticAssets); }); self.addEventListener('activate', event => { event.waitUntil(self.clients.claim()); }); self.addEventListener('fetch', event => { const request = event.request; const url = new URL(request.url); if (url.origin === location.origin) { event.respondWith(cacheFirst(request)); } else { event.respondWith(networkFirst(request)); } }); async function cacheFirst(request) { const cachedResponse = await caches.match(request); return cachedResponse || fetch(request); } async function networkFirst(request) { const dynamicCache = await caches.open('news-dynamic'); try { const networkResponse = await fetch(request); dynamicCache.put(request, networkResponse.clone()); return networkResponse; } catch (err) { const cachedResponse = await dynamicCache.match(request); return cachedResponse || await caches.match('./fallback.json'); } } 

This is the manifest.json file : 这是manifest.json文件:

 { "name": "News", "short_name": "News", "theme_color": "#2196f3", "background_color": "#2196f3", "display": "standalone", "Scope": "/", "start_url": ".", "icons": [ { "src": "images/icons/icon-72x72.png", "sizes": "72x72", "type": "image/png" }, { "src": "images/icons/icon-96x96.png", "sizes": "96x96", "type": "image/png" }, { "src": "images/icons/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, { "src": "images/icons/icon-144x144.png", "sizes": "144x144", "type": "image/png" }, { "src": "images/icons/icon-152x152.png", "sizes": "152x152", "type": "image/png" }, { "src": "images/icons/icon-192x192.png", "sizes": "192x192", "type": "image/png" }, { "src": "images/icons/icon-384x384.png", "sizes": "384x384", "type": "image/png" }, { "src": "images/icons/icon-512x512.png", "sizes": "512x512", "type": "image/png" } ], "splash_pages": null } 

Any idea on how to get it to work as expected on mobile? 关于如何使其在移动设备上按预期工作的任何想法?

You can follow this issue on this github forum . 您可以在此github论坛上关注此问题。 One of the suggested solution was to disable Adblock. 建议的解决方案之一是禁用Adblock。

Confirmed, it works if I tell Adblock not to run on the page. 确认,如果我告诉Adblock不要在页面上运行,它可以工作。

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

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