From 1e4f72579dd22ce2a69c1b74fed13775124f6bbd Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 4 Mar 2015 15:26:33 -0700 Subject: [PATCH] Prevent crash on Safari < 8; code review --- platform/safari/vapi-background.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index a1d6c0d25..6b34892af 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -42,6 +42,29 @@ /******************************************************************************/ + if(navigator.userAgent.indexOf("Safari/6") === -1) { // If we're not on at least Safari 8 + var _open = XMLHttpRequest.prototype.open; + XMLHttpRequest.prototype.open = function(m, u) { + if(u.lastIndexOf("safari-extension:", 0) === 0) { + var i = u.length, seeDot = false; + while(i --) { + if(u[i] === ".") { + seeDot = true; + } + else if(u[i] === "/") { + break; + } + } + if(seeDot === false) { + throw 'InvalidAccessError'; // Avoid crash + return; + } + } + _open.apply(this, arguments); + }; + } + /******************************************************************************/ + vAPI.app.restart = function() {}; /******************************************************************************/