New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.2.4 to 0.2.5-beta1

12

build/mouselog.min.js

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

/*! Mouselog Agent - v0.2.4 | 2020-3-24 | 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 o={},r.m=n=[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 o(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,n){return e&&o(t.prototype,e),n&&o(t,n),t}},function(t,e,n){var o,r,i;i=function(){return function(){return function(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(/^[^/:]+:\/*$/)&&1<t.length){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&&(0<o&&(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()+(0<s.length?"?":"")+s.join("&")}("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 s=n(8),a=n(9);t.exports=function(t,e,n){var o=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var r=(t=t||{}).random||(t.rng||s)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,e)for(var i=0;i<16;++i)e[o+i]=r[i];return e||a(r)}},function(t,e,n){function a(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}t.exports=function(t){if(/number|string|boolean/.test(typeof t))return t;if(t instanceof Date)return new Date(t.getTime());var e=t instanceof Array?[]:{};return function t(e,n){for(var o in e){var r=e[o];if(r instanceof Date){var i=new Date(r.getTime());a(n,o,i)}else if(r instanceof Function){var i=r;a(n,o,i)}else if(r instanceof Array){var i=[],s=a(n,o,i);t(r,s)}else if(r instanceof Object){var i={},s=a(n,o,i);t(r,s)}else{var i=r;a(n,o,i)}}}(t,e),e}},function(t,e,n){n(6),t.exports=n(10)},function(t,e,n){n(7),t.exports=self.fetch.bind(self)},function(t,e,n){"use strict";n.r(e),n.d(e,"Headers",function(){return c}),n.d(e,"Request",function(){return v}),n.d(e,"Response",function(){return m}),n.d(e,"DOMException",function(){return w}),n.d(e,"fetch",function(){return _});var a={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(a.arrayBuffer)var o=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],r=ArrayBuffer.isView||function(t){return t&&-1<o.indexOf(Object.prototype.toString.call(t))};function i(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 s(t){return"string"!=typeof t&&(t=String(t)),t}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return a.iterable&&(t[Symbol.iterator]=function(){return t}),t}function c(e){this.map={},e instanceof c?e.forEach(function(t,e){this.append(e,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function l(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function f(n){return new Promise(function(t,e){n.onload=function(){t(n.result)},n.onerror=function(){e(n.error)}})}function d(t){var e=new FileReader,n=f(e);return e.readAsArrayBuffer(t),n}function h(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;(this._bodyInit=t)?"string"==typeof t?this._bodyText=t:a.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:a.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a.arrayBuffer&&a.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=h(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||r(t))?this._bodyArrayBuffer=h(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):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.blob&&(this.blob=function(){var t=l(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?l(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var t,e,n,o=l(this);if(o)return o;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=f(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)},a.formData&&(this.formData=function(){return this.text().then(g)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,e){t=i(t),e=s(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},c.prototype.delete=function(t){delete this.map[i(t)]},c.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},c.prototype.set=function(t,e){this.map[i(t)]=s(e)},c.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},c.prototype.keys=function(){var n=[];return this.forEach(function(t,e){n.push(e)}),u(n)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),u(e)},c.prototype.entries=function(){var n=[];return this.forEach(function(t,e){n.push([e,t])}),u(n)},a.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function v(t,e){var n,o,r=(e=e||{}).body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new c(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 c(e.headers)),this.method=(n=e.method||this.method||"GET",o=n.toUpperCase(),-1<y.indexOf(o)?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 g(t){var r=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),n=e.shift().replace(/\+/g," "),o=e.join("=").replace(/\+/g," ");r.append(decodeURIComponent(n),decodeURIComponent(o))}}),r}function m(t,e){e=e||{},this.type="default",this.status=void 0===e.status?200:e.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new c(e.headers),this.url=e.url||"",this._initBody(t)}v.prototype.clone=function(){return new v(this,{body:this._bodyInit})},p.call(v.prototype),p.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},m.error=function(){var t=new m(null,{status:0,statusText:""});return t.type="error",t};var b=[301,302,303,307,308];m.redirect=function(t,e){if(-1===b.indexOf(e))throw new RangeError("Invalid status code");return new m(null,{status:e,headers:{location:t}})};var w=self.DOMException;try{new w}catch(t){(w=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function _(r,s){return new Promise(function(o,t){var e=new v(r,s);if(e.signal&&e.signal.aborted)return t(new w("Aborted","AbortError"));var i=new XMLHttpRequest;function n(){i.abort()}i.onload=function(){var t,r,e={status:i.status,statusText:i.statusText,headers:(t=i.getAllResponseHeaders()||"",r=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var e=t.split(":"),n=e.shift().trim();if(n){var o=e.join(":").trim();r.append(n,o)}}),r)};e.url="responseURL"in i?i.responseURL:e.headers.get("X-Request-URL");var n="response"in i?i.response:i.responseText;o(new m(n,e))},i.onerror=function(){t(new TypeError("Network request failed"))},i.ontimeout=function(){t(new TypeError("Network request failed"))},i.onabort=function(){t(new w("Aborted","AbortError"))},i.open(e.method,e.url,!0),"include"===e.credentials?i.withCredentials=!0:"omit"===e.credentials&&(i.withCredentials=!1),"responseType"in i&&a.blob&&(i.responseType="blob"),e.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),e.signal&&(e.signal.addEventListener("abort",n),i.onreadystatechange=function(){4===i.readyState&&e.signal.removeEventListener("abort",n)}),i.send(void 0===e._bodyInit?null:e._bodyInit)})}_.polyfill=!0,self.fetch||(self.fetch=_,self.Headers=c,self.Request=v,self.Response=m)},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 o=[],n=0;n<256;++n)o[n]=(n+256).toString(16).substr(1);t.exports=function(t,e){var n=e||0;return[o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],"-",o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]],o[t[n++]]].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),f=n.n(l),d=!1;function h(t){if(d&&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)}}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:""}function g(t,e){if(t&&e&&t.length==e.length){for(var n=0;n<t.length;++n)if(t[n]!=e[n])return;return 1}}var m=0,b=1,w=2,_=function(){function o(t,e,n){i()(this,o),this.impressionId=t,this.sessionId=e,this.config=n,this.resendQueue=[]}return a()(o,[{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(o,r,t){var i=this,s=2<arguments.length&&void 0!==t&&t;return new Promise(function(e){h("Uploading Pkg ".concat(o.packetId,", window size: ").concat(o.width,"*").concat(o.height,", events count: ").concat(o.events.length));for(var t=0;t<3&&t<o.events.length;++t)h(" ".concat(JSON.stringify(o.events[t])));var n=f()(i.config.absoluteUrl,"?websiteId=".concat(i.config.websiteId,"&sessionId=").concat(i.sessionId,"&impressionId=").concat(i.impressionId,"&userId=").concat(v()).concat(s?"&queryConfig=1":""));i._upload(r,n).then(function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")}).then(function(t){if(h("Pkg ".concat(o.packetId," response=").concat(JSON.stringify(t))),"ok"!==t.status)throw new Error("Response object status is not ok.");"config"==t.msg&&e({status:1,msg:"Get config from server",config:t.data}),e({status:0})}).catch(function(t){h("Pkg ".concat(o.packetId," failed, wait for resending. Error message: ").concat(t.message)),i._appendFailedData(o,r),e({status:-1,msg:"Fail to upload data bunch #".concat(o.packetId,", ").concat(t.message)})})})}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,n=0;0<this.resendQueue.length&&h("Resending data...");for(var e=function(){var e=t.resendQueue[n];e.status==w?t.resendQueue.splice(n,1):(n+=1,h("Resending Pkg ".concat(e.data.packetId)),e.status==m&&(e.status=b,t.upload(e.data,e.encodedData).then(function(t){e.status=t?w:m})))};n<this.resendQueue.length;)e()}},{key:"_upload",value:function(t,e){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})}}]),o}(),I=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.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.enableServerConfig=!0,this.enableSession=!0,this.enableSendEmpty=!1,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(e,t){var n=this,o=1<arguments.length&&void 0!==t&&t;try{this._requiredParams.forEach(function(t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("Param ".concat(t," is required but not declared."))}),Object.keys(e).forEach(function(t){void 0!==n[t]&&0!==t.indexOf("_")&&"function"!=typeof n[t]&&(o&&t in n._ignoredParams||(n[t]=e[t]))}),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=f()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=this.uploadEndpoint}}}]),t}(),k=n(4),E=n.n(k),T=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],x=new Date,D=function(){var t=c()();try{return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch(t){return!1}}(),S="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,B=S?S.replace(/hidden/i,"visibilitychange"):null;function A(){if(!D)return"";var t=localStorage.getItem("mouselogSessionID");return null==t&&(t=c()(),localStorage.setItem("mouselogSessionID",t)),t}var C=function(){function t(){i()(this,t),this.config=new I,this.impressionId=c()(),this.mouselogLoadTime=new Date,this.uploader=new _,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(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,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:x,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{key:"_onVisibilityChange",value:function(){window.document[S]?this._pause():this._resume()}},{key:"_mouseHandler",value:function(t){if("contextmenu"!==t.type||0!==t.pageX||0!==t.pageY){var e=[this.eventsCount,T.indexOf(t.type),Math.floor(t.timeStamp)/1e3];switch(t.type){case"mousemove":var n=y(t.pageX),o=y(t.pageY);e.push(n,o);break;case"touchmove":case"touchstart":case"touchend":n=y(t.changedTouches[0].pageX),o=y(t.changedTouches[0].pageY),e.push(n,o);break;case"wheel":n=y(t.pageX),o=y(t.pageY);var r=y(t.deltaX),i=y(t.deltaY);e.push(n,o,r,i);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=y(t.pageX),o=y(t.pageY);var s="2"===t.buttono?"Right":"";e.push(n,o,s);break;case"resize":var a=t.target.innerWidth,u=t.target.innerHeight;e.push(a,u)}this.lastEvtInfo&&g(this.lastEvtInfo,e)||this.lastEvtInfo&&("mousemove"==T[e[1]]||"touchmove"==T[e[1]])&&this.lastEvtInfo[1]==e[1]&&g(this.lastEvtInfo.slice(3),e.slice(3))||(this.eventsList.push(e),this.lastEvtInfo=e,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{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;0<=n;n--){var o=t.charCodeAt(n);127<o&&o<=2047?e++:2047<o&&o<=65535&&(e+=2),56320<=o&&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._newDataBatch();return t.packetId=this.packetCount,this.packetCount+=1,this.uploader.upload(t,this._encodeData(t),!0)}},{key:"_uploadData",value:function(){var n=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.enableServerConfig)){var t=this._newDataBatch();t.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(t).forEach(function(t){t.packetId=n.packetCount,n.packetCount+=1;var e=n._encodeData(t);n.uploader.upload(t,e)})}}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout(function(){(t.config.enableSendEmpty||0<t.eventsList.length)&&t._uploadData()},this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval(function(){(t.config.enableSendEmpty||0<t.eventsList.length)&&t._uploadData()},this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var e=this;T.forEach(function(t){e.config.scope.addEventListener(t,function(t){return e._mouseHandler(t)})}),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var e=this;T.forEach(function(t){e.config.scope.removeEventListener(t,function(t){return e._mouseHandler(t)})}),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.config.build(t)?(this.sessionId=this.config.enableSession?A():"",this.uploader=new _(this.impressionId,this.sessionId,this.config),this.config.enableServerConfig&&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),e.sessionId=e.config.enableSession?A():"",e.uploader.sessionId=e.sessionId,h("Successfully update config from backend.")}).catch(function(t){h(t)}),window.onunload=function(){0!=e.eventsList.length&&e._uploadData()},{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?(B&&document.addEventListener(B,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(x))):(h(n.msg),h("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;d=!0,(n=e)&&(o=window.document.getElementById(n)),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),h("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function P(){return new C}n.d(e,"init",function(){return P})}],r.c=o,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=5);function r(t){if(o[t])return o[t].exports;var e=o[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}var n,o});
/*! Mouselog Agent - v0.2.5-beta1 | 2020-3-24 | 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 r={},o.m=n=[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 r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}},function(t,e,n){var r,o,i;i=function(){return function(){return function(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(/^[^/:]+:\/*$/)&&1<t.length){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 r=0;r<t.length;r++){var o=t[r];if("string"!=typeof o)throw new TypeError("Url must be a string. Received "+o);""!==o&&(0<r&&(o=o.replace(/^[\/]+/,"")),o=r<t.length-1?o.replace(/[\/]+$/,""):o.replace(/[\/]+$/,"/"),e.push(o))}var i=e.join("/"),s=(i=i.replace(/\/(\?|&|#[^!])/g,"$1")).split("?");return i=s.shift()+(0<s.length?"?":"")+s.join("&")}("object"==typeof arguments[0]?arguments[0]:[].slice.call(arguments))}},t.exports?t.exports=i():void 0===(o="function"==typeof(r=i)?r.call(e,n,e,t):r)||(t.exports=o)},function(t,e,n){var s=n(13),a=n(14);t.exports=function(t,e,n){var r=e&&n||0;"string"==typeof t&&(e="binary"===t?new Array(16):null,t=null);var o=(t=t||{}).random||(t.rng||s)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e)for(var i=0;i<16;++i)e[r+i]=o[i];return e||a(o)}},function(t,e){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){function a(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}t.exports=function(t){if(/number|string|boolean/.test(typeof t))return t;if(t instanceof Date)return new Date(t.getTime());var e=t instanceof Array?[]:{};return function t(e,n){for(var r in e){var o=e[r];if(o instanceof Date){var i=new Date(o.getTime());a(n,r,i)}else if(o instanceof Function){var i=o;a(n,r,i)}else if(o instanceof Array){var i=[],s=a(n,r,i);t(o,s)}else if(o instanceof Object){var i={},s=a(n,r,i);t(o,s)}else{var i=o;a(n,r,i)}}}(t,e),e}},function(t,u,l){(function(o,i){var s;/*! http://mths.be/base64 v0.1.0 by @mathias | MIT license */!function(){var t=u,e=(o&&o.exports,"object"==typeof i&&i);e.global!==e&&e.window;function n(t){this.message=t}(n.prototype=new Error).name="InvalidCharacterError";function c(t){throw new n(t)}var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=/[\t\n\f\r ]/g,r={encode:function(t){t=String(t),/[^\0-\xFF]/.test(t)&&c("The string to be encoded contains characters outside of the Latin1 range.");for(var e,n,r,o,i=t.length%3,s="",a=-1,u=t.length-i;++a<u;)e=t.charCodeAt(a)<<16,n=t.charCodeAt(++a)<<8,r=t.charCodeAt(++a),s+=f.charAt((o=e+n+r)>>18&63)+f.charAt(o>>12&63)+f.charAt(o>>6&63)+f.charAt(63&o);return 2==i?(e=t.charCodeAt(a)<<8,n=t.charCodeAt(++a),s+=f.charAt((o=e+n)>>10)+f.charAt(o>>4&63)+f.charAt(o<<2&63)+"="):1==i&&(o=t.charCodeAt(a),s+=f.charAt(o>>2)+f.charAt(o<<4&63)+"=="),s},decode:function(t){var e=(t=String(t).replace(a,"")).length;e%4==0&&(e=(t=t.replace(/==?$/,"")).length),e%4!=1&&!/[^+a-zA-Z0-9/]/.test(t)||c("Invalid character: the string to be decoded is not correctly encoded.");for(var n,r,o=0,i="",s=-1;++s<e;)r=f.indexOf(t.charAt(s)),n=o%4?64*n+r:r,o++%4&&(i+=String.fromCharCode(255&n>>(-2*o&6)));return i},version:"0.1.0"};void 0===(s=function(){return r}.call(u,l,u,o))||(o.exports=s)}()}).call(this,l(15)(t),l(4))},function(t,e,n){n(8),t.exports=n(16)},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 c}),n.d(e,"Request",function(){return y}),n.d(e,"Response",function(){return g}),n.d(e,"DOMException",function(){return w}),n.d(e,"fetch",function(){return _});var a={searchParams:"URLSearchParams"in self,iterable:"Symbol"in self&&"iterator"in Symbol,blob:"FileReader"in self&&"Blob"in self&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in self,arrayBuffer:"ArrayBuffer"in self};if(a.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(t){return t&&-1<r.indexOf(Object.prototype.toString.call(t))};function i(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 s(t){return"string"!=typeof t&&(t=String(t)),t}function u(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return a.iterable&&(t[Symbol.iterator]=function(){return t}),t}function c(e){this.map={},e instanceof c?e.forEach(function(t,e){this.append(e,t)},this):Array.isArray(e)?e.forEach(function(t){this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function f(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(n){return new Promise(function(t,e){n.onload=function(){t(n.result)},n.onerror=function(){e(n.error)}})}function h(t){var e=new FileReader,n=l(e);return e.readAsArrayBuffer(t),n}function d(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;(this._bodyInit=t)?"string"==typeof t?this._bodyText=t:a.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:a.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:a.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():a.arrayBuffer&&a.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):a.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||o(t))?this._bodyArrayBuffer=d(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):a.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},a.blob&&(this.blob=function(){var t=f(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?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(h)}),this.text=function(){var t,e,n,r=f(this);if(r)return r;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,n=l(e),e.readAsText(t),n;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),n=new Array(e.length),r=0;r<e.length;r++)n[r]=String.fromCharCode(e[r]);return n.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},a.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}c.prototype.append=function(t,e){t=i(t),e=s(e);var n=this.map[t];this.map[t]=n?n+", "+e:e},c.prototype.delete=function(t){delete this.map[i(t)]},c.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},c.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},c.prototype.set=function(t,e){this.map[i(t)]=s(e)},c.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},c.prototype.keys=function(){var n=[];return this.forEach(function(t,e){n.push(e)}),u(n)},c.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),u(e)},c.prototype.entries=function(){var n=[];return this.forEach(function(t,e){n.push([e,t])}),u(n)},a.iterable&&(c.prototype[Symbol.iterator]=c.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var n,r,o=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new c(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=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 c(e.headers)),this.method=(n=e.method||this.method||"GET",r=n.toUpperCase(),-1<v.indexOf(r)?r:n),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function m(t){var o=new FormData;return t.trim().split("&").forEach(function(t){if(t){var e=t.split("="),n=e.shift().replace(/\+/g," "),r=e.join("=").replace(/\+/g," ");o.append(decodeURIComponent(n),decodeURIComponent(r))}}),o}function g(t,e){e=e||{},this.type="default",this.status=void 0===e.status?200:e.status,this.ok=200<=this.status&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new c(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},p.call(y.prototype),p.call(g.prototype),g.prototype.clone=function(){return new g(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new c(this.headers),url:this.url})},g.error=function(){var t=new g(null,{status:0,statusText:""});return t.type="error",t};var b=[301,302,303,307,308];g.redirect=function(t,e){if(-1===b.indexOf(e))throw new RangeError("Invalid status code");return new g(null,{status:e,headers:{location:t}})};var w=self.DOMException;try{new w}catch(t){(w=function(t,e){this.message=t,this.name=e;var n=Error(t);this.stack=n.stack}).prototype=Object.create(Error.prototype),w.prototype.constructor=w}function _(o,s){return new Promise(function(r,t){var e=new y(o,s);if(e.signal&&e.signal.aborted)return t(new w("Aborted","AbortError"));var i=new XMLHttpRequest;function n(){i.abort()}i.onload=function(){var t,o,e={status:i.status,statusText:i.statusText,headers:(t=i.getAllResponseHeaders()||"",o=new c,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var e=t.split(":"),n=e.shift().trim();if(n){var r=e.join(":").trim();o.append(n,r)}}),o)};e.url="responseURL"in i?i.responseURL:e.headers.get("X-Request-URL");var n="response"in i?i.response:i.responseText;r(new g(n,e))},i.onerror=function(){t(new TypeError("Network request failed"))},i.ontimeout=function(){t(new TypeError("Network request failed"))},i.onabort=function(){t(new w("Aborted","AbortError"))},i.open(e.method,e.url,!0),"include"===e.credentials?i.withCredentials=!0:"omit"===e.credentials&&(i.withCredentials=!1),"responseType"in i&&a.blob&&(i.responseType="blob"),e.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),e.signal&&(e.signal.addEventListener("abort",n),i.onreadystatechange=function(){4===i.readyState&&e.signal.removeEventListener("abort",n)}),i.send(void 0===e._bodyInit?null:e._bodyInit)})}_.polyfill=!0,self.fetch||(self.fetch=_,self.Headers=c,self.Request=y,self.Response=g)},function(t,e,n){"use strict";t.exports=n(11).polyfill()},function(t,e,n){(function(rt,ot){
/*!
* @overview es6-promise - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
* @version v4.2.8+1e68dce6
*/
t.exports=function(){"use strict";function r(t){var e=typeof t;return t!==null&&(e==="object"||e==="function")}function u(t){return typeof t==="function"}var t=void 0;if(Array.isArray){t=Array.isArray}else{t=function(t){return Object.prototype.toString.call(t)==="[object Array]"}}var n=t,o=0,e=void 0,i=void 0,s=function t(e,n){w[o]=e;w[o+1]=n;o+=2;if(o===2){if(i){i(_)}else{E()}}};function a(t){i=t}function c(t){s=t}var f=typeof window!=="undefined"?window:undefined,l=f||{},h=l.MutationObserver||l.WebKitMutationObserver,d=typeof self==="undefined"&&typeof rt!=="undefined"&&{}.toString.call(rt)==="[object process]",p=typeof Uint8ClampedArray!=="undefined"&&typeof importScripts!=="undefined"&&typeof MessageChannel!=="undefined";function v(){return function(){return rt.nextTick(_)}}function y(){if(typeof e!=="undefined"){return function(){e(_)}}return b()}function m(){var t=0;var e=new h(_);var n=document.createTextNode("");e.observe(n,{characterData:true});return function(){n.data=t=++t%2}}function g(){var t=new MessageChannel;t.port1.onmessage=_;return function(){return t.port2.postMessage(0)}}function b(){var t=setTimeout;return function(){return t(_,1)}}var w=new Array(1e3);function _(){for(var t=0;t<o;t+=2){var e=w[t];var n=w[t+1];e(n);w[t]=undefined;w[t+1]=undefined}o=0}function T(){try{var t=Function("return this")().require("vertx");e=t.runOnLoop||t.runOnContext;return y()}catch(t){return b()}}var E=void 0;if(d){E=v()}else if(h){E=m()}else if(p){E=g()}else if(f===undefined&&"function"==="function"){E=T()}else{E=b()}function A(t,e){var n=this;var r=new this.constructor(x);if(r[k]===undefined){X(r)}var o=n._state;if(o){var i=arguments[o-1];s(function(){return N(o,r,i,n._result)})}else{q(n,r,t,e)}return r}function I(t){var e=this;if(t&&typeof t==="object"&&t.constructor===e){return t}var n=new e(x);F(n,t);return n}var k=Math.random().toString(36).substring(2);function x(){}var S=void 0,C=1,P=2;function j(){return new TypeError("You cannot resolve a promise with itself")}function D(){return new TypeError("A promises callback cannot return that same promise.")}function O(t,e,n,r){try{t.call(e,n,r)}catch(t){return t}}function B(t,r,o){s(function(e){var n=false;var t=O(o,r,function(t){if(n){return}n=true;if(r!==t){F(e,t)}else{M(e,t)}},function(t){if(n){return}n=true;H(e,t)},"Settle: "+(e._label||" unknown promise"));if(!n&&t){n=true;H(e,t)}},t)}function U(e,t){if(t._state===C){M(e,t._result)}else if(t._state===P){H(e,t._result)}else{q(t,undefined,function(t){return F(e,t)},function(t){return H(e,t)})}}function L(t,e,n){if(e.constructor===t.constructor&&n===A&&e.constructor.resolve===I){U(t,e)}else{if(n===undefined){M(t,e)}else if(u(n)){B(t,e,n)}else{M(t,e)}}}function F(e,t){if(e===t){H(e,j())}else if(r(t)){var n=void 0;try{n=t.then}catch(t){H(e,t);return}L(e,t,n)}else{M(e,t)}}function R(t){if(t._onerror){t._onerror(t._result)}z(t)}function M(t,e){if(t._state!==S){return}t._result=e;t._state=C;if(t._subscribers.length!==0){s(z,t)}}function H(t,e){if(t._state!==S){return}t._state=P;t._result=e;s(R,t)}function q(t,e,n,r){var o=t._subscribers;var i=o.length;t._onerror=null;o[i]=e;o[i+C]=n;o[i+P]=r;if(i===0&&t._state){s(z,t)}}function z(t){var e=t._subscribers;var n=t._state;if(e.length===0){return}var r=void 0,o=void 0,i=t._result;for(var s=0;s<e.length;s+=3){r=e[s];o=e[s+n];if(r){N(n,r,o,i)}else{o(i)}}t._subscribers.length=0}function N(t,e,n,r){var o=u(n),i=void 0,s=void 0,a=true;if(o){try{i=n(r)}catch(t){a=false;s=t}if(e===i){H(e,D());return}}else{i=r}if(e._state!==S){}else if(o&&a){F(e,i)}else if(a===false){H(e,s)}else if(t===C){M(e,i)}else if(t===P){H(e,i)}}function Y(n,t){try{t(function t(e){F(n,e)},function t(e){H(n,e)})}catch(t){H(n,t)}}var G=0;function V(){return G++}function X(t){t[k]=G++;t._state=undefined;t._result=undefined;t._subscribers=[]}function $(){return new Error("Array Methods must be provided an Array")}var Q=function(){function t(t,e){this._instanceConstructor=t;this.promise=new t(x);if(!this.promise[k]){X(this.promise)}if(n(e)){this.length=e.length;this._remaining=e.length;this._result=new Array(this.length);if(this.length===0){M(this.promise,this._result)}else{this.length=this.length||0;this._enumerate(e);if(this._remaining===0){M(this.promise,this._result)}}}else{H(this.promise,$())}}t.prototype._enumerate=function t(e){for(var n=0;this._state===S&&n<e.length;n++){this._eachEntry(e[n],n)}};t.prototype._eachEntry=function t(e,n){var r=this._instanceConstructor;var o=r.resolve;if(o===I){var i=void 0;var s=void 0;var a=false;try{i=e.then}catch(t){a=true;s=t}if(i===A&&e._state!==S){this._settledAt(e._state,n,e._result)}else if(typeof i!=="function"){this._remaining--;this._result[n]=e}else if(r===et){var u=new r(x);if(a){H(u,s)}else{L(u,e,i)}this._willSettleAt(u,n)}else{this._willSettleAt(new r(function(t){return t(e)}),n)}}else{this._willSettleAt(o(e),n)}};t.prototype._settledAt=function t(e,n,r){var o=this.promise;if(o._state===S){this._remaining--;if(e===P){H(o,r)}else{this._result[n]=r}}if(this._remaining===0){M(o,this._result)}};t.prototype._willSettleAt=function t(e,n){var r=this;q(e,undefined,function(t){return r._settledAt(C,n,t)},function(t){return r._settledAt(P,n,t)})};return t}();function W(t){return new Q(this,t).promise}function J(o){var i=this;if(n(o))return new i(function(t,e){for(var n=o.length,r=0;r<n;r++)i.resolve(o[r]).then(t,e)});else return new i(function(t,e){return e(new TypeError("You must pass an array to race."))})}function K(t){var e=new this(x);return H(e,t),e}function Z(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function tt(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}var et=function(){function e(t){this[k]=V();this._result=this._state=undefined;this._subscribers=[];if(x!==t){typeof t!=="function"&&Z();this instanceof e?Y(this,t):tt()}}e.prototype.catch=function t(e){return this.then(null,e)};e.prototype.finally=function t(e){var n=this;var r=n.constructor;if(u(e)){return n.then(function(t){return r.resolve(e()).then(function(){return t})},function(t){return r.resolve(e()).then(function(){throw t})})}return n.then(e,e)};return e}();function nt(){var t=void 0;if(void 0!==ot)t=ot;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=et}return et.prototype.then=A,et.all=function(t){return new Q(this,t).promise},et.race=function(o){var i=this;return n(o)?new i(function(t,e){for(var n=o.length,r=0;r<n;r++)i.resolve(o[r]).then(t,e)}):new i(function(t,e){return e(new TypeError("You must pass an array to race."))})},et.resolve=I,et.reject=function(t){var e=new this(x);return H(e,t),e},et._setScheduler=function(t){i=t},et._setAsap=function(t){s=t},et._asap=s,et.polyfill=function(){var t=void 0;if(void 0!==ot)t=ot;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var e=t.Promise;if(e){var n=null;try{n=Object.prototype.toString.call(e.resolve())}catch(t){}if("[object Promise]"===n&&!e.cast)return}t.Promise=et},et.Promise=et}()}).call(this,n(12),n(4))},function(t,e){var n,r,o=t.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(t){n=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(t){r=s}}();var u,c=[],f=!1,l=-1;function h(){f&&u&&(f=!1,u.length?c=u.concat(c):l=-1,c.length&&d())}function d(){if(!f){var t=a(h);f=!0;for(var e=c.length;e;){for(u=c,c=[];++l<e;)u&&u[l].run();l=-1,e=c.length}u=null,f=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function v(){}o.nextTick=function(t){var e=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new p(t,e)),1!==c.length||f||a(d)},p.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=v,o.addListener=v,o.once=v,o.off=v,o.removeListener=v,o.removeAllListeners=v,o.emit=v,o.prependListener=v,o.prependOnceListener=v,o.listeners=function(t){return[]},o.binding=function(t){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(t){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},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 r=new Uint8Array(16);t.exports=function(){return n(r),r}}else{var o=new Array(16);t.exports=function(){for(var t,e=0;e<16;e++)0==(3&e)&&(t=4294967296*Math.random()),o[e]=t>>>((3&e)<<3)&255;return o}}},function(t,e){for(var r=[],n=0;n<256;++n)r[n]=(n+256).toString(16).substr(1);t.exports=function(t,e){var n=e||0;return[r[t[n++]],r[t[n++]],r[t[n++]],r[t[n++]],"-",r[t[n++]],r[t[n++]],"-",r[t[n++]],r[t[n++]],"-",r[t[n++]],r[t[n++]],"-",r[t[n++]],r[t[n++]],r[t[n++]],r[t[n++]],r[t[n++]],r[t[n++]]].join("")}},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";n.r(e);var r,o=n(0),i=n.n(o),s=n(1),a=n.n(s),u=(n(10),n(3)),c=n.n(u),f=n(2),l=n.n(f),h=!1;function d(t){if(h&&r){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),r.appendChild(e)}}function p(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var r=e[0],o=1;o<e.length;++o)r=r>e[o]?r:e[o];return r}function v(t){var e="number"==typeof t?t:Number(t);return Math.round(e)}function y(){return window.mouselogUserId?window.mouselogUserId:""}function m(t,e){if(t&&e&&t.length==e.length){for(var n=0;n<t.length;++n)if(t[n]!=e[n])return;return 1}}var g=0,b=1,w=2,_=function(){function r(t,e,n){i()(this,r),this.impressionId=t,this.sessionId=e,this.config=n,this.resendQueue=[]}return a()(r,[{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(r,o,t){var i=this,s=2<arguments.length&&void 0!==t&&t;return new Promise(function(e){d("Uploading Pkg ".concat(r.packetId,", window size: ").concat(r.width,"*").concat(r.height,", events count: ").concat(r.events.length));for(var t=0;t<3&&t<r.events.length;++t)d(" ".concat(JSON.stringify(r.events[t])));var n=l()(i.config.absoluteUrl,"?websiteId=".concat(i.config.websiteId,"&sessionId=").concat(i.sessionId,"&impressionId=").concat(i.impressionId,"&userId=").concat(y()).concat(s?"&queryConfig=1":""));i._upload(o,n).then(function(t){if(200==t.status)return t.json();throw new Error("Response status code is not 200.")}).then(function(t){if(d("Pkg ".concat(r.packetId," response=").concat(JSON.stringify(t))),"ok"!==t.status)throw new Error("Response object status is not ok.");"config"==t.msg&&e({status:1,msg:"Get config from server",config:t.data}),e({status:0})}).catch(function(t){d("Pkg ".concat(r.packetId," failed, wait for resending. Error message: ").concat(t.message)),i._appendFailedData(r,o),e({status:-1,msg:"Fail to upload data bunch #".concat(r.packetId,", ").concat(t.message)})})})}},{key:"setConfig",value:function(t){this.stop(),this.config=t,this.start()}},{key:"_resendFailedData",value:function(){var t=this,n=0;0<this.resendQueue.length&&d("Resending data...");for(var e=function(){var e=t.resendQueue[n];e.status==w?t.resendQueue.splice(n,1):(n+=1,d("Resending Pkg ".concat(e.data.packetId)),e.status==g&&(e.status=b,t.upload(e.data,e.encodedData).then(function(t){e.status=t?w:g})))};n<this.resendQueue.length;)e()}},{key:"_upload",value:function(t,e){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:g,data:t,encodedData:e})}}]),r}(),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.uploadTimes=null,this.sizeLimit=65535,this.enableGet=!1,this.resendInterval=2e4,this.scope=window.document,this.encoder="",this.enableServerConfig=!0,this.enableSession=!0,this.enableSendEmpty=!1,this._requiredParams=["uploadEndpoint"],this._ignoredParams=["scope"]}return a()(t,[{key:"build",value:function(e,t){var n=this,r=1<arguments.length&&void 0!==t&&t;try{this._requiredParams.forEach(function(t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new Error("Param ".concat(t," is required but not declared."))}),Object.keys(e).forEach(function(t){void 0!==n[t]&&0!==t.indexOf("_")&&"function"!=typeof n[t]&&(r&&t in n._ignoredParams||(n[t]=e[t]))}),this._formatUrl()}catch(t){return d(t),!1}return!0}},{key:"update",value:function(t){return this.build(t,!0)}},{key:"_formatUrl",value:function(){if("relative"==this.endpointType)this.absoluteUrl=l()(window.location.origin,this.uploadEndpoint);else{if("absolute"!=this.endpointType)throw new Error('`endpointType` can only be "absolute" or "relative"');this.absoluteUrl=this.uploadEndpoint}}}]),t}(),E=n(5),A=n.n(E),I=n(6),k=["mousemove","mousedown","mouseup","click","dblclick","contextmenu","wheel","touchstart","touchmove","touchend","resize"],x=new Date,S=function(){var t=c()();try{return localStorage.setItem(t,t),localStorage.removeItem(t),!0}catch(t){return!1}}(),C="hidden"in document?"hidden":"webkitHidden"in document?"webkitHidden":"mozHidden"in document?"mozHidden":null,P=C?C.replace(/hidden/i,"visibilitychange"):null;function j(){if(!S)return"";var t=localStorage.getItem("mouselogSessionID");return null==t&&(t=c()(),localStorage.setItem("mouselogSessionID",t)),t}var D=function(){function t(){i()(this,t),this.config=new T,this.impressionId=c()(),this.mouselogLoadTime=new Date,this.uploader=new _,this.batchCount=0,this.packetCount=0,this.eventsList=[],this.lastEvtInfo,this.eventsCount=0,this.uploadInterval,this.uploadTimeout}return a()(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,width:p(document.body.scrollWidth,window.innerWidth),height:p(document.body.scrollHeight,window.innerHeight),pageLoadTime:x,referrer:document.referrer,events:[]};return this.batchCount+=1,t}},{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=[this.eventsCount,k.indexOf(t.type),Math.floor(t.timeStamp)/1e3];switch(t.type){case"mousemove":var n=v(t.pageX),r=v(t.pageY);e.push(n,r);break;case"touchmove":case"touchstart":case"touchend":n=v(t.changedTouches[0].pageX),r=v(t.changedTouches[0].pageY),e.push(n,r);break;case"wheel":n=v(t.pageX),r=v(t.pageY);var o=v(t.deltaX),i=v(t.deltaY);e.push(n,r,o,i);break;case"mouseup":case"mousedown":case"click":case"dblclick":case"contextmenu":n=v(t.pageX),r=v(t.pageY);var s="2"===t.buttono?"Right":"";e.push(n,r,s);break;case"resize":var a=t.target.innerWidth,u=t.target.innerHeight;e.push(a,u)}this.lastEvtInfo&&m(this.lastEvtInfo,e)||this.lastEvtInfo&&("mousemove"==k[e[1]]||"touchmove"==k[e[1]])&&this.lastEvtInfo[1]==e[1]&&m(this.lastEvtInfo.slice(3),e.slice(3))||(this.eventsList.push(e),this.lastEvtInfo=e,this.eventsCount+=1,"event-triggered"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&this._uploadData(),"mixed"==this.config.uploadMode&&this.eventsList.length%this.config.frequency==0&&(this._periodUploadTimeout(),this._uploadData()))}}},{key:"_encodeData",value:function(t){var e=JSON.stringify(t);return"base64"==this.config.encoder.toLowerCase()&&(e=I.encode(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;0<=n;n--){var r=t.charCodeAt(n);127<r&&r<=2047?e++:2047<r&&r<=65535&&(e+=2),56320<=r&&r<=57343&&n--}return e}(e)>=this.config.sizeLimit){var r=A()(t);t.events.splice(t.events.length/2),r.events.splice(0,r.events.length/2),this._binarySplitBigDataBlock(t).forEach(function(t){n.push(t)}),this._binarySplitBigDataBlock(r).forEach(function(t){n.push(t)})}else n.push(t);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),!0)}},{key:"_uploadData",value:function(){var n=this;if(!(this.config.uploadTimes&&this.batchCount>=this.config.uploadTimes+this.config.enableServerConfig)){var t=this._newDataBatch();t.events=this.eventsList,this.eventsList=[],this._binarySplitBigDataBlock(t).forEach(function(t){t.packetId=n.packetCount,n.packetCount+=1;var e=n._encodeData(t);n.uploader.upload(t,e)})}}},{key:"_periodUploadTimeout",value:function(){var t=this;clearTimeout(this.uploadTimeout),this.uploadTimeout=setTimeout(function(){(t.config.enableSendEmpty||0<t.eventsList.length)&&t._uploadData()},this.config.uploadPeriod)}},{key:"_periodUploadInterval",value:function(){var t=this;clearInterval(this.uploadInterval),this.uploadInterval=setInterval(function(){(t.config.enableSendEmpty||0<t.eventsList.length)&&t._uploadData()},this.config.uploadPeriod)}},{key:"_runCollector",value:function(){var e=this;k.forEach(function(t){e.config.scope.addEventListener(t,function(t){return e._mouseHandler(t)})}),"periodic"===this.config.uploadMode&&this._periodUploadInterval(),"mixed"===this.config.uploadMode&&this._periodUploadTimeout()}},{key:"_stopCollector",value:function(){var e=this;k.forEach(function(t){e.config.scope.removeEventListener(t,function(t){return e._mouseHandler(t)})}),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.config.build(t)?(this.sessionId=this.config.enableSession?j():"",this.uploader=new _(this.impressionId,this.sessionId,this.config),this.config.enableServerConfig&&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),e.sessionId=e.config.enableSession?j():"",e.uploader.sessionId=e.sessionId,d("Successfully update config from backend.")}).catch(function(t){d(t)}),window.onunload=function(){0!=e.eventsList.length&&e._uploadData()},{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?(P&&document.addEventListener(P,function(t){return e._onVisibilityChange(t)}),this._runCollector(),this.uploader.start(this.impressionId),d("Mouselog agent is activated!"),d("Website ID: ".concat(this.config.websiteId)),d("Session ID: ".concat(this.sessionId)),d("Impression ID: ".concat(this.impressionId)),d("User-Agent: ".concat(navigator.userAgent)),d("User ID: ".concat(y())),d("Page load time: ".concat(x))):(d(n.msg),d("Fail to initialize Mouselog agent."))}},{key:"debug",value:function(t,e){var n;h=!0,(n=e)&&(r=window.document.getElementById(n)),this.run(t)}},{key:"stop",value:function(){this.uploader.stop(),this._stopCollector(),this._clearBuffer(),d("Mouselog agent ".concat(this.impressionId," is stopped!"))}}]),t}();function O(){return new D}n.d(e,"init",function(){return O})}],o.c=r,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(n,r,function(t){return e[t]}.bind(null,r));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=7);function o(t){if(r[t])return r[t].exports;var e=r[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var n,r});

5

package.json
{
"name": "mouselog",
"version": "0.2.4",
"version": "0.2.5-beta1",
"description": "The mouse tracking agent for Mouselog.",

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

"@babel/runtime": "^7.8.4",
"base-64": "^0.1.0",
"deep-copy": "^1.4.2",
"es6-promise": "^4.2.8",
"url-join": "^4.0.1",

@@ -37,3 +39,2 @@ "uuid": "^3.3.3"

"isomorphic-fetch": "^2.2.1",
"promise-polyfill": "^8.1.3",
"rimraf": "^3.0.2",

@@ -40,0 +41,0 @@ "uglifyjs-webpack-plugin": "^2.2.0",

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

###
To achieve high compatability for IE9, you should refer to [promise-polyfill](https://github.com/taylorhakes/promise-polyfill) before refering Mouselog agent.
## Build Manually

@@ -47,0 +44,0 @@ You can also bundle Mouselog.js manually via

Sorry, the diff of this file is too big to display

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