Skip to content

Commit e445f1b

Browse files
committed
Revert "use navigator.sendBeacon when available"
This reverts commit 48b8035. Fix #10
1 parent 8ad1c1d commit e445f1b

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

stackdriver-errors.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,16 @@
118118

119119
StackdriverErrorReporter.prototype.sendErrorPayload = function(payload, callback) {
120120
var url = baseAPIUrl + this.projectId + "/events:report?key=" + this.apiKey;
121-
var CONTENT_TYPE = 'application/json; charset=UTF-8';
122-
var payloadString = JSON.stringify(payload);
123-
var end = typeof callback === 'function' ? callback : function () {};
124-
125-
// Check if we can use sendBeacon
126-
if (typeof Blob !== 'undefined' && typeof navigator.sendBeacon === 'function') {
127-
// create blob to set content type to JSON - needed for correct HTTP header
128-
var blob = new Blob([payloadString], { type: CONTENT_TYPE });
129-
navigator.sendBeacon(url, blob);
130-
return end();
131-
}
132121

133122
var xhr = new XMLHttpRequest();
134123
xhr.open('POST', url, true);
135-
xhr.setRequestHeader('Content-Type', CONTENT_TYPE);
136-
xhr.onloadend = end;
137-
xhr.onerror = end;
138-
xhr.send(payloadString);
124+
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
125+
xhr.onloadend = function() {
126+
return typeof callback === 'function' && callback();
127+
};
128+
xhr.onerror = function(e) {
129+
return typeof callback === 'function' && callback(e);
130+
};
131+
xhr.send(JSON.stringify(payload));
139132
};
140133
})(this);

0 commit comments

Comments
 (0)