How can a web page determine whether it's running in 3D WebView or in a regular browser?

It may sometimes be useful for a web page to determine whether it's running in 3D WebView or in a regular browser app (for example, so it can show a different message when running in a webview vs Google Chrome). It's possible for a web page to determine this via JavaScript by checking for the existence of the window.vuplex object that 3D WebView injects after the page loads. A web page can include the following isRunningInWebView() JavaScript function to determine whether it's running in 3D WebView:

/** @returns Promise<bool> */
function isRunningInWebView() {

  if (window.vuplex) {
    return Promise.resolve(true);
  }
  if (!window._isRunningInWebViewResult) {
    window._isRunningInWebViewResult = new Promise(resolve => {
      const waitThenCheckForWebView = () => {
        // Wait a second to give 3D WebView time to inject the window.vuplex object.
        setTimeout(() => resolve(!!window.vuplex), 1000);
      };
      if (document.readyState !== 'loading') {
        waitThenCheckForWebView()
      } else {
        document.addEventListener('DOMContentLoaded', waitThenCheckForWebView);
      }
    });
  }
  return window._isRunningInWebViewResult;
}

And here's an example of using the isRunningInWebView() JavaScript function, which returns a Promise:

let inWebView = await isRunningInWebView();
console.log('Is running in a webview: ' + inWebView);