Javascript to check if PWA or Mobile Web

前端 未结 5 1812
野的像风
野的像风 2020-12-12 12:12

I was curious if anyone knew a javascript based method for detecting whether the web experience was being run as a PWA (progressive web app) or it was simply being run as a

5条回答
  •  情深已故
    2020-12-12 12:34

    Edit 11 Oct 2019: Added an extra switch to check if the app is launched via TWA - document.referrer.includes('android-app://')

    This works for all - TWA, Chrome & Safari:

    const isInStandaloneMode = () =>
          (window.matchMedia('(display-mode: standalone)').matches) || (window.navigator.standalone) || document.referrer.includes('android-app://');
    
     if (isInStandaloneMode()) {
        console.log("webapp is installed")
    }
    

提交回复
热议问题