Index: remoting/webapp/remoting.js |
diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js |
index e7836c85b7ccaee6ec1fd411231e9c04da3d94a7..a51407e951ac8343a950141aaa1def9188e089da 100644 |
--- a/remoting/webapp/remoting.js |
+++ b/remoting/webapp/remoting.js |
@@ -127,9 +127,13 @@ remoting.logExtensionInfoAsync_ = function() { |
xhr.onload = function(e) { |
var manifest = |
/** @type {{name: string, version: string, default_locale: string}} */ |
- JSON.parse(xhr.responseText); |
- var name = chrome.i18n.getMessage('PRODUCT_NAME'); |
- console.log(name + ' version: ' + manifest.version); |
+ jsonParseSafe(xhr.responseText); |
+ if (manifest) { |
+ var name = chrome.i18n.getMessage('PRODUCT_NAME'); |
+ console.log(name + ' version: ' + manifest.version); |
+ } else { |
+ console.error('Failed to get product version. Corrupt manifest?'); |
+ } |
} |
xhr.send(null); |
}; |
@@ -276,3 +280,15 @@ function getUrlParameters_() { |
} |
return result; |
} |
+ |
+/** |
+ * @param {string} jsonString A JSON-encoded string. |
+ * @return {*} The decoded object, or undefined if the string cannot be parsed. |
+ */ |
+function jsonParseSafe(jsonString) { |
+ try { |
+ return JSON.parse(jsonString); |
+ } catch (err) { |
+ return undefined; |
+ } |
+} |