Google Chrome应用-检查应用还是常规网站 [英] Google Chrome App - check if app or regular site

查看:63
本文介绍了Google Chrome应用-检查应用还是常规网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究将作为Chrome应用&常规站点.

I am working on project which will run as Chrome App & regular site.

如果我在Chrome应用中,如何测试/签入JS? (即某些功能只能在Chrome上使用)

How can I test/check in my JS if I am in an Chrome App? (i.e. some functionality will only work under chrome)

仅供参考,这是我的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.

足以测试不会暴露在常规页面中的Chrome App API.一个例子是测试app.runtime:

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
}

这篇关于Google Chrome应用-检查应用还是常规网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆