Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect in JavaScript if a page was loaded in a Chrome webview?

I'm writing a packaged app for Chrome that has a webview tag where I load my website.

Is it possible for the website JavaScript code to detect that it was loaded in a webview? The navigator.userAgent property has no clues.

like image 495
Mark Vayngrib Avatar asked Oct 21 '22 07:10

Mark Vayngrib


1 Answers

Other approaches in addition to the one mentioned by Jivings:

  • Load a slightly different URL in the webview, e.g., http://example.com?in_webview=1, and reflect that in the JavaScript served by the site.
  • Same idea but use a #fragment. I don't know for sure whether a #fragment will work correctly, but it if does, it's nice because the server won't get confused by a strange query param.
  • Using the embedder, insert a script into the webview's DOM that does something different.
like image 153
sowbug Avatar answered Oct 24 '22 11:10

sowbug