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











up vote
2
down vote

favorite












Trying to make an Progressive Web App, using ASP.NET Core 2.1, using Nuget: WebEssentials.AspNetCore.PWA.



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.



The error:




Site cannot be installed: the page has requested the banner prompt be
cancelled




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












share|improve this question




























    up vote
    2
    down vote

    favorite












    Trying to make an Progressive Web App, using ASP.NET Core 2.1, using Nuget: WebEssentials.AspNetCore.PWA.



    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.



    The error:




    Site cannot be installed: the page has requested the banner prompt be
    cancelled




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












    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Trying to make an Progressive Web App, using ASP.NET Core 2.1, using Nuget: WebEssentials.AspNetCore.PWA.



      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.



      The error:




      Site cannot be installed: the page has requested the banner prompt be
      cancelled




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












      share|improve this question















      Trying to make an Progressive Web App, using ASP.NET Core 2.1, using Nuget: WebEssentials.AspNetCore.PWA.



      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.



      The error:




      Site cannot be installed: the page has requested the banner prompt be
      cancelled




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








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





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






      javascript asp.net asp.net-core progressive-web-apps web-essentials






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 13:03









      qiAlex

      2,0201623




      2,0201623










      asked Nov 13 at 12:38









      Mojo

      715




      715
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          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>








          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281183%2fasp-net-core-2-1-pwa-banner-prompt-be-cancelled%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            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>








            share|improve this answer

























              up vote
              2
              down vote













              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>








              share|improve this answer























                up vote
                2
                down vote










                up vote
                2
                down vote









                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>








                share|improve this answer












                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>








                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>





                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>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 at 12:46









                Mojo

                715




                715






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281183%2fasp-net-core-2-1-pwa-banner-prompt-be-cancelled%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?