Reputation: 994
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.
Upvotes: 5
Views: 2131
Reputation: 4672
Other approaches in addition to the one mentioned by Jivings:
Upvotes: 3
Reputation: 23260
When the webview has finished loading fire an event to the page inside:
webview.addEventListener("loadstop", function () {
contentWindow.postMessage('Hello from Chrome App!', targetOrigin)
});
Your content page can listen for this message using the regular postMessage API. If it receives a message you will know it is loaded in a webview.
Upvotes: 0