简体   繁体   中英

Chrome Manifest.json syntax error

I am working on a chrome app and its basically done, however I am adding code to my customer's website to have it determine if the app is installed on chrome or not.

In order to do this I need to check for a file "manifest.json" is available for the app to determine if its installed or not.

I am using the below code that I got from another posted question on here:

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');
            }
        }

By checking the chrome console I am getting the following output:

Denying load of chrome-extension://gcjbmhbihobfgpjmfbooldocijijdpig/manifest.json. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

so to fix this I am trying to add "web_accessible_resources": ["manifest.json"] into my manifest.json but it tells me that this line doesn't follow syntax.

Here is the full 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"]
}

Any help on this is greatly appreciated.

Unlike extensions, there is no way for a website to access packaged app's resources. If you own both the site and the app, you can use the inline installation feature of Chrome WebStore and test if the app is installed with chrome.app.isInstalled .

At the moment, the isInstalled method is limited to hosted apps, but this bug tracks the packaged apps support.

If you don't own the app or just want to share a link to the app (if installed) or to the store entry (if not installed), there is a feature request you can star and track progress at https://code.google.com/p/chromium/issues/detail?id=161054

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM