Open3

webviewかどうかをjavascriptで判定したい

tenryutenryu

window.print()で実装したボタンがwebviewでは表示されない。
どうにかしてwebviewで表示されていることを確認し、その場合は非表示にしたい

tenryutenryu

https://thewebdev.info/2022/05/21/how-to-detect-ipad-or-iphone-web-view-via-javascript/

const standalone = window.navigator.standalone;
const userAgent = window.navigator.userAgent.toLowerCase();
const safari = /safari/.test(userAgent);
const ios = /iphone|ipod|ipad/.test(userAgent);

if (ios) {
  if (!standalone && safari) {
    //browser
  } else if (standalone && !safari) {
    //standalone
  } else if (!standalone && !safari) {
    //uiwebview
  }
} else {
  //not iOS
}

試してみたが、Property 'standalone' does not exist on type 'Navigator'と表示されエラーになる