@ohbug/browser 1.0.18 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +2 -3
  2. package/dist/index.d.ts +70 -6
  3. package/dist/index.js +674 -0
  4. package/dist/index.mjs +653 -0
  5. package/package.json +20 -21
  6. package/src/capture/action/captureClick.ts +35 -0
  7. package/src/capture/action/captureUrlChange.ts +100 -0
  8. package/src/capture/console/captureConsole.ts +45 -0
  9. package/src/capture/index.ts +64 -0
  10. package/src/capture/network/captureAjaxError.ts +81 -0
  11. package/src/capture/network/captureFetchError.ts +69 -0
  12. package/src/capture/network/captureWebSocketError.ts +51 -0
  13. package/src/capture/script/captureUncaughtError.ts +20 -0
  14. package/src/capture/script/captureUnhandledrejectionError.ts +20 -0
  15. package/src/client.ts +46 -0
  16. package/src/destroy.ts +22 -0
  17. package/src/device.ts +19 -0
  18. package/src/dispatch/index.ts +2 -0
  19. package/src/dispatch/networkDispatcher.ts +29 -0
  20. package/src/dispatch/scriptDispatcher.ts +30 -0
  21. package/src/extension.ts +12 -0
  22. package/src/handle/ajaxErrorHandler.ts +26 -0
  23. package/src/handle/fetchErrorHandler.ts +25 -0
  24. package/src/handle/index.ts +16 -0
  25. package/src/handle/resourceErrorHandler.ts +41 -0
  26. package/src/handle/uncaughtErrorHandler.ts +37 -0
  27. package/src/handle/unhandledrejectionErrorHandler.ts +21 -0
  28. package/src/handle/unknownErrorHandler.ts +18 -0
  29. package/src/handle/websocketErrorHandler.ts +23 -0
  30. package/src/index.ts +13 -0
  31. package/src/notifier.ts +42 -0
  32. package/src/version.ts +1 -0
  33. package/dist/capture/action/captureClick.d.ts +0 -3
  34. package/dist/capture/action/captureClick.d.ts.map +0 -1
  35. package/dist/capture/action/captureUrlChange.d.ts +0 -3
  36. package/dist/capture/action/captureUrlChange.d.ts.map +0 -1
  37. package/dist/capture/console/captureConsole.d.ts +0 -3
  38. package/dist/capture/console/captureConsole.d.ts.map +0 -1
  39. package/dist/capture/index.d.ts +0 -10
  40. package/dist/capture/index.d.ts.map +0 -1
  41. package/dist/capture/network/captureAjaxError.d.ts +0 -6
  42. package/dist/capture/network/captureAjaxError.d.ts.map +0 -1
  43. package/dist/capture/network/captureFetchError.d.ts +0 -6
  44. package/dist/capture/network/captureFetchError.d.ts.map +0 -1
  45. package/dist/capture/network/captureWebSocketError.d.ts +0 -5
  46. package/dist/capture/network/captureWebSocketError.d.ts.map +0 -1
  47. package/dist/capture/script/captureUncaughtError.d.ts +0 -6
  48. package/dist/capture/script/captureUncaughtError.d.ts.map +0 -1
  49. package/dist/capture/script/captureUnhandledrejectionError.d.ts +0 -6
  50. package/dist/capture/script/captureUnhandledrejectionError.d.ts.map +0 -1
  51. package/dist/client.d.ts +0 -8
  52. package/dist/client.d.ts.map +0 -1
  53. package/dist/destroy.d.ts +0 -2
  54. package/dist/destroy.d.ts.map +0 -1
  55. package/dist/device.d.ts +0 -3
  56. package/dist/device.d.ts.map +0 -1
  57. package/dist/dispatch/index.d.ts +0 -3
  58. package/dist/dispatch/index.d.ts.map +0 -1
  59. package/dist/dispatch/networkDispatcher.d.ts +0 -2
  60. package/dist/dispatch/networkDispatcher.d.ts.map +0 -1
  61. package/dist/dispatch/scriptDispatcher.d.ts +0 -2
  62. package/dist/dispatch/scriptDispatcher.d.ts.map +0 -1
  63. package/dist/extension.d.ts +0 -2
  64. package/dist/extension.d.ts.map +0 -1
  65. package/dist/handle/ajaxErrorHandler.d.ts +0 -15
  66. package/dist/handle/ajaxErrorHandler.d.ts.map +0 -1
  67. package/dist/handle/fetchErrorHandler.d.ts +0 -14
  68. package/dist/handle/fetchErrorHandler.d.ts.map +0 -1
  69. package/dist/handle/index.d.ts +0 -15
  70. package/dist/handle/index.d.ts.map +0 -1
  71. package/dist/handle/resourceErrorHandler.d.ts +0 -13
  72. package/dist/handle/resourceErrorHandler.d.ts.map +0 -1
  73. package/dist/handle/uncaughtErrorHandler.d.ts +0 -10
  74. package/dist/handle/uncaughtErrorHandler.d.ts.map +0 -1
  75. package/dist/handle/unhandledrejectionErrorHandler.d.ts +0 -6
  76. package/dist/handle/unhandledrejectionErrorHandler.d.ts.map +0 -1
  77. package/dist/handle/unknownErrorHandler.d.ts +0 -5
  78. package/dist/handle/unknownErrorHandler.d.ts.map +0 -1
  79. package/dist/handle/websocketErrorHandler.d.ts +0 -12
  80. package/dist/handle/websocketErrorHandler.d.ts.map +0 -1
  81. package/dist/index.d.ts.map +0 -1
  82. package/dist/notifier.d.ts +0 -3
  83. package/dist/notifier.d.ts.map +0 -1
  84. package/dist/ohbug-browser.es.js +0 -1530
  85. package/dist/ohbug-browser.es.min.js +0 -58
  86. package/dist/ohbug-browser.umd.js +0 -1542
  87. package/dist/ohbug-browser.umd.min.js +0 -58
  88. package/dist/types.d.ts +0 -10
  89. package/dist/types.d.ts.map +0 -1
  90. package/dist/version.d.ts +0 -2
  91. package/dist/version.d.ts.map +0 -1
@@ -1,58 +0,0 @@
1
- /*! *****************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function t(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{c(r.next(e))}catch(e){a(e)}}function u(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,u)}c((r=r.apply(e,t||[])).next())}))}function n(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function r(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e}
16
- /*! *****************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */function o(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e}function a(e){return"string"==typeof e}function i(e){return"function"==typeof e}function u(e){return"[object Object]"===Object.prototype.toString.call(e)}var c={apiKey:{defaultValue:void 0,message:"is required",validate:function(e){return Boolean(e)&&a(e)}},appVersion:{defaultValue:void 0,message:"should be a string",validate:function(e){return void 0===e||a(e)}},appType:{defaultValue:void 0,message:"should be a string",validate:function(e){return void 0===e||a(e)}},releaseStage:{defaultValue:"production",message:"should be a string",validate:function(e){return void 0===e||a(e)}},endpoint:{defaultValue:"http://localhost:6660/report",message:"should be a string",validate:function(e){return void 0===e||a(e)}},maxActions:{defaultValue:30,message:"should be a number between 0 and 100",validate:function(e){return void 0===e||function(e){return"number"==typeof e&&parseInt(""+e,10)===e}(e)&&e>=1&&e<=100}},created:{defaultValue:function(e){return e},message:"should be a function",validate:function(e){return void 0===e||i(e)}},notified:{defaultValue:function(){},message:"should be a function",validate:function(e){return void 0===e||i(e)}},logger:{defaultValue:{log:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.log.apply(console,o(["Ohbug"],e))},info:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.info.apply(console,o(["Ohbug"],e))},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.warn.apply(console,o(["Ohbug"],e))},error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.error.apply(console,o(["Ohbug"],e))}},message:"should be null or an object with methods { log, info, warn, error }",validate:function(e){return void 0===e||e&&["log","info","warn","error"].reduce((function(t,n){return t&&"function"==typeof e[n]}),!0)}},user:{defaultValue:void 0,message:"should be an object and have up to 6 attributes",validate:function(e){return void 0===e||u(e)&&Object.keys(e).length<=6}},metaData:{defaultValue:void 0,message:"should be an object",validate:function(e){return void 0===e||u(e)}}};function s(e,t){for(var n,o=[],a=2;a<arguments.length;a++)o[a-2]=arguments[a];var u=null===(n=e.init)||void 0===n?void 0:n.call.apply(n,r([e,t],o));return t._extensions.push(e),t._hooks.created=function(e,t){var n,o,a=r([t._config.created],t._extensions.filter((function(e){return i(e.created)})).map((function(e){return e.created})));return 0===a.length?function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e}(e,t):1===a.length?null===(n=a[0])||void 0===n?void 0:n.call(a,e,t):null===(o=a.reduce((function(e,n){return function(r){return n(e(r,t),t)}})))||void 0===o?void 0:o(e,t)},t._hooks.notified=function(e,t){return r([t._config.notified],t._extensions.filter((function(e){return i(e.notified)})).map((function(e){return e.notified}))).forEach((function(n){return null==n?void 0:n(e,t)}))},u||t}var l=function(e,t,n,r){this.type=n,this.timestamp=r||(new Date).toISOString(),this.message=e,this.data=t};function f(e,t){return new Error("Invalid data\n- "+e+", got "+JSON.stringify(t))}function d(e,t,n){t&&(e[t]=n)}function p(e,t){if(e[t])return e[t]}function v(e,t){if(e[t])return delete e[t]}var h=function(){function t(e,t){var n=e.apiKey,r=e.appVersion,o=e.appType,a=e.releaseStage,i=e.timestamp,u=e.category,c=e.type,s=e.sdk,l=e.detail,f=e.device,d=e.user,p=e.actions,v=e.metaData;this.apiKey=n,this.appVersion=r,this.appType=o,this.releaseStage=a,this.timestamp=i,this.category=u,this.type=c,this.sdk=s,this.detail=l,this.device=f,this.user=d,this.actions=p,this.metaData=v,this._client=t}return Object.defineProperty(t.prototype,"_isOhbugEvent",{get:function(){return!0},enumerable:!1,configurable:!0}),t.prototype.addAction=function(e,t,n,r){var o,i,u=this.actions,c=a(e)?e:"",s=t||{},f=a(n)?n:"",d=new l(c,s,f,r);u.length>=(null!==(i=null===(o=this._client)||void 0===o?void 0:o._config.maxActions)&&void 0!==i?i:30)&&u.shift(),u.push(d)},t.prototype.getUser=function(){return this.user},t.prototype.setUser=function(t){var n;if(u(t)&&Object.keys(t).length<=6)return this.user=e(e({},this.user),t),this.getUser();null===(n=this._client)||void 0===n||n._logger.warn(f("setUser should be an object and have up to 6 attributes",t))},t.prototype.addMetaData=function(e,t){return d(this.metaData,e,t)},t.prototype.getMetaData=function(e){return p(this.metaData,e)},t.prototype.deleteMetaData=function(e){return v(this.metaData,e)},t.prototype.toJSON=function(){var e=this;return{apiKey:e.apiKey,appVersion:e.appVersion,appType:e.appType,timestamp:e.timestamp,category:e.category,type:e.type,sdk:e.sdk,device:e.device,detail:e.detail,user:e.user,actions:e.actions,metaData:e.metaData,releaseStage:e.releaseStage}},t}();var g=function(){function o(e){var t=this,n=e.sdk,r=e.config,o=e.schema,a=void 0===o?c:o,i=e.device,s=e.notifier,l=function(e,t){return Object.keys(t).reduce((function(n,r){var o=e[r],a=t[r],i=a.defaultValue,u=a.message,c=a.validate;return void 0!==o?c(o)?n.config[r]=o:(n.config[r]=i,n.errors[r]=u):n.config[r]=i,n}),{config:{},errors:{}})}(r,a),f=l.config,d=l.errors;this._sdk=n,this._config=f,this._logger=f.logger,this._device=i,this._notifier=s,this._extensions=[],this._hooks={created:f.created,notified:f.notified},this._actions=[],this._user=f.user,this._metaData={},u(f.metaData)&&Object.keys(f.metaData).forEach((function(e){t.addMetaData(e,f.metaData[e])})),Object.keys(d).length&&this._logger.warn(function(e,t){return new Error("Invalid configuration\n"+Object.keys(e).map((function(n){return"- "+n+" "+e[n]+", got "+JSON.stringify(t[n])})).join("\n")+"\n ")}(d,r))}return o.prototype.use=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return s.apply(void 0,r([e,this],t))},o.prototype.createEvent=function(e){var t=function(e,t){var n,r,o,a=t._config,i=a.apiKey,c=a.appVersion,s=a.appType,l=a.releaseStage,f=(new Date).toISOString(),d=t._device(t);return u(e)&&Object.prototype.hasOwnProperty.call(e,"type")&&Object.prototype.hasOwnProperty.call(e,"detail")?(n=e.category||"error",r=e.type,o=e.detail):(n="error",r="unknownError",o=e),new h({apiKey:i,appVersion:c,appType:s,timestamp:f,category:n,type:r,sdk:t._sdk,device:d,user:t._user,detail:o,actions:t._actions,metaData:t._metaData,releaseStage:l},t)}(e,this);return i(this._hooks.created)?this._hooks.created(t,this):t},o.prototype.notify=function(e,r){var o;return o=Boolean(e)&&!function(e){return Boolean(null==e?void 0:e._isOhbugEvent)}(e)?this.createEvent(e):e,r&&(o=r(o)),function(e,r){return t(this,void 0,void 0,(function(){var t,o;return n(this,(function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),t=null,e?[4,r._notifier(e)]:[3,2];case 1:t=n.sent(),n.label=2;case 2:return i(r._hooks.notified)&&r._hooks.notified(e,r),[2,t];case 3:return o=n.sent(),r._logger.error(o),[3,4];case 4:return[2]}}))}))}(o,this)},o.prototype.addAction=function(e,t,n,r){var o=this._actions,i=a(e)?e:"",u=t||{},c=a(n)?n:"",s=new l(i,u,c,r);o.length>=this._config.maxActions&&o.shift(),o.push(s)},o.prototype.getUser=function(){return this._user},o.prototype.setUser=function(t){if(u(t)&&Object.keys(t).length<=6)return this._user=e(e({},this._user),t),this.getUser();this._logger.warn(f("setUser should be an object and have up to 6 attributes",t))},o.prototype.addMetaData=function(e,t){return d(this._metaData,e,t)},o.prototype.getMetaData=function(e){return p(this._metaData,e)},o.prototype.deleteMetaData=function(e){return v(this._metaData,e)},o}();
30
- /*! *****************************************************************************
31
- Copyright (c) Microsoft Corporation.
32
-
33
- Permission to use, copy, modify, and/or distribute this software for any
34
- purpose with or without fee is hereby granted.
35
-
36
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
37
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
39
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
40
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
41
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
42
- PERFORMANCE OF THIS SOFTWARE.
43
- ***************************************************************************** */function y(e,t){for(var n=0,r=t.length,o=e.length;n<r;n++,o++)e[o]=t[n];return e}var m=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];console.warn.apply(console,y(["Ohbug"],e))};function b(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];try{if("production"!==process.env.NODE_ENV){if(void 0===t)throw new Error("`Ohbug warning(condition, format, ...args)` requires a warning message argument");if(!e){var o=0,a=t.replace(/%s/g,(function(){return n[o++]}));m(a)}}}catch(e){}}var E={};function _(){return"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:E}function w(){var e=_();return function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(void 0===t)throw new Error("`Ohbug warning(condition, format, ...args)` requires a warning message argument");if(!e){var o=0,a=t.replace(/%s/g,(function(){return n[o++]}));throw new Error("Ohbug "+a)}}(Boolean(e.__OHBUG__),"Failed to get `OhbugObject`, please confirm if `Ohbug.init`"),e.__OHBUG__}function O(e,t,n){if(t in e){var r=e[t],o=n(r);return e[t]=o,r}}function k(e){if("string"!=typeof e)return{};var t=e.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};var n=t[6]||"",r=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],relative:t[5]+n+r}}function S(e,t){e.parentNode&&(t.push(e.parentNode),S(e.parentNode,t))}function j(e){var t=[];return t.push(e),S(e,t),t}var R,T,D,L=function(e){for(var t=e.target||e.srcElement,n=e.target||e.srcElement,r=[],o=0;n&&n.nodeType===Node.ELEMENT_NODE&&n.nodeType!==Node.DOCUMENT_TYPE_NODE;n=n.previousSibling)o&&r.push(n),o+=1;var a=void 0===e.path?j(e.target):e.path,i=t.outerHTML;return a.reverse().map((function(e){return(e.localName||"")+(e.id?"#"+e.id:"")+(e.className?"."+e.className:"")+(e.outerHTML===i?":nth-child("+r.length+")":"")})).filter((function(e){return Boolean(e)})).join(" > ")},N=function(){var e={};if(navigator){var t=navigator.language,n=navigator.userAgent;e.language=t,e.userAgent=n}if(document){var r=document.title;e.title=r}if(window.location){var o=window.location.href;e.url=o}return e},x=_();function M(e,t){var n,r=w().client,o=k(null===(n=null==x?void 0:x.location)||void 0===n?void 0:n.href),a=k(e),i=k(t);a.path||(a=o),D=t;var u=e,c=t;o.protocol===i.protocol&&o.host===i.host&&(c=i.relative),o.protocol===a.protocol&&o.host===a.host&&(u=a.relative),u!==c&&r.addAction("navigation to "+t,{from:e,to:t},"navigation")}function H(e){return function(t,n,r){return r&&M(D,String(r)),e.apply(this,[t,n,r])}}var A={pushState:null===(R=null==x?void 0:x.history)||void 0===R?void 0:R.pushState,replaceState:null===(T=null==x?void 0:x.history)||void 0===T?void 0:T.replaceState,onpopstate:null==x?void 0:x.onpopstate};function V(e){var t=e;M(t.oldURL,t.newURL)}function U(){var e;A.pushState=O(null==x?void 0:x.history,"pushState",H),A.replaceState=O(null==x?void 0:x.history,"replaceState",H),A.onpopstate=O(x,"onpopstate",(function(e){return function(){for(var t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=null===(t=null==x?void 0:x.location)||void 0===t?void 0:t.href;return M(D,o),e.apply(this,n)}})),null===(e=null==x?void 0:x.addEventListener)||void 0===e||e.call(x,"hashchange",V,!0)}var q=_();function B(e){if(e.target){var t=w().client,n=e.target,r=n.tagName,o=n.id,a=n.className,i=n.name,u=n.src,c=n.outerHTML,s=n.nodeType,l=L(e);t.addAction("click node",{tagName:r,id:o,className:a,name:i,src:u,outerHTML:c,nodeType:s,selector:l},"click")}}
44
- /*! *****************************************************************************
45
- Copyright (c) Microsoft Corporation.
46
-
47
- Permission to use, copy, modify, and/or distribute this software for any
48
- purpose with or without fee is hereby granted.
49
-
50
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
51
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
52
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
53
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
54
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
55
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
56
- PERFORMANCE OF THIS SOFTWARE.
57
- ***************************************************************************** */
58
- var X=function(){return(X=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},F=["log","info","warn","error"],P=Object.keys(F).reduce((function(e,t){var n;return X(X({},e),((n={})[t]=console[t],n))}),{log:null,info:null,warn:null,error:null});var W=Object.freeze({__proto__:null,UNCAUGHT_ERROR:"uncaughtError",RESOURCE_ERROR:"resourceError",UNHANDLEDREJECTION_ERROR:"unhandledrejectionError",AJAX_ERROR:"ajaxError",FETCH_ERROR:"fetchError",WEBSOCKET_ERROR:"websocketError",UNKNOWN_ERROR:"unknownError",MESSAGE:"message",VIEW:"view"});function K(e){var t=e.message?e:{message:e},n=w().client,r=n.createEvent({category:"error",type:"unknownError",detail:t});n.notify(r)}function C(e){try{var t=e.type;if("error"===t){var n=e,r=n.message,o=n.error,a=e.target||e.srcElement;r&&o?function(e){var t=e.message,n=e.filename,r=e.lineno,o=e.colno,a=e.error,i=a.stack,u={name:a.name,message:t,filename:n,lineno:r,colno:o,stack:i},c=w().client,s=c.createEvent({category:"error",type:"uncaughtError",detail:u});c.notify(s)}(n):a&&function(e){var t=e.target||e.srcElement,n=t.outerHTML,r=L(e),o={outerHTML:n,src:t&&t.src,tagName:t&&t.tagName,id:t&&t.id,className:t&&t.className,name:t&&t.name,nodeType:t&&t.nodeType,selector:r},a=w().client,i=a.createEvent({category:"error",type:"resourceError",detail:o});a.notify(i)}(n)}else"unhandledrejection"===t?function(e){var t={message:e.reason.message||e.reason,stack:e.reason.stack},n=w().client,r=n.createEvent({category:"error",type:"unhandledrejectionError",detail:t});n.notify(r)}(e):K(e)}catch(o){K(o)}}function I(e,t){try{switch(e){case"ajaxError":!function(e){var t=w().client,n=t.createEvent({category:"error",type:"ajaxError",detail:e});t.notify(n)}(t);break;case"fetchError":!function(e){var t=w().client,n=t.createEvent({category:"error",type:"fetchError",detail:e});t.notify(n)}(t);break;case"websocketError":!function(e){var t=w().client,n=t.createEvent({category:"error",type:"websocketError",detail:e});t.notify(n)}(t)}}catch(e){K(e)}}var J=_(),G="XMLHttpRequest"in J,z=G?{open:XMLHttpRequest.prototype.open,send:XMLHttpRequest.prototype.send}:{};var Y=_(),$="fetch"in Y,Q=$?Y.fetch:null;var Z=_();var ee=_();function te(e){C(e)}var ne=_();function re(e){C(e)}function oe(){U(),function(){var e,t;null===(t=null===(e=null==q?void 0:q.document)||void 0===e?void 0:e.addEventListener)||void 0===t||t.call(e,"click",B)}()}function ae(){!function(){var e;x.history.pushState=A.pushState,x.history.replaceState=A.replaceState,x.onpopstate=A.onpopstate,null===(e=null==x?void 0:x.removeEventListener)||void 0===e||e.call(x,"hashchange",V,!0)}(),function(){var e,t;null===(t=null===(e=null==q?void 0:q.document)||void 0===e?void 0:e.removeEventListener)||void 0===t||t.call(e,"click",B)}()}function ie(){!function(){if(b(G,"Binding `AJAX` monitoring failed, the current environment did not find the object `XMLHttpRequest`"),G){var e=w().client,t={method:"",url:""},n=null===XMLHttpRequest||void 0===XMLHttpRequest?void 0:XMLHttpRequest.prototype;z.open=O(n,"open",(function(e){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=n[0],a=n[1];return t.method=o,t.url=a,e.apply(this,n)}})),z.send=O(n,"send",(function(n){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];return this.addEventListener("readystatechange",(function(){if(4===this.readyState&&t.url!==e._config.endpoint){var n={req:{url:t.url,method:t.method,data:r[0]||{}},res:{status:this.status,statusText:this.statusText,response:this.response}};e.addAction("ajax",n,"ajax"),(!this.status||this.status>=400)&&I("ajaxError",n)}})),n.apply(this,r)}}))}}(),function(){if(b($,"Binding `fetch` monitoring failed, the current environment did not find the object `fetch`"),$){var e=w().client;Q=O(Y,"fetch",(function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return t.apply(this,n).then((function(t){var r=n[0],o=n[1],a={req:{url:r,method:o&&o.method,data:o&&o.body||{}},res:{status:t.status,statusText:t.statusText}};return e.addAction("fetch",a,"fetch"),(!t.status||t.status>=400)&&I("fetchError",a),t})).catch((function(e){I("fetchError",e)}))}}))}}(),function(){if(b("WebSocket"in Z,"Binding `WebSocket` monitoring failed, the current environment did not find the object `WebSocket`"),"WebSocket"in Z){var e=null===WebSocket||void 0===WebSocket?void 0:WebSocket.prototype,t=Object.getOwnPropertyDescriptor(e,"onerror");Object.defineProperty(e,"onerror",{set:function(){var e,n=arguments[0];null===(e=null==t?void 0:t.set)||void 0===e||e.call(this,(function(e){var t=e.target,r=t.url,o=t.readyState,a=t.protocol,i=t.extensions,u=t.binaryType,c=t.bufferedAmount;I("websocketError",{url:r,timeStamp:e.timeStamp,readyState:o,protocol:a,extensions:i,binaryType:u,bufferedAmount:c}),n.apply(this,arguments)}))}})}}()}function ue(){!function(){if(G&&z.open&&z.send){var e=null===XMLHttpRequest||void 0===XMLHttpRequest?void 0:XMLHttpRequest.prototype;e.open=z.open,e.send=z.send}}(),$&&Q&&(Y.fetch=Q)}function ce(){var e=_();b(Boolean(e.addEventListener),"Binding script monitoring failed, the current environment did not find the object `addEventListener`"),e.addEventListener&&(function(){var e;null===(e=null==ee?void 0:ee.addEventListener)||void 0===e||e.call(ee,"error",te,!0)}(),function(){var e;null===(e=null==ne?void 0:ne.addEventListener)||void 0===e||e.call(ne,"unhandledrejection",re,!0)}())}function se(){!function(){var e;null===(e=null==ee?void 0:ee.removeEventListener)||void 0===e||e.call(ee,"error",te,!0)}(),function(){var e;null===(e=null==ne?void 0:ne.removeEventListener)||void 0===e||e.call(ne,"unhandledrejection",re,!0)}()}function le(){var e;ce(),ie(),oe(),e=w().client,F.forEach((function(t){P[t]=O(console,t,(function(n){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];return r.some((function(e){return"string"==typeof e&&e.includes("Ohbug")}))||e.addAction("console."+t,r,"console"),n.apply(this,r)}}))}))}var fe=_();function de(){var e;null===(e=null==fe?void 0:fe.addEventListener)||void 0===e||e.call(fe,"unload",(function(){se(),ue(),ae(),console&&F.forEach((function(e){console[e]=P[e]}))}),!0)}var pe={name:"OhbugBrowser",init:function(){le(),de()}};function ve(e){var t=w().client._config.endpoint;return new Promise((function(n,r){var o=JSON.stringify(e);if(navigator.sendBeacon){var a=navigator.sendBeacon(t,o);n(a)}else{var i=new XMLHttpRequest;i.onreadystatechange=function(){if(i.readyState===XMLHttpRequest.DONE){if(i.status>=200&&i.status<300)return n(i.response);r(i)}},i.open("POST",t),i.setRequestHeader("Content-Type","application/json;charset=UTF-8"),i.send(o)}}))}var he={_client:null,init:function(e){var t;return he._client?(null===(t=he._client._logger)||void 0===t||t.log("init() has been called. Ignored."),he._client):(he._client=function(e){var t=_(),n=new g({sdk:{platform:"ohbug-browser",version:"1.0.18"},config:e,device:N,notifier:ve});return t.__OHBUG__={client:n},n.use(pe),console.log("%c @ohbug/browser %c Detected Ohbug v1.0.18 %c","background:#333; padding: 2px 1px; color: #FFF","background:#FF6F61; padding: 2px 1px; color: #FFF","background:transparent"),n}(e),he._client)}};export{he as Client,he as default,W as types};