我正在开发一个chrome应用程序,它基本上完成了,但是我正在添加代码到我的客户的网站上,让它确定该应用程序是否安装在chrome上。
为此,我需要检查文件"manifest.json“是否可供应用程序使用,以确定其是否已安装。
我正在使用下面的代码,这是我从这里发布的另一个问题中获得的代码:
function detectChromeExtension(extensionId, accesibleResource, callback){
if (typeof(chrome) !== 'undefined'){
var xmlHttp = new XMLHttpRequest(),
testUrl = 'chrome-extension://' +extensionId +'/' +accesibleResource;
xmlHttp.open('HEAD', testUrl, true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.timeout = 1000;
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && typeof(callback) == 'function') {
if (xmlHttp.status == 200) {
callback.call(this, true);
} else {
callback.call(this, false);
}
}
}
xmlHttp.ontimeout = function() {
if (typeof(callback) == 'function')
callback.call(this, false);
}
xmlHttp.send();
} else {
if (typeof(callback) == 'function')
callback.call(this, false);
}
};
detectChromeExtension('gcjbmhbihobfgpjmfbooldocijijdpig', 'manifest.json', myCallbackFunction);
function myCallbackFunction(extensionExists) {
if (extensionExists){
console.log('Extension present');
} else {
console.log('Extension not present');
}
}通过检查chrome控制台,我得到了以下输出:
拒绝chrome-extension://gcjbmhbihobfgpjmfbooldocijijdpig/manifest.json.的负载资源必须在web_accessible_resources清单键中列出,才能由扩展外部的页面加载。
因此,为了解决这个问题,我尝试将"web_accessible_resources":" manifest.json“添加到我的manifest.json中,但它告诉我这一行不符合语法。
下面是完整的manifest.json:
{
"name": "Watch TBR",
"version": "1.0",
"manifest_version": 2,
"default_locale": "en",
"description": "Easy access to WatchTBR.com",
"icons": { "128": "icon_128.png", "16": "icon_16.png" },
"app": {
"urls": [
"http://www.watchtbr.com/"
],
"launch": {
"web_url": "http://www.watchtbr.com/"
}
},
"web_accessible_resources": ["manifest.json"],
"permissions":["http://www.watchtbr.com"]
}这方面的任何帮助都是非常感谢的。
发布于 2013-04-16 02:05:23
与扩展不同的是,网站无法访问打包应用的资源。如果你同时拥有网站和应用程序,你可以使用Chrome WebStore的inline installation功能,测试应用程序是否安装了chrome.app.isInstalled。
目前,isInstalled方法仅限于托管应用程序,但this bug跟踪打包应用程序的支持。
如果您不拥有该应用程序,或者只想共享指向该应用程序(如果已安装)或商店条目(如果未安装)的链接,您可以在https://code.google.com/p/chromium/issues/detail?id=161054上启动并追踪该功能请求
https://stackoverflow.com/questions/16010100
复制相似问题