简体   繁体   English

ASP.NET Core 2.1 - PWA(取消横幅提示)

[英]ASP.NET Core 2.1 - PWA (Banner prompt be cancelled)

Trying to make an Progressive Web App, using ASP.NET Core 2.1, using Nuget: WebEssentials.AspNetCore.PWA .尝试使用 ASP.NET Core 2.1,使用 Nuget: WebEssentials.AspNetCore.PWA制作渐进式 Web 应用程序。

My serviceworker and manifest gets displayed in the Chrome Dev Tools, but when I hit the "Add to homescreen" nothing happens except displayed error on computer, and on phone the load banner on top is stuck loading.我的 serviceworker 和清单显示在 Chrome 开发工具中,但是当我点击“添加到主屏幕”时,除了计算机上显示的错误外,没有任何反应,并且在手机上,顶部的加载横幅卡在加载中。

The error:错误:

Site cannot be installed: the page has requested the banner prompt be cancelled站点无法安装:页面已请求取消banner提示

I couldn't seem to find anything on this error, so hope you guys can help me out.我似乎无法找到有关此错误的任何信息,所以希望你们能帮助我。 Thanks in advance.提前致谢。

ServiceWorker:服务工作者:

 self.addEventListener('install', async event => { const cache = await caches.open(CACHE_NAME); cache.addAll(urlsToCache).catch(err => console.log('An error occured: ', err)); }); self.addEventListener('fetch', event => { const request = event.request; const url = new URL(request.URL); if (url.orgin === location.orgin) { event.respondWith(cacheFirst(request)); } else { event.responseWith(networkFirst(request)); } }); async function cacheFirst(request) { const cachedResponse = await caches.match(request); return cachedResponse || fetch(request); } async function networkFirst(request) { const cache = await caches.open('wportal-dynamic-v1'); try { const res = await fetch(request); cache.put(request, res.clone()); return res; } catch (exception) { console.log('An error occured in networkFirst: ', exception); return await cache.match(request); } }

Found the solution..找到解决办法了。。

 var deferredPrompt = null; window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); // Prevent Chrome 67 and earlier from automatically showing the prompt deferredPrompt = e; });
 <button onclick="deferredPrompt.prompt();">Click me to install pwa</button>

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

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