From 81e1747469db83dd0832dae9199f0ee0583f6d73 Mon Sep 17 00:00:00 2001 From: Peter Dietrich Date: Tue, 12 Dec 2017 07:45:35 +0100 Subject: [PATCH 1/2] try/catch xhr.responseType to avoid exception The line can cause exceptions on Android 4.x in certain circumstances. Unfortunately, not reproducible but only visible when logging client errors in production, see https://github.com/socketio/engine.io-client/issues/589 --- lib/transports/polling-xhr.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/transports/polling-xhr.js b/lib/transports/polling-xhr.js index 297bac59e..a1c5a7b98 100755 --- a/lib/transports/polling-xhr.js +++ b/lib/transports/polling-xhr.js @@ -244,7 +244,10 @@ Request.prototype.create = function () { contentType = xhr.getResponseHeader('Content-Type'); } catch (e) {} if (contentType === 'application/octet-stream') { - xhr.responseType = 'arraybuffer'; + // next line can sometimes cause an exception in Android 4.x + try { + xhr.responseType = 'arraybuffer'; + } catch (e) {} } } if (4 !== xhr.readyState) return; From e47306004ced025409798e2e0a417349afa34aff Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 4 Jan 2018 12:49:11 +0100 Subject: [PATCH 2/2] merge both try catch --- lib/transports/polling-xhr.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/transports/polling-xhr.js b/lib/transports/polling-xhr.js index a1c5a7b98..6044266a9 100755 --- a/lib/transports/polling-xhr.js +++ b/lib/transports/polling-xhr.js @@ -239,16 +239,12 @@ Request.prototype.create = function () { } else { xhr.onreadystatechange = function () { if (xhr.readyState === 2) { - var contentType; try { - contentType = xhr.getResponseHeader('Content-Type'); - } catch (e) {} - if (contentType === 'application/octet-stream') { - // next line can sometimes cause an exception in Android 4.x - try { + var contentType = xhr.getResponseHeader('Content-Type'); + if (contentType === 'application/octet-stream') { xhr.responseType = 'arraybuffer'; - } catch (e) {} - } + } + } catch (e) {} } if (4 !== xhr.readyState) return; if (200 === xhr.status || 1223 === xhr.status) {