Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mouselog

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mouselog - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

0

.eslintrc.js

@@ -0,0 +0,0 @@ module.exports = {

239

build/mouselog.js

@@ -1,2 +0,2 @@

/*! Mouselog Agent - v0.1.7 | 2020-3-21 | MIT */
/*! Mouselog Agent - v0.1.8 | 2020-3-21 | MIT */
(function webpackUniversalModuleDefinition(root, factory) {

@@ -95,3 +95,3 @@ if(typeof exports === 'object' && typeof module === 'object')

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 6);
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ })

@@ -225,4 +225,4 @@ /************************************************************************/

var rng = __webpack_require__(9);
var bytesToUuid = __webpack_require__(10);
var rng = __webpack_require__(13);
var bytesToUuid = __webpack_require__(14);

@@ -434,3 +434,19 @@ function v4(options, buf, offset) {

var arrayWithoutHoles = __webpack_require__(10);
var iterableToArray = __webpack_require__(11);
var nonIterableSpread = __webpack_require__(12);
function _toConsumableArray(arr) {
return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
}
module.exports = _toConsumableArray;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
;(function (name, root, factory) {

@@ -512,11 +528,11 @@ if (true) {

/***/ }),
/* 6 */
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(7);
module.exports = __webpack_require__(11);
__webpack_require__(8);
module.exports = __webpack_require__(15);
/***/ }),
/* 7 */
/* 8 */
/***/ (function(module, exports, __webpack_require__) {

@@ -528,3 +544,3 @@

// Return that as the export for use in Webpack, Browserify etc.
__webpack_require__(8);
__webpack_require__(9);
module.exports = self.fetch.bind(self);

@@ -534,3 +550,3 @@

/***/ }),
/* 8 */
/* 9 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

@@ -1064,5 +1080,41 @@

/***/ }),
/* 9 */
/* 10 */
/***/ (function(module, exports) {
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
}
}
module.exports = _arrayWithoutHoles;
/***/ }),
/* 11 */
/***/ (function(module, exports) {
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
module.exports = _iterableToArray;
/***/ }),
/* 12 */
/***/ (function(module, exports) {
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
module.exports = _nonIterableSpread;
/***/ }),
/* 13 */
/***/ (function(module, exports) {
// Unique ID creation requires a high quality random # generator. In the

@@ -1105,3 +1157,3 @@ // browser this is a little complicated due to unknown quality of Math.random()

/***/ }),
/* 10 */
/* 14 */
/***/ (function(module, exports) {

@@ -1138,3 +1190,3 @@

/***/ }),
/* 11 */
/* 15 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

@@ -1145,2 +1197,6 @@

// EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/toConsumableArray.js
var toConsumableArray = __webpack_require__(5);
var toConsumableArray_default = /*#__PURE__*/__webpack_require__.n(toConsumableArray);
// EXTERNAL MODULE: ../node_modules/@babel/runtime/helpers/classCallCheck.js

@@ -1241,3 +1297,5 @@ var classCallCheck = __webpack_require__(0);

var uploader_Uploader = /*#__PURE__*/function () {
var uploader_Uploader =
/*#__PURE__*/
function () {
function Uploader(impId, sessId, config) {

@@ -1274,3 +1332,3 @@ classCallCheck_default()(this, Uploader);

return new Promise(function (resolve) {
write("Uploading Pkg ".concat(data.idx, ", window size: ").concat(data.width, "*").concat(data.height, ", events count: ").concat(data.events.length));
write("Uploading Pkg ".concat(data.packetId, ", window size: ").concat(data.width, "*").concat(data.height, ", events count: ").concat(data.events.length));

@@ -1288,3 +1346,3 @@ for (var i = 0; i < 3 && i < data.events.length; ++i) {

}).then(function (resObj) {
write("Pkg ".concat(data.idx, " response=").concat(JSON.stringify(resObj)));
write("Pkg ".concat(data.packetId, " response=").concat(JSON.stringify(resObj)));

@@ -1307,3 +1365,3 @@ if (resObj.status !== "ok") {

})["catch"](function (err) {
write("Pkg ".concat(data.idx, " failed, wait for resending. Error message: ").concat(err.message));
write("Pkg ".concat(data.packetId, " failed, wait for resending. Error message: ").concat(err.message));

@@ -1314,3 +1372,3 @@ _this2._appendFailedData(data, encodedData);

status: -1,
msg: "Fail to upload data bunch #".concat(data.idx, ", ").concat(err.message)
msg: "Fail to upload data bunch #".concat(data.packetId, ", ").concat(err.message)
});

@@ -1346,3 +1404,3 @@ });

i += 1;
write("Resending Pkg ".concat(obj.data.idx));
write("Resending Pkg ".concat(obj.data.packetId));

@@ -1410,3 +1468,5 @@ if (obj.status == StatusEnum.WAITING) {

var config_Config = /*#__PURE__*/function () {
var config_Config =
/*#__PURE__*/
function () {
// Set up a default config

@@ -1423,3 +1483,6 @@ function Config() {

this.endpointType = "absolute"; // Upload mode, "mixed", "periodic" or "event-triggered"
this.endpointType = "absolute"; // An array "mixed", "periodic", "event-triggered"
// Periodic mode: Upload data in every given period
// Event-triggered mode: Upload data when a given number of events are collected
// Mixed mode: a mix of periodic and event-triggered mode

@@ -1434,4 +1497,7 @@ this.uploadMode = "mixed"; // Type: number

this.frequency = 50; // Maximum size of a single package
this.frequency = 50; // Type: number | null
// Mouselog will stop uploading data after uploading `uploadTimes` batch data.
this.uploadTimes = null; // Maximum size of a single package
this.sizeLimit = 65535; // Type: bool

@@ -1446,4 +1512,10 @@ // Use GET method to upload data? (stringified data will be embedded in URI)

this.scope = window.document; // These parameters are required for runing a Mouselog agent
this.scope = window.document; // Content: "base64" or an empty string
// Use a encoder before uploading the data
this.encoder = ""; // Type: Boolean
// If `serverConfig`, Mouselog will fetch config from backend server during initialization
this.serverConfig = true; // These parameters are required for runing a Mouselog agent
this._requiredParams = ["uploadEndpoint"]; // These parameters will be ignored when updating config

@@ -1510,3 +1582,3 @@

// EXTERNAL MODULE: ../node_modules/deep-copy/index.js
var deep_copy = __webpack_require__(5);
var deep_copy = __webpack_require__(6);
var deep_copy_default = /*#__PURE__*/__webpack_require__.n(deep_copy);

@@ -1528,2 +1600,3 @@

var targetEvents = ["mousemove", "mousedown", "mouseup", "click", "dblclick", "contextmenu", "wheel", "touchstart", "touchmove", "touchend"];

@@ -1534,7 +1607,2 @@ var pageLoadTime = new Date();

function getRelativeTimestampInSeconds() {
var diff = new Date() - pageLoadTime;
return Math.floor(diff) / 1000;
}
function getButton(btn) {

@@ -1559,3 +1627,5 @@ if (btn === '2') {

var src_Mouselog = /*#__PURE__*/function () {
var src_Mouselog =
/*#__PURE__*/
function () {
function Mouselog() {

@@ -1570,2 +1640,4 @@ classCallCheck_default()(this, Mouselog);

this.uploader = new uploader();
this.batchCount = 0;
this.packetCount = 0;
this.eventsList = [];

@@ -1585,7 +1657,7 @@ this.lastEvent;

}, {
key: "_newTrace",
value: function _newTrace() {
key: "_newDataBatch",
value: function _newDataBatch() {
var trace = {
id: '0',
idx: 0,
batchId: this.batchCount,
packetId: 0,
url: window.location.hostname ? window.location.hostname : "localhost",

@@ -1600,2 +1672,3 @@ path: window.location.pathname,

};
this.batchCount += 1;
return trace;

@@ -1634,3 +1707,3 @@ }

id: this.eventsCount,
timestamp: getRelativeTimestampInSeconds(),
timestamp: Math.floor(evt.timeStamp) / 1000,
type: evt.type,

@@ -1649,4 +1722,10 @@ x: x,

if (this.lastEvent && this.lastEvent.timestamp == tmpEvt.timestamp && this.lastEvent.x == tmpEvt.x && this.lastEvent.y == tmpEvt.y && this.lastEvent.type == tmpEvt.type && this.lastEvent.button == tmpEvt.button) {
return;
if (this.lastEvent && this.lastEvent.x == tmpEvt.x && this.lastEvent.y == tmpEvt.y) {
if (this.lastEvent.type == "mousemove" && tmpEvt.type == "mousemove") {
return;
}
if (this.lastEvent.type == tmpEvt.type && this.lastEvent.button == tmpEvt.button && this.lastEvent.timestamp == tmpEvt.timestamp) {
return;
}
}

@@ -1669,7 +1748,19 @@

}, {
key: "_encodeData",
value: function _encodeData(data) {
var encodedData = JSON.stringify(data);
if (this.config.encoder.toLowerCase() == "base64") {
encodedData = btoa(encodedData);
}
return encodedData;
}
}, {
key: "_binarySplitBigDataBlock",
value: function _binarySplitBigDataBlock(dataBlock) {
var encodedData = JSON.stringify(dataBlock);
var res = [];
var encodedData = this._encodeData(dataBlock);
var rawAndEncodedDataArray = [];
if (byteLength(encodedData) >= this.config.sizeLimit) {

@@ -1680,14 +1771,14 @@ var newDataBlock = deep_copy_default()(dataBlock);

this._binarySplitBigDataBlock(dataBlock).forEach(function (block) {
res.push(block);
this._binarySplitBigDataBlock(dataBlock).forEach(function (rawAndEncodedData) {
rawAndEncodedDataArray.push(rawAndEncodedData);
});
this._binarySplitBigDataBlock(newDataBlock).forEach(function (block) {
res.push(block);
this._binarySplitBigDataBlock(newDataBlock).forEach(function (rawAndEncodedData) {
rawAndEncodedDataArray.push(rawAndEncodedData);
});
} else {
res.push(dataBlock);
rawAndEncodedDataArray.push([dataBlock, encodedData]);
}
return res;
return rawAndEncodedDataArray;
}

@@ -1698,7 +1789,7 @@ }, {

// Upload an empty trace to fetch config from server
var trace = this._newTrace();
var trace = this._newDataBatch();
trace.idx = this.uploadIdx;
this.uploadIdx += 1;
return this.uploader.upload(trace, JSON.stringify(trace)); // This is a promise
trace.packetId = this.packetCount;
this.packetCount += 1;
return this.uploader.upload(trace, this._encodeData(trace)); // This is a promise
}

@@ -1710,17 +1801,22 @@ }, {

var trace = this._newTrace();
if (this.config.uploadTimes && this.batchCount >= this.config.uploadTimes + this.config.serverConfig) {
return; // TODO: This is only a stopgap method, a better method is to stop mouselog entirely.
}
var trace = this._newDataBatch();
trace.events = this.eventsList;
this.eventsList = [];
var dataBlocks = this._binarySplitBigDataBlock(trace); // An array of data blocks
var dataList = this._binarySplitBigDataBlock(trace); // An array of data blocks
dataBlocks.forEach(function (dataBlock) {
dataBlock.idx = _this.uploadIdx;
_this.uploadIdx += 1;
var encodedData = JSON.stringify(dataBlock);
dataList.forEach(function (rawAndEncodedData) {
var _this$uploader;
_this.uploader.upload(dataBlock, encodedData); // This is a promise
rawAndEncodedData[0].packetId = _this.packetCount;
_this.packetCount += 1;
(_this$uploader = _this.uploader).upload.apply(_this$uploader, toConsumableArray_default()(rawAndEncodedData)); // This is a promise
});

@@ -1798,24 +1894,25 @@ }

this.uploadIdx = 0;
this.uploader = new uploader(this.impressionId, this.sessionId, this.config);
if (this.config.build(config)) {
// Async: Upload an empty data to fetch config from server
this._fetchConfigFromServer().then(function (result) {
if (result.status == 1) {
if (_this6.config.update(result.config)) {
_this6._resetCollector();
if (this.config.serverConfig) {
// Async: Upload an empty data to fetch config from server
this._fetchConfigFromServer().then(function (result) {
if (result.status == 1) {
if (_this6.config.update(result.config)) {
_this6._resetCollector();
_this6.uploader.setConfig(_this6.config);
_this6.uploader.setConfig(_this6.config);
write("Successfully update config from backend.");
write("Successfully update config from backend.");
} else {
throw new Error("Unable to update config with server config.");
}
} else {
throw new Error("Unable to update config with server config.");
throw new Error("Fail to get config from server.");
}
} else {
throw new Error("Fail to get config from server.");
}
})["catch"](function (err) {
write(err);
});
})["catch"](function (err) {
write(err);
});
}

@@ -1822,0 +1919,0 @@ window.onunload = function () {

@@ -1,3 +0,3 @@

/*! Mouselog Agent - v0.1.7 | 2020-3-21 | MIT */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mouselog=e():t.mouselog=e()}(window,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=6)}([function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function n(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}t.exports=function(t,e,o){return e&&n(t.prototype,e),o&&n(t,o),t}},function(t,e,n){var o,r,i;i=function(){function t(t){var e=[];if(0===t.length)return"";if("string"!=typeof t[0])throw new TypeError("Url must be a string. Received "+t[0]);if(t[0].match(/^[^/:]+:\/*$/)&&t.length>1){var n=t.shift();t[0]=n+t[0]}t[0].match(/^file:\/\/\//)?t[0]=t[0].replace(/^([^/:]+):\/*/,"$1:///"):t[0]=t[0].replace(/^([^/:]+):\/*/,"$1://");for(var o=0;o<t.length;o++){var r=t[o];if("string"!=typeof r)throw new TypeError("Url must be a string. Received "+r);""!==r&&(o>0&&(r=r.replace(/^[\/]+/,"")),r=o<t.length-1?r.replace(/[\/]+$/,""):r.replace(/[\/]+$/,"/"),e.push(r))}var i=e.join("/"),s=(i=i.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i=s.shift()+(s.length>0?"?":"")+s.join("&")}return function(){return t("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},t.exports?t.exports=i():void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r)},function(t,e,n){var o=n(9),r=n(10);t.exports=function(t,e,n){var i=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var s=(t=t||{}).random||(t.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e)for(var a=0;a<16;++a)e[i+a]=s[a];return e||r(s)}},function(t,e,n){var o,r;
/*! Mouselog Agent - v0.1.8 | 2020-3-21 | MIT */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.mouselog=e():t.mouselog=e()}(window,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=7)}([function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function n(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}t.exports=function(t,e,o){return e&&n(t.prototype,e),o&&n(t,o),t}},function(t,e,n){var o,r,i;i=function(){function t(t){var e=[];if(0===t.length)return"";if("string"!=typeof t[0])throw new TypeError("Url must be a string. Received "+t[0]);if(t[0].match(/^[^/:]+:\/*$/)&&t.length>1){var n=t.shift();t[0]=n+t[0]}t[0].match(/^file:\/\/\//)?t[0]=t[0].replace(/^([^/:]+):\/*/,"$1:///"):t[0]=t[0].replace(/^([^/:]+):\/*/,"$1://");for(var o=0;o<t.length;o++){var r=t[o];if("string"!=typeof r)throw new TypeError("Url must be a string. Received "+r);""!==r&&(o>0&&(r=r.replace(/^[\/]+/,"")),r=o<t.length-1?r.replace(/[\/]+$/,""):r.replace(/[\/]+$/,"/"),e.push(r))}var i=e.join("/"),s=(i=i.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i=s.shift()+(s.length>0?"?":"")+s.join("&")}return function(){return t("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},t.exports?t.exports=i():void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r)},function(t,e,n){var o=n(13),r=n(14);t.exports=function(t,e,n){var i=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var s=(t=t||{}).random||(t.rng||o)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e)for(var a=0;a<16;++a)e[i+a]=s[a];return e||r(s)}},function(t,e,n){var o,r;
/*!

@@ -9,2 +9,2 @@ * JavaScript Cookie v2.2.1

* Released under the MIT license
*/!function(i){if(void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r),!0,t.exports=i(),!!0){var s=window.Cookies,a=window.Cookies=i();a.noConflict=function(){return window.Cookies=s,a}}}((function(){function t(){for(var t=0,e={};t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(o){function r(){}function i(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=t({path:"/"},r.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var s=JSON.stringify(n);/^[\{\[]/.test(s)&&(n=s)}catch(t){}n=o.write?o.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in i)i[u]&&(a+="; "+u,!0!==i[u]&&(a+="="+i[u].split(";")[0]));return document.cookie=e+"="+n+a}}function s(t,n){if("undefined"!=typeof document){for(var r={},i=document.cookie?document.cookie.split("; "):[],s=0;s<i.length;s++){var a=i[s].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=e(a[0]);if(u=(o.read||o)(u,c)||e(u),n)try{u=JSON.parse(u)}catch(t){}if(r[c]=u,t===c)break}catch(t){}}return t?r[t]:r}}return r.set=i,r.get=function(t){return s(t,!1)},r.getJSON=function(t){return s(t,!0)},r.remove=function(e,n){i(e,"",t(n,{expires:-1}))},r.defaults={},r.withConverter=n,r}((function(){}))}))},function(t,e,n){t.exports=function(){return function(e){if(/number|string|boolean/.test(typeof e))return e;if(e instanceof Date)return new Date(e.getTime());var n=e instanceof Array?[]:{};return function e(n,o){for(var r in n){var i=n[r];if(i instanceof Date){var s=new Date(i.getTime());t(o,r,s)}else if(i instanceof Function)t(o,r,s=i);else if(i instanceof Array){var a=t(o,r,s=[]);e(i,a)}else i instanceof Object?(a=t(o,r,s={}),e(i,a)):t(o,r,s=i)}}(e,n),n};function t(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}}()},function(t,e,n){n(7),t.exports=n(11)},function(t,e,n){n(8),t.exports=self.fetch.bind(self)},function(t,e,n){"use strict";n.r(e),n.d(e,"Headers",(function(){return h})),n.d(e,"Request",(function(){return w})),n.d(e,"Response",(function(){return x})),n.d(e,"DOMException",(function(){return I})),n.d(e,"fetch",(function(){return T}));var o="URLSearchParams"in self,r="Symbol"in self&&"iterator"in Symbol,i="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in self,a="ArrayBuffer"in self;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function l(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function d(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function y(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function v(t){var e=new FileReader,n=y(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:o&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=m(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=p(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,n,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=y(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),o=0;o<e.length;o++)n[o]=String.fromCharCode(e[o]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=l(t),e=d(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},h.prototype.delete=function(t){delete this.map[l(t)]},h.prototype.get=function(t){return t=l(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(l(t))},h.prototype.set=function(t,e){this.map[l(t)]=d(e)},h.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),f(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),f(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),f(t)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,o,r=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(n=e.method||this.method||"GET",o=n.toUpperCase(),b.indexOf(o)>-1?o:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),o=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(r))}})),e}function x(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},g.call(w.prototype),g.call(x.prototype),x.prototype.clone=function(){return new x(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},x.error=function(){var t=new x(null,{status:0,statusText:""});return t.type="error",t};var E=[301,302,303,307,308];x.redirect=function(t,e){if(-1===E.indexOf(e))throw new RangeError("Invalid status code");return new x(null,{status:e,headers:{location:t}})};var I=self.DOMException;try{new I}catch(t){(I=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),I.prototype.constructor=I}function T(t,e){return new Promise((function(n,o){var r=new w(t,e);if(r.signal&&r.signal.aborted)return o(new I("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var t,e,o={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),o=n.shift().trim();if(o){var r=n.join(":").trim();e.append(o,r)}})),e)};o.url="responseURL"in s?s.responseURL:o.headers.get("X-Request-URL");var r="response"in s?s.response:s.responseText;n(new x(r,o))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new I("Aborted","AbortError"))},s.open(r.method,r.url,!0),"include"===r.credentials?s.withCredentials=!0:"omit"===r.credentials&&(s.withCredentials=!1),"responseType"in s&&i&&(s.responseType="blob"),r.headers.forEach((function(t,e){s.setRequestHeader(e,t)})),r.signal&&(r.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&r.signal.removeEventListener("abort",a)}),s.send(void 0===r._bodyInit?null:r._bodyInit)}))}T.polyfill=!0,self.fetch||(self.fetch=T,self.Headers=h,self.Request=w,self.Response=x)},function(t,e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);t.exports=function(){return n(o),o}}else{var r=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),r[e]=t>>>((3&e)<<3)&255;return r}}},function(t,e){for(var n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);t.exports=function(t,e){var o=e||0,r=n;return[r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]]].join("")}},function(t,e,n){"use strict";n.r(e);var o,r=n(0),i=n.n(r),s=n(1),a=n.n(s),u=n(3),c=n.n(u),l=n(2),d=n.n(l),f=!1;function h(t){if(f){if(o){var e=document.createElement("p");e.style.display="block",e.style.fontSize="10px",e.style.margin="2px";var n=document.createTextNode(t);e.appendChild(n),o.appendChild(e)}console.log(t)}}function p(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var o=e[0],r=1;r<e.length;++r)o=o>e[r]?o:e[r];return o}function y(t){var e="number"==typeof t?t:Number(t);return Math.round(e)}function v(){return window.mouselogUserId?window.mouselogUserId:""}var m=0,g=1,b=2,w=function(){function t(e,n,o){i()(this,t),this.impressionId=e,this.sessionId=n,this.config=o,this.resendQueue=[]}return a()(t,[{key:"start",value:function(){var t=this;this.resendInterval=setInterval((function(){t._resendFailedData.call(t)}),this.config.resendInterval)}},{key:"stop",value:function(){clearInterval(this.resendInterval)}},{key:"upload",value:function(t,e){var n=this;return new Promise((function(o){h("Uploading Pkg ".concat(t.idx,", window size: ").concat(t.width,"*").concat(t.height,", events count: ").concat(t.events.length));for(var r=0;r<3&&r<t.events.length;++r)h(" ".concat(JSON.stringify(t.events[r])));n._upload(e).then((function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")})).then((function(e){if(h("Pkg ".concat(t.idx," response=").concat(JSON.stringify(e))),"ok"!==e.status)throw new Error("Response object status is not ok.");"config"==e.msg&&o({status:1,msg:"Get config from server",config:e.data}),o({status:0})})).catch((function(r){h("Pkg ".concat(t.idx," failed, wait for resending. Error message: ").concat(r.message)),n._appendFailedData(t,e),o({status:-1,msg:"Fail to upload data bunch #".concat(t.idx,", ").concat(r.message)})}))}))}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,e=0;this.resendQueue.length>0&&h("Resending data...");for(var n=function(){var n=t.resendQueue[e];n.status==b?t.resendQueue.splice(e,1):(e+=1,h("Resending Pkg ".concat(n.data.idx)),n.status==m&&(n.status=g,t.upload(n.data,n.encodedData).then((function(t){n.status=t?b:m}))))};e<this.resendQueue.length;)n()}},{key:"_upload",value:function(t){var e=d()(this.config.absoluteUrl,"?websiteId=".concat(this.config.websiteId,"&sessionId=").concat(this.sessionId,"&impressionId=").concat(this.impressionId,"&userId=").concat(v()));return this.config.enableGet?fetch("".concat(e,"&data=").concat(t),{method:"GET",credentials:"include",keepalive:!0}):fetch(e,{method:"POST",credentials:"include",body:t,keepalive:!0})}},{key:"_appendFailedData",value:function(t,e){this.resendQueue.push({status:m,data:t,encodedData:e})}}]),t}(),_=function(){function t(){i()(this,t),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{this._requiredParams.forEach((function(e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error("Param ".concat(e," is required but not declared."))})),Object.keys(t).forEach((function(o){void 0!==e[o]&&0!==o.indexOf("_")&&"function"!=typeof e[o]&&(n&&o in e._ignoredParams||(e[o]=t[o]))})),this._formatUrl()}catch(t){return h(t),!1}return!0}},{key:"update",value:function(t){return this.build(t,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=d()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=d()(this.uploadEndpoint,"/api/upload-trace")}}}]),t}(),x=n(5),E=n.n(x),I=n(4),T=n.n(I),k=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend"],A=new Date,C="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,U=C?C.replace(/hidden/i,"visibilitychange"):null;var B=function(){function t(){var e;i()(this,t),this.impressionId=c()(),this.sessionId=((e=T.a.get("mouselogSessionId"))||(e=c()(),T.a.set("mouselogSessionId",e)),e),this.config=new _,this.mouselogLoadTime=new Date,this.uploader=new w,this.eventsList=[],this.lastEvent,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newTrace",value:function(){return{id:"0",idx:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,sessionId:this.sessionId,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:A,referrer:document.referrer,events:[]}}},{key:"_onVisibilityChange",value:function(){window.document[C]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=y(t.pageX),n=y(t.pageY);NaN!=e&&null!=e||(e=y(t.changedTouches[0].pageX),n=y(t.changedTouches[0].pageY));var o,r,i={id:this.eventsCount,timestamp:(r=new Date-A,Math.floor(r)/1e3),type:t.type,x:e,y:n,button:(o=t.button,"2"===o?"Right":"")};"wheel"==t.type&&(i.deltaX=t.deltaX,i.deltaY=t.deltaY),this.lastEvent&&this.lastEvent.timestamp==i.timestamp&&this.lastEvent.x==i.x&&this.lastEvent.y==i.y&&this.lastEvent.type==i.type&&this.lastEvent.button==i.button||(this.eventsList.push(i),this.lastEvent=i,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadTrace(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadTrace()))}}},{key:"_binarySplitBigDataBlock",value:function(t){var e=JSON.stringify(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;n>=0;n--){var o=t.charCodeAt(n);o>127&&o<=2047?e++:o>2047&&o<=65535&&(e+=2),o>=56320&&o<=57343&&n--}return e}(e)>=this.config.sizeLimit){var o=E()(t);t.events.splice(t.events.length/2),o.events.splice(0,o.events.length/2),this._binarySplitBigDataBlock(t).forEach((function(t){n.push(t)})),this._binarySplitBigDataBlock(o).forEach((function(t){n.push(t)}))}else n.push(t);return n}},{key:"_fetchConfigFromServer",value:function(){var t=this._newTrace();return t.idx=this.uploadIdx,this.uploadIdx+=1,this.uploader.upload(t,JSON.stringify(t))}},{key:"_uploadTrace",value:function(){var t=this,e=this._newTrace();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){e.idx=t.uploadIdx,t.uploadIdx+=1;var n=JSON.stringify(e);t.uploader.upload(e,n)}))}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var t=this;k.forEach((function(e){t.config.scope.addEventListener(e,(function(e){return t._mouseHandler(e)}))})),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var t=this;k.forEach((function(e){t.config.scope.removeEventListener(e,(function(e){return t._mouseHandler(e)}))})),clearInterval(this.uploadInterval),clearTimeout(this.uploadTimeout)}},{key:"_resetCollector",value:function(){this._stopCollector(),this._runCollector()}},{key:"_init",value:function(t){var e=this;return this._clearBuffer(),this.uploadIdx=0,this.uploader=new w(this.impressionId,this.sessionId,this.config),this.config.build(t)?(this._fetchConfigFromServer().then((function(t){if(1!=t.status)throw new Error("Fail to get config from server.");if(!e.config.update(t.config))throw new Error("Unable to update config with server config.");e._resetCollector(),e.uploader.setConfig(e.config),h("Successfully update config from backend.")})).catch((function(t){h(t)})),window.onunload=function(){0!=e.eventsList.length&&e._uploadTrace()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(t){var e=this,n=this._init(t);0==n.status?(U&&document.addEventListener(U,(function(t){return e._onVisibilityChange(t)})),this._runCollector(),this.uploader.start(this.impressionId),h("Mouselog agent is activated!"),h("Website ID: ".concat(this.config.websiteId)),h("Session ID: ".concat(this.sessionId)),h("Impression ID: ".concat(this.impressionId)),h("User-Agent: ".concat(navigator.userAgent)),h("User ID: ".concat(v())),h("Page load time: ".concat(A))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;f=!0,(n=e)&&((o=window.document.getElementById(n))||console.log("Fail to find the output element.")),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),h("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function S(){return new B}n.d(e,"init",(function(){return S}))}])}));
*/!function(i){if(void 0===(r="function"==typeof(o=i)?o.call(e,n,e,t):o)||(t.exports=r),!0,t.exports=i(),!!0){var s=window.Cookies,a=window.Cookies=i();a.noConflict=function(){return window.Cookies=s,a}}}((function(){function t(){for(var t=0,e={};t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(o){function r(){}function i(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=t({path:"/"},r.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var s=JSON.stringify(n);/^[\{\[]/.test(s)&&(n=s)}catch(t){}n=o.write?o.write(n,e):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var u in i)i[u]&&(a+="; "+u,!0!==i[u]&&(a+="="+i[u].split(";")[0]));return document.cookie=e+"="+n+a}}function s(t,n){if("undefined"!=typeof document){for(var r={},i=document.cookie?document.cookie.split("; "):[],s=0;s<i.length;s++){var a=i[s].split("="),u=a.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var c=e(a[0]);if(u=(o.read||o)(u,c)||e(u),n)try{u=JSON.parse(u)}catch(t){}if(r[c]=u,t===c)break}catch(t){}}return t?r[t]:r}}return r.set=i,r.get=function(t){return s(t,!1)},r.getJSON=function(t){return s(t,!0)},r.remove=function(e,n){i(e,"",t(n,{expires:-1}))},r.defaults={},r.withConverter=n,r}((function(){}))}))},function(t,e,n){var o=n(10),r=n(11),i=n(12);t.exports=function(t){return o(t)||r(t)||i()}},function(t,e,n){t.exports=function(){return function(e){if(/number|string|boolean/.test(typeof e))return e;if(e instanceof Date)return new Date(e.getTime());var n=e instanceof Array?[]:{};return function e(n,o){for(var r in n){var i=n[r];if(i instanceof Date){var s=new Date(i.getTime());t(o,r,s)}else if(i instanceof Function)t(o,r,s=i);else if(i instanceof Array){var a=t(o,r,s=[]);e(i,a)}else i instanceof Object?(a=t(o,r,s={}),e(i,a)):t(o,r,s=i)}}(e,n),n};function t(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}}()},function(t,e,n){n(8),t.exports=n(15)},function(t,e,n){n(9),t.exports=self.fetch.bind(self)},function(t,e,n){"use strict";n.r(e),n.d(e,"Headers",(function(){return h})),n.d(e,"Request",(function(){return w})),n.d(e,"Response",(function(){return I})),n.d(e,"DOMException",(function(){return k})),n.d(e,"fetch",(function(){return x}));var o="URLSearchParams"in self,r="Symbol"in self&&"iterator"in Symbol,i="FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),s="FormData"in self,a="ArrayBuffer"in self;if(a)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],c=ArrayBuffer.isView||function(t){return t&&u.indexOf(Object.prototype.toString.call(t))>-1};function l(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function f(t){return"string"!=typeof t&&(t=String(t)),t}function d(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function p(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function y(t){return new Promise((function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}}))}function v(t){var e=new FileReader,n=y(e);return e.readAsArrayBuffer(t),n}function m(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function g(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:o&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a&&i&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=m(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a&&(ArrayBuffer.prototype.isPrototypeOf(t)||c(t))?this._bodyArrayBuffer=m(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):o&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i&&(this.blob=function(){var t=p(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?p(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(v)}),this.text=function(){var t,e,n,o=p(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=y(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),o=0;o<e.length;o++)n[o]=String.fromCharCode(e[o]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s&&(this.formData=function(){return this.text().then(_)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=l(t),e=f(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},h.prototype.delete=function(t){delete this.map[l(t)]},h.prototype.get=function(t){return t=l(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(l(t))},h.prototype.set=function(t,e){this.map[l(t)]=f(e)},h.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,n){t.push(n)})),d(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),d(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,n){t.push([n,e])})),d(t)},r&&(h.prototype[Symbol.iterator]=h.prototype.entries);var b=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,e){var n,o,r=(e=e||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,r||null==t._bodyInit||(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(n=e.method||this.method||"GET",o=n.toUpperCase(),b.indexOf(o)>-1?o:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&r)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(r)}function _(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var n=t.split("="),o=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(r))}})),e}function I(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},g.call(w.prototype),g.call(I.prototype),I.prototype.clone=function(){return new I(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},I.error=function(){var t=new I(null,{status:0,statusText:""});return t.type="error",t};var E=[301,302,303,307,308];I.redirect=function(t,e){if(-1===E.indexOf(e))throw new RangeError("Invalid status code");return new I(null,{status:e,headers:{location:t}})};var k=self.DOMException;try{new k}catch(t){(k=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),k.prototype.constructor=k}function x(t,e){return new Promise((function(n,o){var r=new w(t,e);if(r.signal&&r.signal.aborted)return o(new k("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var t,e,o={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var n=t.split(":"),o=n.shift().trim();if(o){var r=n.join(":").trim();e.append(o,r)}})),e)};o.url="responseURL"in s?s.responseURL:o.headers.get("X-Request-URL");var r="response"in s?s.response:s.responseText;n(new I(r,o))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.onabort=function(){o(new k("Aborted","AbortError"))},s.open(r.method,r.url,!0),"include"===r.credentials?s.withCredentials=!0:"omit"===r.credentials&&(s.withCredentials=!1),"responseType"in s&&i&&(s.responseType="blob"),r.headers.forEach((function(t,e){s.setRequestHeader(e,t)})),r.signal&&(r.signal.addEventListener("abort",a),s.onreadystatechange=function(){4===s.readyState&&r.signal.removeEventListener("abort",a)}),s.send(void 0===r._bodyInit?null:r._bodyInit)}))}x.polyfill=!0,self.fetch||(self.fetch=x,self.Headers=h,self.Request=w,self.Response=I)},function(t,e){t.exports=function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}},function(t,e){t.exports=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(t,e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var o=new Uint8Array(16);t.exports=function(){return n(o),o}}else{var r=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),r[e]=t>>>((3&e)<<3)&255;return r}}},function(t,e){for(var n=[],o=0;o<256;++o)n[o]=(o+256).toString(16).substr(1);t.exports=function(t,e){var o=e||0,r=n;return[r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],"-",r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]],r[t[o++]]].join("")}},function(t,e,n){"use strict";n.r(e);var o,r=n(5),i=n.n(r),s=n(0),a=n.n(s),u=n(1),c=n.n(u),l=n(3),f=n.n(l),d=n(2),h=n.n(d),p=!1;function y(t){if(p){if(o){var e=document.createElement("p");e.style.display="block",e.style.fontSize="10px",e.style.margin="2px";var n=document.createTextNode(t);e.appendChild(n),o.appendChild(e)}console.log(t)}}function v(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var o=e[0],r=1;r<e.length;++r)o=o>e[r]?o:e[r];return o}function m(t){var e="number"==typeof t?t:Number(t);return Math.round(e)}function g(){return window.mouselogUserId?window.mouselogUserId:""}var b=0,w=1,_=2,I=function(){function t(e,n,o){a()(this,t),this.impressionId=e,this.sessionId=n,this.config=o,this.resendQueue=[]}return c()(t,[{key:"start",value:function(){var t=this;this.resendInterval=setInterval((function(){t._resendFailedData.call(t)}),this.config.resendInterval)}},{key:"stop",value:function(){clearInterval(this.resendInterval)}},{key:"upload",value:function(t,e){var n=this;return new Promise((function(o){y("Uploading Pkg ".concat(t.packetId,", window size: ").concat(t.width,"*").concat(t.height,", events count: ").concat(t.events.length));for(var r=0;r<3&&r<t.events.length;++r)y(" ".concat(JSON.stringify(t.events[r])));n._upload(e).then((function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")})).then((function(e){if(y("Pkg ".concat(t.packetId," response=").concat(JSON.stringify(e))),"ok"!==e.status)throw new Error("Response object status is not ok.");"config"==e.msg&&o({status:1,msg:"Get config from server",config:e.data}),o({status:0})})).catch((function(r){y("Pkg ".concat(t.packetId," failed, wait for resending. Error message: ").concat(r.message)),n._appendFailedData(t,e),o({status:-1,msg:"Fail to upload data bunch #".concat(t.packetId,", ").concat(r.message)})}))}))}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,e=0;this.resendQueue.length>0&&y("Resending data...");for(var n=function(){var n=t.resendQueue[e];n.status==_?t.resendQueue.splice(e,1):(e+=1,y("Resending Pkg ".concat(n.data.packetId)),n.status==b&&(n.status=w,t.upload(n.data,n.encodedData).then((function(t){n.status=t?_:b}))))};e<this.resendQueue.length;)n()}},{key:"_upload",value:function(t){var e=h()(this.config.absoluteUrl,"?websiteId=".concat(this.config.websiteId,"&sessionId=").concat(this.sessionId,"&impressionId=").concat(this.impressionId,"&userId=").concat(g()));return this.config.enableGet?fetch("".concat(e,"&data=").concat(t),{method:"GET",credentials:"include",keepalive:!0}):fetch(e,{method:"POST",credentials:"include",body:t,keepalive:!0})}},{key:"_appendFailedData",value:function(t,e){this.resendQueue.push({status:b,data:t,encodedData:e})}}]),t}(),E=function(){function t(){a()(this,t),this.uploadEndpoint="http://localhost:9000",this.websiteId="unknown",this.endpointType="absolute",this.uploadMode="mixed",this.uploadPeriod=5e3,this.frequency=50,this.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.serverConfig=!0,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return c()(t,[{key:"build",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{this._requiredParams.forEach((function(e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new Error("Param ".concat(e," is required but not declared."))})),Object.keys(t).forEach((function(o){void 0!==e[o]&&0!==o.indexOf("_")&&"function"!=typeof e[o]&&(n&&o in e._ignoredParams||(e[o]=t[o]))})),this._formatUrl()}catch(t){return y(t),!1}return!0}},{key:"update",value:function(t){return this.build(t,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=h()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=h()(this.uploadEndpoint,"/api/upload-trace")}}}]),t}(),k=n(6),x=n.n(k),T=n(4),C=n.n(T),A=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend"],B=new Date,U="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,S=U?U.replace(/hidden/i,"visibilitychange"):null;var D=function(){function t(){var e;a()(this,t),this.impressionId=f()(),this.sessionId=((e=C.a.get("mouselogSessionId"))||(e=f()(),C.a.set("mouselogSessionId",e)),e),this.config=new E,this.mouselogLoadTime=new Date,this.uploader=new I,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvent,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return c()(t,[{key:"_clearBuffer",value:function(){this.eventsList=[]}},{key:"_newDataBatch",value:function(){var t={batchId:this.batchCount,packetId:0,url:window.location.hostname?window.location.hostname:"localhost",path:window.location.pathname,sessionId:this.sessionId,width:v(document.body.scrollWidth,window.innerWidth),height:v(document.body.scrollHeight,window.innerHeight),pageLoadTime:B,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{key:"_onVisibilityChange",value:function(){window.document[U]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=m(t.pageX),n=m(t.pageY);NaN!=e&&null!=e||(e=m(t.changedTouches[0].pageX),n=m(t.changedTouches[0].pageY));var o,r={id:this.eventsCount,timestamp:Math.floor(t.timeStamp)/1e3,type:t.type,x:e,y:n,button:(o=t.button,"2"===o?"Right":"")};if("wheel"==t.type&&(r.deltaX=t.deltaX,r.deltaY=t.deltaY),this.lastEvent&&this.lastEvent.x==r.x&&this.lastEvent.y==r.y){if("mousemove"==this.lastEvent.type&&"mousemove"==r.type)return;if(this.lastEvent.type==r.type&&this.lastEvent.button==r.button&&this.lastEvent.timestamp==r.timestamp)return}this.eventsList.push(r),this.lastEvent=r,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadTrace(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadTrace())}}},{key:"_encodeData",value:function(t){var e=JSON.stringify(t);return"base64"==this.config.encoder.toLowerCase()&&(e=btoa(e)),e}},{key:"_binarySplitBigDataBlock",value:function(t){var e=this._encodeData(t),n=[];if(function(t){for(var e=t.length,n=t.length-1;n>=0;n--){var o=t.charCodeAt(n);o>127&&o<=2047?e++:o>2047&&o<=65535&&(e+=2),o>=56320&&o<=57343&&n--}return e}(e)>=this.config.sizeLimit){var o=x()(t);t.events.splice(t.events.length/2),o.events.splice(0,o.events.length/2),this._binarySplitBigDataBlock(t).forEach((function(t){n.push(t)})),this._binarySplitBigDataBlock(o).forEach((function(t){n.push(t)}))}else n.push([t,e]);return n}},{key:"_fetchConfigFromServer",value:function(){var t=this._newDataBatch();return t.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(t,this._encodeData(t))}},{key:"_uploadTrace",value:function(){var t=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.serverConfig)){var e=this._newDataBatch();e.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(e).forEach((function(e){var n;e[0].packetId=t.packetCount,t.packetCount+=1,(n=t.uploader).upload.apply(n,i()(e))}))}}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval((function(){t.eventsList.length>0&&t._uploadTrace()}),this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var t=this;A.forEach((function(e){t.config.scope.addEventListener(e,(function(e){return t._mouseHandler(e)}))})),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var t=this;A.forEach((function(e){t.config.scope.removeEventListener(e,(function(e){return t._mouseHandler(e)}))})),clearInterval(this.uploadInterval),clearTimeout(this.uploadTimeout)}},{key:"_resetCollector",value:function(){this._stopCollector(),this._runCollector()}},{key:"_init",value:function(t){var e=this;return this._clearBuffer(),this.uploader=new I(this.impressionId,this.sessionId,this.config),this.config.build(t)?(this.config.serverConfig&&this._fetchConfigFromServer().then((function(t){if(1!=t.status)throw new Error("Fail to get config from server.");if(!e.config.update(t.config))throw new Error("Unable to update config with server config.");e._resetCollector(),e.uploader.setConfig(e.config),y("Successfully update config from backend.")})).catch((function(t){y(t)})),window.onunload=function(){0!=e.eventsList.length&&e._uploadTrace()},{status:0}):{status:-1,msg:"Invalid configuration."}}},{key:"_pause",value:function(){this._stopCollector()}},{key:"_resume",value:function(){this._runCollector()}},{key:"run",value:function(t){var e=this,n=this._init(t);0==n.status?(S&&document.addEventListener(S,(function(t){return e._onVisibilityChange(t)})),this._runCollector(),this.uploader.start(this.impressionId),y("Mouselog agent is activated!"),y("Website ID: ".concat(this.config.websiteId)),y("Session ID: ".concat(this.sessionId)),y("Impression ID: ".concat(this.impressionId)),y("User-Agent: ".concat(navigator.userAgent)),y("User ID: ".concat(g())),y("Page load time: ".concat(B))):(y(n.msg),y("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;p=!0,(n=e)&&((o=window.document.getElementById(n))||console.log("Fail to find the output element.")),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),y("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function O(){return new D}n.d(e,"init",(function(){return O}))}])}));
{
"name": "mouselog",
"version": "0.1.7",
"version": "0.1.8",
"description": "The mouse tracking agent for Mouselog.",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -113,5 +113,17 @@ [![NPM version](https://img.shields.io/npm/v/mouselog)](https://www.npmjs.com/package/mouselog)

// Type: number | null
// Mouselog will stop uploading data after uploading `uploadTimes` batch data.
uploadTimes = null
// Maximum size of a single package
sizeLimit = 65535,
// Content: "base64" or an empty string
// Use a encoder before uploading the data
encoder = "";
// Type: Boolean
// If `serverConfig`, Mouselog will fetch config from backend server during initialization
serverConfig = true;
// Type: bool

@@ -118,0 +130,0 @@ // Use GET method to upload data? (stringified data will be embedded in URI)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc