var initialized = false;
var options = {};

Pebble.addEventListener("ready", function() {
  console.log("ready called!");
  initialized = true;
});

Pebble.addEventListener("showConfiguration", function() {
  console.log("showing configuration");
  Pebble.openURL('http://assets.getpebble.com.s3-website-us-east-1.amazonaws.com/pebble-js/configurable.html?'+encodeURIComponent(JSON.stringify(options)));
});

Pebble.addEventListener("webviewclosed", function(e) {
  console.log("configuration closed");
  // webview closed
  if (e.response != "{}") {
    options = JSON.parse(decodeURIComponent(e.response));
    console.log("Options = " + JSON.stringify(options));
  } else {
    console.log("Cancelled");
  }
});

@@ -520,32 +520,149 @@
 sed%0A
-  if (e.response != %22%7B%7D%22
+%09//Using primitive JSON validity and non-empty check%0A%09if (e.response.charAt(0) == %22%7B%22 && e.response.slice(-1) == %22%7D%22 && e.response.length %3E 5
 ) %7B%0A

Improve robustness of cancellation detection.