I am working on project which will run as Chrome App & regular site.
How can I test/check in my JS if I am in an Chrome App? (i.e. some functionality will only work under chrome)
Just FYI, here is my Chrome App manifest, please note I am running this in the developer mode (directly from the source, not packaged yet)
{
"manifest_version": 2,
"name": "Example KIOSK APP",
"version": "1.1",
"icons": {
"16": "images/icon-16.png",
"48": "images/icon-48.png",
"128": "images/icon-128.png"
},
"app": {
"background": {
"scripts": ["background.js"],
"persistent": true
}
},
"kiosk_enabled": true,
"offline_enabled": true,
"permissions": [
"system.display",
"power",
"webview",
"fileSystem",
"alwaysOnTopWindows",
"system.storage",
"<all_urls>"
]
}
Any suggestions much appreciated.
Turns out the question meant to distinguish between identical code running in a webpage and inside a (regular) Chrome App window.
It is enough to test for Chrome App APIs that are never exposed to regular pages. An example of that would be to test for app.runtime
:
if (window.chrome && chrome.app && chrome.app.runtime) {
// Running inside a Chrome App context
} else {
// Either not Chrome, or not as an app window
}