Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tracker_client",
"version": "0.2.0",
"version": "0.2.1",
"description": "a flexble client error and action track script",
"main": "src/index.js",
"directories": {
Expand Down
16 changes: 12 additions & 4 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ dispatcher.prototype = {
},
sendError: function(info) {
var endPoint = this.endPoint(this.config.token)
var xhr = getXHR(endPoint)
if (util.isString(info)) {
xhr.send(info)
if (!util.isString(info)) {
info = JSON.stringify(info)
}
if (navigator.sendBeacon) {
/*
* https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
* This method addresses the needs of analytics and diagnostics code that typically attempts to send data to a web server prior to the unloading of the document.
* user agents typically ignore asynchronous XMLHttpRequests made in an unload handler
*/
navigator.sendBeacon(endPoint, info);
}
else {
xhr.send(JSON.stringify(info))
var xhr = getXHR(endPoint)
xhr.send(info)
}
}
}
Expand Down