posthog-js
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
!function(){"use strict";function e(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),r.push.apply(r,t)}return r}function n(n){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?e(Object(o),!0).forEach((function(e){t(n,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))}))}return n}function r(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}function t(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function o(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==r)return;var t,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(t=r.next()).done)&&(i.push(t.value),!n||i.length!==n);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}(e,n)||i(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,n){if(e){if("string"==typeof e)return a(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,n):void 0}}function a(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function c(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=i(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0,o=function(){};return{s:o,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){l=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(l)throw a}}}}var l="undefined"!=typeof window?window:void 0,u="undefined"!=typeof globalThis?globalThis:l,s=null==u?void 0:u.navigator;null==u||u.document,null==u||u.location,null==u||u.fetch,null!=u&&u.XMLHttpRequest&&"withCredentials"in new u.XMLHttpRequest&&u.XMLHttpRequest,null==u||u.AbortController,null==s||s.userAgent;var f=null!=l?l:{},p=Array.isArray,d=Object.prototype.toString,v=p||function(e){return"[object Array]"===d.call(e)},g=function(e){return"function"==typeof e},h=function(e){return e===Object(e)&&!v(e)},y=function(e){return void 0===e},_=function(e){return"[object String]"==d.call(e)},b=function(e){return null===e},x=function(e){return"[object Number]"==d.call(e)};function O(e){return!y(Event)&&E(e,Event)}function E(e,n){try{return e instanceof n}catch(e){return!1}}function m(e){return b(e)||!h(e)&&!g(e)}function j(e,n){return Object.prototype.toString.call(e)==="[object ".concat(n,"]")}function w(e){return j(e,"DOMError")}var $=/\(error: (.*)\)/,S=50,T="?";function H(e,n,r,t){var o={filename:e,function:n,in_app:!0};return y(r)||(o.lineno=r),y(t)||(o.colno=t),o}var R=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,P=/\((\S*)(?::(\d+))(?::(\d+))\)/,A=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,D=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,k=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;var U=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var o=r.sort((function(e,n){return e[0]-n[0]})).map((function(e){return e[1]}));return function(e){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=[],i=e.split("\n"),a=r;a<i.length;a++){var l=i[a];if(!(l.length>1024)){var u=$.test(l)?l.replace($,"$1"):l;if(!u.match(/\S*Error: /)){var s,f=c(o);try{for(f.s();!(s=f.n()).done;){var p=(0,s.value)(u);if(p){t.push(p);break}}}catch(e){f.e(e)}finally{f.f()}if(t.length>=S)break}}}return function(e){if(!e.length)return[];var r=e.slice(0,S);return r.reverse(),r.map((function(e){return n(n({},e),{},{filename:e.filename||r[r.length-1].filename,function:e.function||"?"})}))}(t)}}.apply(void 0,[[30,function(e){var n=R.exec(e);if(n){if(n[2]&&0===n[2].indexOf("eval")){var r=P.exec(n[2]);r&&(n[2]=r[1],n[3]=r[2],n[4]=r[3])}var t=o(M(n[1]||T,n[2]),2),i=t[0];return H(t[1],i,n[3]?+n[3]:void 0,n[4]?+n[4]:void 0)}}],[50,function(e){var n=A.exec(e);if(n){if(n[3]&&n[3].indexOf(" > eval")>-1){var r=D.exec(n[3]);r&&(n[1]=n[1]||"eval",n[3]=r[1],n[4]=r[2],n[5]="")}var t=n[3],i=n[1]||T,a=o(M(i,t),2);return i=a[0],H(t=a[1],i,n[4]?+n[4]:void 0,n[5]?+n[5]:void 0)}}],[40,function(e){var n=k.exec(e);return n?H(n[2],n[1]||T,+n[3],n[4]?+n[4]:void 0):void 0}]]),M=function(e,n){var r=-1!==e.indexOf("safari-extension"),t=-1!==e.indexOf("safari-web-extension");return r||t?[-1!==e.indexOf("@")?e.split("@")[0]:T,r?"safari-extension:".concat(n):"safari-web-extension:".concat(n)]:[e,n]},I=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i,N=/Minified React error #\d+;/i;function C(e){var n=e.stacktrace||e.stack||"",r=function(e){if(e){if(x(e.framesToPop))return e.framesToPop;if(N.test(e.message))return 1}return 0}(e);try{return U(n,r)}catch(e){}return[]}function G(e){var n=C(e);return{$exception_type:e.name,$exception_message:e.message,$exception_stack_trace_raw:JSON.stringify(n)}}function z(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:40,r=Object.keys(e);if(r.sort(),!r.length)return"[object has no keys]";for(var t=r.length;t>0;t--){var o=r.slice(0,t).join(", ");if(!(o.length>n))return t===r.length||o.length<=n?o:"".concat(o.slice(0,n),"...")}return""}function q(e){var r=o(e,5),t=r[0],i=r[1],a=r[2],c=r[3],l=r[4],u={};if(y(l)&&_(t)){var s="Error",f=t,p=t.match(I);p&&(s=p[1],f=p[2]),u={$exception_type:s,$exception_message:f}}var d=l||t;if(w(d)||function(e){return j(e,"DOMException")}(d)){var v=d;if(function(e){return"stack"in e}(d))u=G(d);else{var g=v.name||(w(v)?"DOMError":"DOMException"),h=v.message?"".concat(g,": ").concat(v.message):g;u=function(e){return{$exception_type:"Error",$exception_message:e}}(h),u.$exception_type=w(v)?"DOMError":"DOMException",u.$exception_message=u.$exception_message||h}"code"in v&&(u.$exception_DOMException_code="".concat(v.code))}else if(function(e){return j(e,"ErrorEvent")}(d)&&d.error)u=G(d.error);else if(function(e){switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return E(e,Error)}}(d))u=G(d);else if(function(e){return j(e,"Object")}(d)||O(d)){u=function(e){return{$exception_type:O(e)?e.constructor.name:"Error",$exception_message:"Non-Error ".concat("exception"," captured with keys: ",z(e))}}(d),u.$exception_is_synthetic=!0}else u.$exception_type=u.$exception_type||"Error",u.$exception_message=u.$exception_message||d,u.$exception_is_synthetic=!0;return n(n(n(n({},u),{},{$exception_type:u.$exception_type||"UnknownErrorType",$exception_message:u.$exception_message||""},i?{$exception_source:i}:{}),a?{$exception_lineno:a}:{}),c?{$exception_colno:c}:{})}var L="[PostHog.js]",X={_log:function(e){if(l&&f.POSTHOG_DEBUG&&!y(l.console)&&l.console){for(var n=("__rrweb_original__"in l.console[e]?l.console[e].__rrweb_original__:l.console[e]),r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];n.apply(void 0,[L].concat(t))}},info:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];X._log.apply(X,["log"].concat(n))},warn:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];X._log.apply(X,["warn"].concat(n))},error:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];X._log.apply(X,["error"].concat(n))},critical:function(){for(var e,n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];(e=console).error.apply(e,[L].concat(r))},uninitializedWarning:function(e){X.error("You must initialize PostHog before calling ".concat(e))}},W=function(e,n){var r=new B(e);return r.afterDecideResponse(n),r},B=function(){function e(n){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),t(this,"originalOnErrorHandler",void 0),t(this,"originalOnUnhandledRejectionHandler",void 0),t(this,"errorsToIgnore",[]),this.instance=n}var i,a,c;return i=e,a=[{key:"startCapturing",value:function(){var e;if(l&&this.isEnabled()&&(null===(e=l.onerror)||void 0===e||!e.__POSTHOG_INSTRUMENTED__))try{this.originalOnErrorHandler=l.onerror,l.onerror=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return this.captureException(n),!!this.originalOnErrorHandler&&this.originalOnErrorHandler.apply(this,n)}.bind(this),l.onerror.__POSTHOG_INSTRUMENTED__=!0,this.originalOnUnhandledRejectionHandler=l.onunhandledrejection,l.onunhandledrejection=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var i=function(e){var r=o(e,1)[0],t=r;try{"reason"in r?t=r.reason:"detail"in r&&"reason"in r.detail&&(t=r.detail.reason)}catch(e){}var i={};return(i=m(t)?{$exception_message:"Non-Error promise rejection captured with value: ".concat(String(t))}:q([t])).$exception_handled=!1,n(n({},i),{},{$exception_type:i.$exception_type="UnhandledRejection",$exception_message:i.$exception_message=i.$exception_message||r.reason||String(t)})}(r);return this.sendExceptionEvent(i),!l||!this.originalOnUnhandledRejectionHandler||this.originalOnUnhandledRejectionHandler.apply(l,r)}.bind(this),l.onunhandledrejection.__POSTHOG_INSTRUMENTED__=!0}catch(e){X.error("PostHog failed to start exception autocapture",e),this.stopCapturing()}}},{key:"stopCapturing",value:function(){var e,n;l&&(y(this.originalOnErrorHandler)||(l.onerror=this.originalOnErrorHandler,this.originalOnErrorHandler=null),null===(e=l.onerror)||void 0===e||delete e.__POSTHOG_INSTRUMENTED__,y(this.originalOnUnhandledRejectionHandler)||(l.onunhandledrejection=this.originalOnUnhandledRejectionHandler,this.originalOnUnhandledRejectionHandler=null),null===(n=l.onunhandledrejection)||void 0===n||delete n.__POSTHOG_INSTRUMENTED__)}},{key:"isCapturing",value:function(){var e;return!(null==l||null===(e=l.onerror)||void 0===e||!e.__POSTHOG_INSTRUMENTED__)}},{key:"isEnabled",value:function(){var e;return null!==(e=this.remoteEnabled)&&void 0!==e&&e}},{key:"afterDecideResponse",value:function(e){var n=e.autocaptureExceptions;if(this.remoteEnabled=!!n||!1,!m(n)&&"errors_to_ignore"in n&&v(n.errors_to_ignore)){var r=n.errors_to_ignore;this.errorsToIgnore=r.map((function(e){return new RegExp(e)}))}this.isEnabled()&&(this.startCapturing(),X.info("[Exception Capture] Remote config for exception autocapture is enabled, starting with config: ",h(n)?n:{}))}},{key:"captureException",value:function(e,r){var t=q(e);if(this.errorsToIgnore.some((function(e){return e.test(t.$exception_message||"")})))X.info("[Exception Capture] Ignoring exception based on remote config",t);else{var o=n(n({},r),t),i=this.instance.requestRouter.endpointFor("ui");t.$exception_personURL="".concat(i,"/project/").concat(this.instance.config.token,"/person/").concat(this.instance.get_distinct_id()),this.sendExceptionEvent(o)}}},{key:"sendExceptionEvent",value:function(e){this.instance.capture("$exception",e,{_noTruncate:!0,_batchKey:"exceptionEvent",_noHeatmaps:!0})}}],a&&r(i.prototype,a),c&&r(i,c),Object.defineProperty(i,"prototype",{writable:!1}),e}();l.extendPostHogWithExceptionAutoCapture=W}(); | ||
!function(){"use strict";function e(e,n){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n&&(t=t.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),r.push.apply(r,t)}return r}function n(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?e(Object(o),!0).forEach((function(e){r(n,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))}))}return n}function r(e,n,r){return n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function t(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==r)return;var t,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(t=r.next()).done)&&(i.push(t.value),!n||i.length!==n);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}(e,n)||o(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,n){if(e){if("string"==typeof e)return i(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,n):void 0}}function i(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function a(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=o(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0,i=function(){};return{s:i,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,c=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return c=e.done,e},e:function(e){l=!0,a=e},f:function(){try{c||null==r.return||r.return()}finally{if(l)throw a}}}}var c=Array.isArray,l=Object.prototype.toString,u=c||function(e){return"[object Array]"===l.call(e)},f=function(e){return"function"==typeof e},s=function(e){return e===Object(e)&&!u(e)},p=function(e){return void 0===e},v=function(e){return"[object String]"==l.call(e)},d=function(e){return v(e)&&0===e.trim().length},y=function(e){return null===e},g=function(e){return"[object Number]"==l.call(e)};function _(e){return!p(Event)&&h(e,Event)}function h(e,n){try{return e instanceof n}catch(e){return!1}}function b(e,n){return Object.prototype.toString.call(e)==="[object ".concat(n,"]")}function x(e){return b(e,"DOMError")}var m=/\(error: (.*)\)/,O=50,w="?";function $(e,n,r,t){var o={filename:e,function:n,in_app:!0};return p(r)||(o.lineno=r),p(t)||(o.colno=t),o}var j=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,E=/\((\S*)(?::(\d+))(?::(\d+))\)/,S=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,A=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,T=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;var P,D=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var o=r.sort((function(e,n){return e[0]-n[0]})).map((function(e){return e[1]}));return function(e){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=[],i=e.split("\n"),c=r;c<i.length;c++){var l=i[c];if(!(l.length>1024)){var u=m.test(l)?l.replace(m,"$1"):l;if(!u.match(/\S*Error: /)){var f,s=a(o);try{for(s.s();!(f=s.n()).done;){var p=(0,f.value)(u);if(p){t.push(p);break}}}catch(e){s.e(e)}finally{s.f()}if(t.length>=O)break}}}return function(e){if(!e.length)return[];var r=e.slice(0,O);return r.reverse(),r.map((function(e){return n(n({},e),{},{filename:e.filename||r[r.length-1].filename,function:e.function||"?"})}))}(t)}}.apply(void 0,[[30,function(e){var n=j.exec(e);if(n){if(n[2]&&0===n[2].indexOf("eval")){var r=E.exec(n[2]);r&&(n[2]=r[1],n[3]=r[2],n[4]=r[3])}var o=t(M(n[1]||w,n[2]),2),i=o[0];return $(o[1],i,n[3]?+n[3]:void 0,n[4]?+n[4]:void 0)}}],[50,function(e){var n=S.exec(e);if(n){if(n[3]&&n[3].indexOf(" > eval")>-1){var r=A.exec(n[3]);r&&(n[1]=n[1]||"eval",n[3]=r[1],n[4]=r[2],n[5]="")}var o=n[3],i=n[1]||w,a=t(M(i,o),2);return i=a[0],$(o=a[1],i,n[4]?+n[4]:void 0,n[5]?+n[5]:void 0)}}],[40,function(e){var n=T.exec(e);return n?$(n[2],n[1]||w,+n[3],n[4]?+n[4]:void 0):void 0}]]),M=function(e,n){var r=-1!==e.indexOf("safari-extension"),t=-1!==e.indexOf("safari-web-extension");return r||t?[-1!==e.indexOf("@")?e.split("@")[0]:w,r?"safari-extension:".concat(n):"safari-web-extension:".concat(n)]:[e,n]};!function(e){e.GZipJS="gzip-js",e.Base64="base64"}(P||(P={}));var R=["fatal","error","warning","log","info","debug"],N=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i,U=/Minified React error #\d+;/i;function k(e){var n=e.stacktrace||e.stack||"",r=function(e){if(e){if(g(e.framesToPop))return e.framesToPop;if(U.test(e.message))return 1}return 0}(e);try{return D(n,r)}catch(e){}return[]}function I(e){var n=k(e);return{$exception_type:e.name,$exception_message:e.message,$exception_stack_trace_raw:JSON.stringify(n),$exception_level:"error"}}function H(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:40,r=Object.keys(e);if(r.sort(),!r.length)return"[object has no keys]";for(var t=r.length;t>0;t--){var o=r.slice(0,t).join(", ");if(!(o.length>n))return t===r.length||o.length<=n?o:"".concat(o.slice(0,n),"...")}return""}function G(e){return v(e)&&!d(e)&&R.indexOf(e)>=0}function z(e){var r=t(e,5),o=r[0],i=r[1],a=r[2],c=r[3],l=r[4],u={};if(p(l)&&v(o)){var f="Error",s=o,d=o.match(N);d&&(f=d[1],s=d[2]),u={$exception_type:f,$exception_message:s}}var y=l||o;if(x(y)||function(e){return b(e,"DOMException")}(y)){var g=y;if(function(e){return"stack"in e}(y))u=I(y);else{var m=g.name||(x(g)?"DOMError":"DOMException"),O=g.message?"".concat(m,": ").concat(g.message):m;u=function(e){return{$exception_type:"Error",$exception_message:e,$exception_level:"error"}}(O),u.$exception_type=x(g)?"DOMError":"DOMException",u.$exception_message=u.$exception_message||O}"code"in g&&(u.$exception_DOMException_code="".concat(g.code))}else if(function(e){return b(e,"ErrorEvent")}(y)&&y.error)u=I(y.error);else if(function(e){switch(Object.prototype.toString.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return h(e,Error)}}(y))u=I(y);else if(function(e){return b(e,"Object")}(y)||_(y)){u=function(e){return{$exception_type:_(e)?e.constructor.name:"Error",$exception_message:"Non-Error ".concat("exception"," captured with keys: ",H(e)),$exception_level:G(e.level)?e.level:"error"}}(y),u.$exception_is_synthetic=!0}else u.$exception_type=u.$exception_type||"Error",u.$exception_message=u.$exception_message||y,u.$exception_is_synthetic=!0;return n(n(n(n({},u),{},{$exception_type:u.$exception_type||"UnknownErrorType",$exception_message:u.$exception_message||"",$exception_level:G(u.$exception_level)?u.$exception_level:"error"},i?{$exception_source:i}:{}),a?{$exception_lineno:a}:{}),c?{$exception_colno:c}:{})}function q(e){var r=t(e,1)[0],o=r;try{"reason"in r?o=r.reason:"detail"in r&&"reason"in r.detail&&(o=r.detail.reason)}catch(e){}var i,a={};return(a=y(i=o)||!s(i)&&!f(i)?{$exception_message:"Non-Error promise rejection captured with value: ".concat(String(o))}:z([o])).$exception_handled=!1,n(n({},a),{},{$exception_type:a.$exception_type="UnhandledRejection",$exception_message:a.$exception_message=a.$exception_message||r.reason||String(o),$exception_level:G(a.$exception_level)?a.$exception_level:"error"})}var C="undefined"!=typeof window?window:void 0,L="undefined"!=typeof globalThis?globalThis:C,X=null==L?void 0:L.navigator;null==L||L.document,null==L||L.location,null==L||L.fetch,null!=L&&L.XMLHttpRequest&&"withCredentials"in new L.XMLHttpRequest&&L.XMLHttpRequest,null==L||L.AbortController,null==X||X.userAgent;var B=null!=C?C:{},J="[PostHog.js]",W={_log:function(e){if(C&&B.POSTHOG_DEBUG&&!p(C.console)&&C.console){for(var n=("__rrweb_original__"in C.console[e]?C.console[e].__rrweb_original__:C.console[e]),r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];n.apply(void 0,[J].concat(t))}},info:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];W._log.apply(W,["log"].concat(n))},warn:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];W._log.apply(W,["warn"].concat(n))},error:function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];W._log.apply(W,["error"].concat(n))},critical:function(){for(var e,n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];(e=console).error.apply(e,[J].concat(r))},uninitializedWarning:function(e){W.error("You must initialize PostHog before calling ".concat(e))}},F={wrapOnError:function(e){var n=C;n||W.info("window not available, cannot wrap onerror");var r=n.onerror;return n.onerror=function(){for(var n,t=arguments.length,o=new Array(t),i=0;i<t;i++)o[i]=arguments[i];var a=z(o);return e(a),null!==(n=null==r?void 0:r.apply(void 0,o))&&void 0!==n&&n},n.onerror.__POSTHOG_INSTRUMENTED__=!0,function(){var e;null===(e=n.onerror)||void 0===e||delete e.__POSTHOG_INSTRUMENTED__,n.onerror=r}},wrapUnhandledRejection:function(e){var n=C;n||W.info("window not available, cannot wrap onUnhandledRejection");var r=n.onunhandledrejection;return n.onunhandledrejection=function(){for(var t,o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];var c=q(i);return e(c),null!==(t=null==r?void 0:r.apply(n,i))&&void 0!==t&&t},n.onunhandledrejection.__POSTHOG_INSTRUMENTED__=!0,function(){var e;null===(e=n.onunhandledrejection)||void 0===e||delete e.__POSTHOG_INSTRUMENTED__,n.onunhandledrejection=r}}};C.posthogErrorWrappingFunctions=F}(); | ||
//# sourceMappingURL=exception-autocapture.js.map |
@@ -8,2 +8,5 @@ export declare const PEOPLE_DISTINCT_ID_KEY = "$people_distinct_id"; | ||
export declare const HEATMAPS_ENABLED_SERVER_SIDE = "$heatmaps_enabled_server_side"; | ||
export declare const EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE = "$exception_capture_enabled_server_side"; | ||
export declare const EXCEPTION_CAPTURE_ENDPOINT = "$exception_capture_endpoint"; | ||
export declare const WEB_VITALS_ENABLED_SERVER_SIDE = "$web_vitals_enabled_server_side"; | ||
export declare const SESSION_RECORDING_ENABLED_SERVER_SIDE = "$session_recording_enabled_server_side"; | ||
@@ -10,0 +13,0 @@ export declare const CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = "$console_log_recording_enabled_server_side"; |
import { PostHog } from './posthog-core'; | ||
import { DecideResponse } from './types'; | ||
export declare class Decide { | ||
instance: PostHog; | ||
private readonly instance; | ||
constructor(instance: PostHog); | ||
@@ -6,0 +6,0 @@ call(): void; |
import { StackFrame } from './stack-trace'; | ||
export type ErrorEventArgs = [ | ||
event: string | Event, | ||
source?: string | undefined, | ||
lineno?: number | undefined, | ||
colno?: number | undefined, | ||
error?: Error | undefined | ||
]; | ||
export interface ErrorProperties { | ||
$exception_type: string; | ||
$exception_message: string; | ||
$exception_source?: string; | ||
$exception_lineno?: number; | ||
$exception_colno?: number; | ||
$exception_DOMException_code?: string; | ||
$exception_is_synthetic?: boolean; | ||
$exception_stack_trace_raw?: string; | ||
$exception_handled?: boolean; | ||
$exception_personURL?: string; | ||
} | ||
import { ErrorEventArgs, ErrorProperties } from '../../types'; | ||
export declare function parseStackFrames(ex: Error & { | ||
@@ -22,0 +4,0 @@ framesToPop?: number; |
import { PostHog } from '../../posthog-core'; | ||
import { DecideResponse, Properties } from '../../types'; | ||
import { ErrorEventArgs } from './error-conversion'; | ||
export declare const extendPostHog: (instance: PostHog, response: DecideResponse) => ExceptionObserver; | ||
export declare class ExceptionObserver { | ||
private _endpoint; | ||
instance: PostHog; | ||
remoteEnabled: boolean | undefined; | ||
private originalOnErrorHandler; | ||
private originalOnUnhandledRejectionHandler; | ||
private errorsToIgnore; | ||
private unwrapOnError; | ||
private unwrapUnhandledRejection; | ||
constructor(instance: PostHog); | ||
startCapturing(): void; | ||
stopCapturing(): void; | ||
isCapturing(): boolean; | ||
isEnabled(): boolean; | ||
get isEnabled(): boolean; | ||
get isCapturing(): boolean; | ||
get hasHandlers(): ((this: WindowEventHandlers, ev: PromiseRejectionEvent) => any) | undefined; | ||
startIfEnabled(): void; | ||
private loadScript; | ||
private startCapturing; | ||
private stopCapturing; | ||
afterDecideResponse(response: DecideResponse): void; | ||
captureException(args: ErrorEventArgs, properties?: Properties): void; | ||
captureException(errorProperties: Properties): void; | ||
/** | ||
@@ -19,0 +21,0 @@ * :TRICKY: Make sure we batch these requests |
@@ -19,2 +19,3 @@ /** | ||
import { PostHog } from '../posthog-core'; | ||
import { SeverityLevel } from '../types'; | ||
type _SentryEvent = any; | ||
@@ -31,4 +32,2 @@ type _SentryEventProcessor = any; | ||
} | ||
declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; | ||
declare type _SeverityLevel = typeof severityLevels[number]; | ||
export type SentryIntegrationOptions = { | ||
@@ -45,3 +44,3 @@ organization?: string; | ||
*/ | ||
severityAllowList?: _SeverityLevel[] | '*'; | ||
severityAllowList?: SeverityLevel[] | '*'; | ||
}; | ||
@@ -61,4 +60,4 @@ export declare function createEventProcessor(_posthog: PostHog, { organization, projectId, prefix, severityAllowList }?: SentryIntegrationOptions): (event: _SentryEvent) => _SentryEvent; | ||
*/ | ||
severityAllowList?: _SeverityLevel[] | '*'); | ||
severityAllowList?: SeverityLevel[] | '*'); | ||
} | ||
export {}; |
@@ -1,2 +0,6 @@ | ||
import { extendPostHog } from './extensions/exception-autocapture'; | ||
export default extendPostHog; | ||
import { Properties } from './types'; | ||
declare const posthogErrorWrappingFunctions: { | ||
wrapOnError: (captureFn: (props: Properties) => void) => () => void; | ||
wrapUnhandledRejection: (captureFn: (props: Properties) => void) => () => void; | ||
}; | ||
export default posthogErrorWrappingFunctions; |
@@ -20,2 +20,4 @@ import { PostHogFeatureFlags } from './posthog-featureflags'; | ||
import { ConsentManager } from './consent'; | ||
import { ExceptionObserver } from './extensions/exception-autocapture'; | ||
import { WebVitalsAutocapture } from './extensions/web-vitals'; | ||
type OnlyValidKeys<T, Shape> = T extends Shape ? (Exclude<keyof T, keyof Shape> extends never ? T : never) : never; | ||
@@ -50,2 +52,4 @@ export declare const defaultConfig: () => PostHogConfig; | ||
heatmaps?: Heatmaps; | ||
webVitalsAutocapture?: WebVitalsAutocapture; | ||
exceptionObserver?: ExceptionObserver; | ||
_requestQueue?: RequestQueue; | ||
@@ -62,3 +66,3 @@ _retryQueue?: RetryQueue; | ||
sentryIntegration: (options?: SentryIntegrationOptions) => ReturnType<typeof sentryIntegration>; | ||
private _debugEventEmitter; | ||
private _internalEventEmitter; | ||
/** DEPRECATED: We keep this to support existing usage but now one should just call .setPersonProperties */ | ||
@@ -65,0 +69,0 @@ people: { |
@@ -69,2 +69,8 @@ import type { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'; | ||
} | ||
export interface PerformanceCaptureConfig { | ||
/** works with session replay to use the browser's native performance observer to capture performance metrics */ | ||
network_timing?: boolean; | ||
/** works as a passenger event to use chrome's web vitals library to wrap fetch and capture web vitals */ | ||
web_vitals?: boolean; | ||
} | ||
export interface PostHogConfig { | ||
@@ -143,3 +149,3 @@ api_host: string; | ||
_onCapture: (eventName: string, eventData: CaptureResult) => void; | ||
capture_performance?: boolean; | ||
capture_performance?: boolean | PerformanceCaptureConfig; | ||
disable_compression: boolean; | ||
@@ -245,3 +251,4 @@ bootstrap: BootstrapConfig; | ||
_url?: string; /** Used to override the desired endpoint for the captured event */ | ||
_noHeatmaps?: boolean; /** Used to ensure that heatmap data is not included with this event */ | ||
/** Some events are sent as passengers inside other events - e.g. heatmaps and web vitals, not all ingestion routes can process passengers */ | ||
_noHeatmaps?: boolean; | ||
_batchKey?: string; /** key of queue, e.g. 'sessionRecording' vs 'event' */ | ||
@@ -264,3 +271,12 @@ _noTruncate?: boolean; /** if set, overrides and disables config.properties_string_max_length */ | ||
autocapture_opt_out?: boolean; | ||
capturePerformance?: boolean; | ||
/** | ||
* originally capturePerformance was replay only and so boolean true | ||
* is equivalent to { network_timing: true } | ||
* now capture performance can be separately enabled within replay | ||
* and as a standalone web vitals tracker | ||
* people can have them enabled separately | ||
* they work standalone but enhance each other | ||
* TODO: deprecate this so we make a new config that doesn't need this explanation | ||
*/ | ||
capturePerformance?: boolean | PerformanceCaptureConfig; | ||
analytics?: { | ||
@@ -272,3 +288,2 @@ endpoint?: string; | ||
endpoint?: string; | ||
errors_to_ignore: string[]; | ||
}; | ||
@@ -388,1 +403,27 @@ sessionRecording?: { | ||
}; | ||
export type ErrorEventArgs = [ | ||
event: string | Event, | ||
source?: string | undefined, | ||
lineno?: number | undefined, | ||
colno?: number | undefined, | ||
error?: Error | undefined | ||
]; | ||
export declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; | ||
export declare type SeverityLevel = typeof severityLevels[number]; | ||
export interface ErrorProperties { | ||
$exception_type: string; | ||
$exception_message: string; | ||
$exception_level: SeverityLevel; | ||
$exception_source?: string; | ||
$exception_lineno?: number; | ||
$exception_colno?: number; | ||
$exception_DOMException_code?: string; | ||
$exception_is_synthetic?: boolean; | ||
$exception_stack_trace_raw?: string; | ||
$exception_handled?: boolean; | ||
$exception_personURL?: string; | ||
} | ||
export interface ErrorConversions { | ||
errorToProperties: (args: ErrorEventArgs) => ErrorProperties; | ||
unhandledRejectionToProperties: (args: [ev: PromiseRejectionEvent]) => ErrorProperties; | ||
} |
{ | ||
"name": "posthog-js", | ||
"version": "1.141.0", | ||
"version": "1.141.1", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -37,3 +37,4 @@ "repository": "https://github.com/PostHog/posthog-js", | ||
"fflate": "^0.4.8", | ||
"preact": "^10.19.3" | ||
"preact": "^10.19.3", | ||
"web-vitals": "^4.0.1" | ||
}, | ||
@@ -40,0 +41,0 @@ "devDependencies": { |
@@ -8,2 +8,5 @@ export declare const PEOPLE_DISTINCT_ID_KEY = "$people_distinct_id"; | ||
export declare const HEATMAPS_ENABLED_SERVER_SIDE = "$heatmaps_enabled_server_side"; | ||
export declare const EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE = "$exception_capture_enabled_server_side"; | ||
export declare const EXCEPTION_CAPTURE_ENDPOINT = "$exception_capture_endpoint"; | ||
export declare const WEB_VITALS_ENABLED_SERVER_SIDE = "$web_vitals_enabled_server_side"; | ||
export declare const SESSION_RECORDING_ENABLED_SERVER_SIDE = "$session_recording_enabled_server_side"; | ||
@@ -10,0 +13,0 @@ export declare const CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = "$console_log_recording_enabled_server_side"; |
@@ -13,2 +13,5 @@ /* | ||
export var HEATMAPS_ENABLED_SERVER_SIDE = '$heatmaps_enabled_server_side'; | ||
export var EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE = '$exception_capture_enabled_server_side'; | ||
export var EXCEPTION_CAPTURE_ENDPOINT = '$exception_capture_endpoint'; | ||
export var WEB_VITALS_ENABLED_SERVER_SIDE = '$web_vitals_enabled_server_side'; | ||
export var SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_side'; | ||
@@ -15,0 +18,0 @@ export var CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = '$console_log_recording_enabled_server_side'; |
import { PostHog } from './posthog-core'; | ||
import { DecideResponse } from './types'; | ||
export declare class Decide { | ||
instance: PostHog; | ||
private readonly instance; | ||
constructor(instance: PostHog); | ||
@@ -6,0 +6,0 @@ call(): void; |
@@ -15,5 +15,4 @@ var __values = (this && this.__values) || function(o) { | ||
import { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'; | ||
import { isUndefined } from './utils/type-utils'; | ||
import { logger } from './utils/logger'; | ||
import { window, document, assignableWindow } from './utils/globals'; | ||
import { document, assignableWindow } from './utils/globals'; | ||
var Decide = /** @class */ (function () { | ||
@@ -72,17 +71,2 @@ function Decide(instance) { | ||
this.instance._afterDecideResponse(response); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
var exceptionAutoCaptureAddedToWindow = window === null || window === void 0 ? void 0 : window.extendPostHogWithExceptionAutoCapture; | ||
if (response['autocaptureExceptions'] && | ||
!!response['autocaptureExceptions'] && | ||
isUndefined(exceptionAutoCaptureAddedToWindow)) { | ||
loadScript(this.instance.requestRouter.endpointFor('assets', '/static/exception-autocapture.js'), function (err) { | ||
if (err) { | ||
return logger.error("Could not load exception autocapture script", err); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
window.extendPostHogWithExceptionAutocapture(_this.instance, response); | ||
}); | ||
} | ||
if (response['siteApps']) { | ||
@@ -89,0 +73,0 @@ if (this.instance.config.opt_in_site_apps) { |
import { StackFrame } from './stack-trace'; | ||
export type ErrorEventArgs = [ | ||
event: string | Event, | ||
source?: string | undefined, | ||
lineno?: number | undefined, | ||
colno?: number | undefined, | ||
error?: Error | undefined | ||
]; | ||
export interface ErrorProperties { | ||
$exception_type: string; | ||
$exception_message: string; | ||
$exception_source?: string; | ||
$exception_lineno?: number; | ||
$exception_colno?: number; | ||
$exception_DOMException_code?: string; | ||
$exception_is_synthetic?: boolean; | ||
$exception_stack_trace_raw?: string; | ||
$exception_handled?: boolean; | ||
$exception_personURL?: string; | ||
} | ||
import { ErrorEventArgs, ErrorProperties } from '../../types'; | ||
export declare function parseStackFrames(ex: Error & { | ||
@@ -22,0 +4,0 @@ framesToPop?: number; |
@@ -30,3 +30,4 @@ var __assign = (this && this.__assign) || function () { | ||
import { defaultStackParser } from './stack-trace'; | ||
import { isNumber, isString, isUndefined } from '../../utils/type-utils'; | ||
import { isEmptyString, isNumber, isString, isUndefined } from '../../utils/type-utils'; | ||
import { severityLevels } from '../../types'; | ||
/** | ||
@@ -68,2 +69,3 @@ * based on the very wonderful MIT licensed Sentry SDK | ||
$exception_stack_trace_raw: JSON.stringify(frames), | ||
$exception_level: 'error', | ||
}; | ||
@@ -75,2 +77,3 @@ } | ||
$exception_message: candidate, | ||
$exception_level: 'error', | ||
}; | ||
@@ -102,2 +105,5 @@ } | ||
} | ||
function isSeverityLevel(x) { | ||
return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x) >= 0; | ||
} | ||
function errorPropertiesFromObject(candidate) { | ||
@@ -107,2 +113,3 @@ return { | ||
$exception_message: "Non-Error ".concat('exception', " captured with keys: ").concat(extractExceptionKeysForMessage(candidate)), | ||
$exception_level: isSeverityLevel(candidate.level) ? candidate.level : 'error', | ||
}; | ||
@@ -112,3 +119,3 @@ } | ||
var _b = __read(_a, 5), event = _b[0], source = _b[1], lineno = _b[2], colno = _b[3], error = _b[4]; | ||
// exception type and message are not optional but, it's useful to start off without them enforced | ||
// some properties are not optional but, it's useful to start off without them enforced | ||
var errorProperties = {}; | ||
@@ -167,3 +174,5 @@ if (isUndefined(error) && isString(event)) { | ||
// now we make sure the mandatory fields that were made optional are present | ||
$exception_type: errorProperties.$exception_type || 'UnknownErrorType', $exception_message: errorProperties.$exception_message || '' }), (source | ||
$exception_type: errorProperties.$exception_type || 'UnknownErrorType', $exception_message: errorProperties.$exception_message || '', $exception_level: isSeverityLevel(errorProperties.$exception_level) | ||
? errorProperties.$exception_level | ||
: 'error' }), (source | ||
? { | ||
@@ -196,3 +205,3 @@ $exception_source: source, // TODO get this from URL if not present | ||
} | ||
// exception type and message are not optional but, it's useful to start off without them enforced | ||
// some properties are not optional but, it's useful to start off without them enforced | ||
var errorProperties = {}; | ||
@@ -211,4 +220,6 @@ if (isPrimitive(error)) { | ||
$exception_type: (errorProperties.$exception_type = 'UnhandledRejection'), $exception_message: (errorProperties.$exception_message = | ||
errorProperties.$exception_message || ev.reason || String(error)) }); | ||
errorProperties.$exception_message || ev.reason || String(error)), $exception_level: isSeverityLevel(errorProperties.$exception_level) | ||
? errorProperties.$exception_level | ||
: 'error' }); | ||
} | ||
//# sourceMappingURL=error-conversion.js.map |
import { PostHog } from '../../posthog-core'; | ||
import { DecideResponse, Properties } from '../../types'; | ||
import { ErrorEventArgs } from './error-conversion'; | ||
export declare const extendPostHog: (instance: PostHog, response: DecideResponse) => ExceptionObserver; | ||
export declare class ExceptionObserver { | ||
private _endpoint; | ||
instance: PostHog; | ||
remoteEnabled: boolean | undefined; | ||
private originalOnErrorHandler; | ||
private originalOnUnhandledRejectionHandler; | ||
private errorsToIgnore; | ||
private unwrapOnError; | ||
private unwrapUnhandledRejection; | ||
constructor(instance: PostHog); | ||
startCapturing(): void; | ||
stopCapturing(): void; | ||
isCapturing(): boolean; | ||
isEnabled(): boolean; | ||
get isEnabled(): boolean; | ||
get isCapturing(): boolean; | ||
get hasHandlers(): ((this: WindowEventHandlers, ev: PromiseRejectionEvent) => any) | undefined; | ||
startIfEnabled(): void; | ||
private loadScript; | ||
private startCapturing; | ||
private stopCapturing; | ||
afterDecideResponse(response: DecideResponse): void; | ||
captureException(args: ErrorEventArgs, properties?: Properties): void; | ||
captureException(errorProperties: Properties): void; | ||
/** | ||
@@ -19,0 +21,0 @@ * :TRICKY: Make sure we batch these requests |
@@ -1,120 +0,110 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
import { window } from '../../utils/globals'; | ||
import { errorToProperties, unhandledRejectionToProperties } from './error-conversion'; | ||
import { isPrimitive } from './type-checking'; | ||
import { isArray, isObject, isUndefined } from '../../utils/type-utils'; | ||
import { isObject } from '../../utils/type-utils'; | ||
import { logger } from '../../utils/logger'; | ||
export var extendPostHog = function (instance, response) { | ||
var exceptionObserver = new ExceptionObserver(instance); | ||
exceptionObserver.afterDecideResponse(response); | ||
return exceptionObserver; | ||
}; | ||
import { EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE, EXCEPTION_CAPTURE_ENDPOINT } from '../../constants'; | ||
import { loadScript } from '../../utils'; | ||
import Config from '../../config'; | ||
// TODO: move this to /x/ as default | ||
var BASE_ENDPOINT = '/e/'; | ||
var LOGGER_PREFIX = '[Exception Capture]'; | ||
var ExceptionObserver = /** @class */ (function () { | ||
function ExceptionObserver(instance) { | ||
this.originalOnErrorHandler = undefined; | ||
var _this = this; | ||
var _a; | ||
this._endpoint = BASE_ENDPOINT; | ||
this.originalOnUnhandledRejectionHandler = undefined; | ||
this.errorsToIgnore = []; | ||
this.startCapturing = function () { | ||
var _a; | ||
if (!window || !_this.isEnabled || _this.hasHandlers || ((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__)) { | ||
return; | ||
} | ||
var wrapOnError = window.posthogErrorWrappingFunctions.wrapOnError; | ||
var wrapUnhandledRejection = window.posthogErrorWrappingFunctions.wrapUnhandledRejection; | ||
if (!wrapOnError || !wrapUnhandledRejection) { | ||
logger.error(LOGGER_PREFIX + ' failed to load error wrapping functions - cannot start'); | ||
return; | ||
} | ||
try { | ||
_this.unwrapOnError = wrapOnError(_this.captureException.bind(_this)); | ||
_this.unwrapUnhandledRejection = wrapUnhandledRejection(_this.captureException.bind(_this)); | ||
} | ||
catch (e) { | ||
logger.error(LOGGER_PREFIX + ' failed to start', e); | ||
_this.stopCapturing(); | ||
} | ||
}; | ||
this.instance = instance; | ||
this.remoteEnabled = !!((_a = this.instance.persistence) === null || _a === void 0 ? void 0 : _a.props[EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE]); | ||
this.startIfEnabled(); | ||
} | ||
ExceptionObserver.prototype.startCapturing = function () { | ||
var _a; | ||
if (!window || !this.isEnabled() || ((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__)) { | ||
return; | ||
Object.defineProperty(ExceptionObserver.prototype, "isEnabled", { | ||
get: function () { | ||
var _a; | ||
return (_a = this.remoteEnabled) !== null && _a !== void 0 ? _a : false; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExceptionObserver.prototype, "isCapturing", { | ||
get: function () { | ||
var _a; | ||
return !!((_a = window === null || window === void 0 ? void 0 : window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ExceptionObserver.prototype, "hasHandlers", { | ||
get: function () { | ||
return this.originalOnUnhandledRejectionHandler || this.unwrapOnError; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
ExceptionObserver.prototype.startIfEnabled = function () { | ||
if (this.isEnabled && !this.isCapturing) { | ||
logger.info(LOGGER_PREFIX + ' enabled, starting...'); | ||
this.loadScript(this.startCapturing); | ||
} | ||
try { | ||
this.originalOnErrorHandler = window.onerror; | ||
window.onerror = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
this.captureException(args); | ||
if (this.originalOnErrorHandler) { | ||
// eslint-disable-next-line prefer-rest-params | ||
return this.originalOnErrorHandler.apply(this, args); | ||
} | ||
return false; | ||
}.bind(this); | ||
window.onerror.__POSTHOG_INSTRUMENTED__ = true; | ||
this.originalOnUnhandledRejectionHandler = window.onunhandledrejection; | ||
window.onunhandledrejection = function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var errorProperties = unhandledRejectionToProperties(args); | ||
this.sendExceptionEvent(errorProperties); | ||
if (window && this.originalOnUnhandledRejectionHandler) { | ||
// eslint-disable-next-line prefer-rest-params | ||
return this.originalOnUnhandledRejectionHandler.apply(window, args); | ||
} | ||
return true; | ||
}.bind(this); | ||
window.onunhandledrejection.__POSTHOG_INSTRUMENTED__ = true; | ||
}; | ||
ExceptionObserver.prototype.loadScript = function (cb) { | ||
if (this.hasHandlers) { | ||
// already loaded | ||
cb(); | ||
} | ||
catch (e) { | ||
logger.error('PostHog failed to start exception autocapture', e); | ||
this.stopCapturing(); | ||
} | ||
loadScript(this.instance.requestRouter.endpointFor('assets', "/static/exception-autocapture.js?v=".concat(Config.LIB_VERSION)), function (err) { | ||
if (err) { | ||
logger.error(LOGGER_PREFIX + ' failed to load script', err); | ||
} | ||
cb(); | ||
}); | ||
}; | ||
ExceptionObserver.prototype.stopCapturing = function () { | ||
var _a, _b; | ||
if (!window) { | ||
return; | ||
} | ||
if (!isUndefined(this.originalOnErrorHandler)) { | ||
window.onerror = this.originalOnErrorHandler; | ||
this.originalOnErrorHandler = null; | ||
} | ||
(_a = window.onerror) === null || _a === void 0 ? true : delete _a.__POSTHOG_INSTRUMENTED__; | ||
if (!isUndefined(this.originalOnUnhandledRejectionHandler)) { | ||
window.onunhandledrejection = this.originalOnUnhandledRejectionHandler; | ||
this.originalOnUnhandledRejectionHandler = null; | ||
} | ||
(_b = window.onunhandledrejection) === null || _b === void 0 ? true : delete _b.__POSTHOG_INSTRUMENTED__; | ||
(_a = this.unwrapOnError) === null || _a === void 0 ? void 0 : _a.call(this); | ||
(_b = this.unwrapUnhandledRejection) === null || _b === void 0 ? void 0 : _b.call(this); | ||
}; | ||
ExceptionObserver.prototype.isCapturing = function () { | ||
var _a; | ||
return !!((_a = window === null || window === void 0 ? void 0 : window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__); | ||
}; | ||
ExceptionObserver.prototype.isEnabled = function () { | ||
var _a; | ||
return (_a = this.remoteEnabled) !== null && _a !== void 0 ? _a : false; | ||
}; | ||
ExceptionObserver.prototype.afterDecideResponse = function (response) { | ||
var _a, _b; | ||
var autocaptureExceptionsResponse = response.autocaptureExceptions; | ||
// store this in-memory in case persistence is disabled | ||
this.remoteEnabled = !!autocaptureExceptionsResponse || false; | ||
if (!isPrimitive(autocaptureExceptionsResponse) && | ||
'errors_to_ignore' in autocaptureExceptionsResponse && | ||
isArray(autocaptureExceptionsResponse.errors_to_ignore)) { | ||
var dropRules = autocaptureExceptionsResponse.errors_to_ignore; | ||
this.errorsToIgnore = dropRules.map(function (rule) { | ||
return new RegExp(rule); | ||
}); | ||
this._endpoint = isObject(autocaptureExceptionsResponse) | ||
? autocaptureExceptionsResponse.endpoint || BASE_ENDPOINT | ||
: BASE_ENDPOINT; | ||
if (this.instance.persistence) { | ||
this.instance.persistence.register((_a = {}, | ||
_a[EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE] = this.remoteEnabled, | ||
_a)); | ||
// when we come to moving the endpoint to not /e/ we'll want that to persist between startup and decide response | ||
// TODO: once BASE_ENDPOINT is no longer /e/ this can be removed | ||
this.instance.persistence.register((_b = {}, | ||
_b[EXCEPTION_CAPTURE_ENDPOINT] = this._endpoint, | ||
_b)); | ||
} | ||
if (this.isEnabled()) { | ||
this.startCapturing(); | ||
logger.info('[Exception Capture] Remote config for exception autocapture is enabled, starting with config: ', isObject(autocaptureExceptionsResponse) ? autocaptureExceptionsResponse : {}); | ||
} | ||
this.startIfEnabled(); | ||
}; | ||
ExceptionObserver.prototype.captureException = function (args, properties) { | ||
var errorProperties = errorToProperties(args); | ||
if (this.errorsToIgnore.some(function (regex) { return regex.test(errorProperties.$exception_message || ''); })) { | ||
logger.info('[Exception Capture] Ignoring exception based on remote config', errorProperties); | ||
return; | ||
} | ||
var propertiesToSend = __assign(__assign({}, properties), errorProperties); | ||
ExceptionObserver.prototype.captureException = function (errorProperties) { | ||
var posthogHost = this.instance.requestRouter.endpointFor('ui'); | ||
errorProperties.$exception_personURL = "".concat(posthogHost, "/project/").concat(this.instance.config.token, "/person/").concat(this.instance.get_distinct_id()); | ||
this.sendExceptionEvent(propertiesToSend); | ||
this.sendExceptionEvent(errorProperties); | ||
}; | ||
@@ -129,2 +119,3 @@ /** | ||
_noHeatmaps: true, | ||
_url: this._endpoint, | ||
}); | ||
@@ -131,0 +122,0 @@ }; |
@@ -251,5 +251,10 @@ var __assign = (this && this.__assign) || function () { | ||
var bodyEnabled = (networkPayloadCapture_client_side === null || networkPayloadCapture_client_side === void 0 ? void 0 : networkPayloadCapture_client_side.recordBody) || (networkPayloadCapture_server_side === null || networkPayloadCapture_server_side === void 0 ? void 0 : networkPayloadCapture_server_side.recordBody); | ||
var performanceEnabled = this.instance.config.capture_performance || (networkPayloadCapture_server_side === null || networkPayloadCapture_server_side === void 0 ? void 0 : networkPayloadCapture_server_side.capturePerformance); | ||
return headersEnabled || bodyEnabled || performanceEnabled | ||
? { recordHeaders: headersEnabled, recordBody: bodyEnabled, recordPerformance: performanceEnabled } | ||
var clientConfigForPerformanceCapture = isObject(this.instance.config.capture_performance) | ||
? this.instance.config.capture_performance.network_timing | ||
: this.instance.config.capture_performance; | ||
var networkTimingEnabled = !!(isBoolean(clientConfigForPerformanceCapture) | ||
? clientConfigForPerformanceCapture | ||
: networkPayloadCapture_server_side === null || networkPayloadCapture_server_side === void 0 ? void 0 : networkPayloadCapture_server_side.capturePerformance); | ||
return headersEnabled || bodyEnabled || networkTimingEnabled | ||
? { recordHeaders: headersEnabled, recordBody: bodyEnabled, recordPerformance: networkTimingEnabled } | ||
: undefined; | ||
@@ -840,3 +845,3 @@ }, | ||
_batchKey: SESSION_RECORDING_BATCH_KEY, | ||
_noHeatmaps: true, // Session Replay ingestion can't handle heatamap data | ||
_noHeatmaps: true, | ||
}); | ||
@@ -843,0 +848,0 @@ }; |
@@ -19,2 +19,3 @@ /** | ||
import { PostHog } from '../posthog-core'; | ||
import { SeverityLevel } from '../types'; | ||
type _SentryEvent = any; | ||
@@ -31,4 +32,2 @@ type _SentryEventProcessor = any; | ||
} | ||
declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; | ||
declare type _SeverityLevel = typeof severityLevels[number]; | ||
export type SentryIntegrationOptions = { | ||
@@ -45,3 +44,3 @@ organization?: string; | ||
*/ | ||
severityAllowList?: _SeverityLevel[] | '*'; | ||
severityAllowList?: SeverityLevel[] | '*'; | ||
}; | ||
@@ -61,4 +60,4 @@ export declare function createEventProcessor(_posthog: PostHog, { organization, projectId, prefix, severityAllowList }?: SentryIntegrationOptions): (event: _SentryEvent) => _SentryEvent; | ||
*/ | ||
severityAllowList?: _SeverityLevel[] | '*'); | ||
severityAllowList?: SeverityLevel[] | '*'); | ||
} | ||
export {}; |
@@ -18,5 +18,2 @@ /** | ||
*/ | ||
// levels copied from Sentry to avoid relying on a frequently changing @sentry/types dependency | ||
// but provided as an array of literal types, so we can constrain the level below | ||
var severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug']; | ||
var NAME = 'posthog-js'; | ||
@@ -43,2 +40,3 @@ export function createEventProcessor(_posthog, _a) { | ||
$exception_personURL: personUrl, | ||
$exception_level: event.level, | ||
// Sentry Exception Properties | ||
@@ -45,0 +43,0 @@ $sentry_event_id: event.event_id, |
@@ -128,2 +128,3 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
// TODO we should be able to mask this | ||
var url = window.location.href; | ||
@@ -130,0 +131,0 @@ this.buffer = this.buffer || {}; |
@@ -1,2 +0,6 @@ | ||
import { extendPostHog } from './extensions/exception-autocapture'; | ||
export default extendPostHog; | ||
import { Properties } from './types'; | ||
declare const posthogErrorWrappingFunctions: { | ||
wrapOnError: (captureFn: (props: Properties) => void) => () => void; | ||
wrapUnhandledRejection: (captureFn: (props: Properties) => void) => () => void; | ||
}; | ||
export default posthogErrorWrappingFunctions; |
@@ -1,7 +0,81 @@ | ||
import { extendPostHog } from './extensions/exception-autocapture'; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
import { errorToProperties, unhandledRejectionToProperties } from './extensions/exception-autocapture/error-conversion'; | ||
import { window } from './utils/globals'; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
window.extendPostHogWithExceptionAutoCapture = extendPostHog; | ||
export default extendPostHog; | ||
import { logger } from './utils/logger'; | ||
var wrapOnError = function (captureFn) { | ||
var win = window; | ||
if (!win) { | ||
logger.info('window not available, cannot wrap onerror'); | ||
} | ||
var originalOnError = win.onerror; | ||
win.onerror = function () { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var errorProperties = errorToProperties(args); | ||
captureFn(errorProperties); | ||
return (_a = originalOnError === null || originalOnError === void 0 ? void 0 : originalOnError.apply(void 0, __spreadArray([], __read(args), false))) !== null && _a !== void 0 ? _a : false; | ||
}; | ||
win.onerror.__POSTHOG_INSTRUMENTED__ = true; | ||
return function () { | ||
var _a; | ||
(_a = win.onerror) === null || _a === void 0 ? true : delete _a.__POSTHOG_INSTRUMENTED__; | ||
win.onerror = originalOnError; | ||
}; | ||
}; | ||
var wrapUnhandledRejection = function (captureFn) { | ||
var win = window; | ||
if (!win) { | ||
logger.info('window not available, cannot wrap onUnhandledRejection'); | ||
} | ||
var originalOnUnhandledRejection = win.onunhandledrejection; | ||
win.onunhandledrejection = function () { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var errorProperties = unhandledRejectionToProperties(args); | ||
captureFn(errorProperties); | ||
return (_a = originalOnUnhandledRejection === null || originalOnUnhandledRejection === void 0 ? void 0 : originalOnUnhandledRejection.apply(win, args)) !== null && _a !== void 0 ? _a : false; | ||
}; | ||
win.onunhandledrejection.__POSTHOG_INSTRUMENTED__ = true; | ||
return function () { | ||
var _a; | ||
(_a = win.onunhandledrejection) === null || _a === void 0 ? true : delete _a.__POSTHOG_INSTRUMENTED__; | ||
win.onunhandledrejection = originalOnUnhandledRejection; | ||
}; | ||
}; | ||
var posthogErrorWrappingFunctions = { | ||
wrapOnError: wrapOnError, | ||
wrapUnhandledRejection: wrapUnhandledRejection, | ||
}; | ||
window.posthogErrorWrappingFunctions = posthogErrorWrappingFunctions; | ||
export default posthogErrorWrappingFunctions; | ||
//# sourceMappingURL=loader-exception-autocapture.js.map |
@@ -20,2 +20,4 @@ import { PostHogFeatureFlags } from './posthog-featureflags'; | ||
import { ConsentManager } from './consent'; | ||
import { ExceptionObserver } from './extensions/exception-autocapture'; | ||
import { WebVitalsAutocapture } from './extensions/web-vitals'; | ||
type OnlyValidKeys<T, Shape> = T extends Shape ? (Exclude<keyof T, keyof Shape> extends never ? T : never) : never; | ||
@@ -50,2 +52,4 @@ export declare const defaultConfig: () => PostHogConfig; | ||
heatmaps?: Heatmaps; | ||
webVitalsAutocapture?: WebVitalsAutocapture; | ||
exceptionObserver?: ExceptionObserver; | ||
_requestQueue?: RequestQueue; | ||
@@ -62,3 +66,3 @@ _retryQueue?: RetryQueue; | ||
sentryIntegration: (options?: SentryIntegrationOptions) => ReturnType<typeof sentryIntegration>; | ||
private _debugEventEmitter; | ||
private _internalEventEmitter; | ||
/** DEPRECATED: We keep this to support existing usage but now one should just call .setPersonProperties */ | ||
@@ -65,0 +69,0 @@ people: { |
@@ -69,2 +69,8 @@ import type { MaskInputOptions, SlimDOMOptions } from 'rrweb-snapshot'; | ||
} | ||
export interface PerformanceCaptureConfig { | ||
/** works with session replay to use the browser's native performance observer to capture performance metrics */ | ||
network_timing?: boolean; | ||
/** works as a passenger event to use chrome's web vitals library to wrap fetch and capture web vitals */ | ||
web_vitals?: boolean; | ||
} | ||
export interface PostHogConfig { | ||
@@ -143,3 +149,3 @@ api_host: string; | ||
_onCapture: (eventName: string, eventData: CaptureResult) => void; | ||
capture_performance?: boolean; | ||
capture_performance?: boolean | PerformanceCaptureConfig; | ||
disable_compression: boolean; | ||
@@ -245,3 +251,4 @@ bootstrap: BootstrapConfig; | ||
_url?: string; /** Used to override the desired endpoint for the captured event */ | ||
_noHeatmaps?: boolean; /** Used to ensure that heatmap data is not included with this event */ | ||
/** Some events are sent as passengers inside other events - e.g. heatmaps and web vitals, not all ingestion routes can process passengers */ | ||
_noHeatmaps?: boolean; | ||
_batchKey?: string; /** key of queue, e.g. 'sessionRecording' vs 'event' */ | ||
@@ -264,3 +271,12 @@ _noTruncate?: boolean; /** if set, overrides and disables config.properties_string_max_length */ | ||
autocapture_opt_out?: boolean; | ||
capturePerformance?: boolean; | ||
/** | ||
* originally capturePerformance was replay only and so boolean true | ||
* is equivalent to { network_timing: true } | ||
* now capture performance can be separately enabled within replay | ||
* and as a standalone web vitals tracker | ||
* people can have them enabled separately | ||
* they work standalone but enhance each other | ||
* TODO: deprecate this so we make a new config that doesn't need this explanation | ||
*/ | ||
capturePerformance?: boolean | PerformanceCaptureConfig; | ||
analytics?: { | ||
@@ -272,3 +288,2 @@ endpoint?: string; | ||
endpoint?: string; | ||
errors_to_ignore: string[]; | ||
}; | ||
@@ -388,1 +403,27 @@ sessionRecording?: { | ||
}; | ||
export type ErrorEventArgs = [ | ||
event: string | Event, | ||
source?: string | undefined, | ||
lineno?: number | undefined, | ||
colno?: number | undefined, | ||
error?: Error | undefined | ||
]; | ||
export declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"]; | ||
export declare type SeverityLevel = typeof severityLevels[number]; | ||
export interface ErrorProperties { | ||
$exception_type: string; | ||
$exception_message: string; | ||
$exception_level: SeverityLevel; | ||
$exception_source?: string; | ||
$exception_lineno?: number; | ||
$exception_colno?: number; | ||
$exception_DOMException_code?: string; | ||
$exception_is_synthetic?: boolean; | ||
$exception_stack_trace_raw?: string; | ||
$exception_handled?: boolean; | ||
$exception_personURL?: string; | ||
} | ||
export interface ErrorConversions { | ||
errorToProperties: (args: ErrorEventArgs) => ErrorProperties; | ||
unhandledRejectionToProperties: (args: [ev: PromiseRejectionEvent]) => ErrorProperties; | ||
} |
@@ -6,2 +6,6 @@ export var Compression; | ||
})(Compression || (Compression = {})); | ||
// levels originally copied from Sentry to work with the sentry integration | ||
// and to avoid relying on a frequently changing @sentry/types dependency | ||
// but provided as an array of literal types, so we can constrain the level below | ||
export var severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug']; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "posthog-js", | ||
"version": "1.141.0", | ||
"version": "1.141.1", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -37,3 +37,4 @@ "repository": "https://github.com/PostHog/posthog-js", | ||
"fflate": "^0.4.8", | ||
"preact": "^10.19.3" | ||
"preact": "^10.19.3", | ||
"web-vitals": "^4.0.1" | ||
}, | ||
@@ -40,0 +41,0 @@ "devDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
7182839
2.43%326
3.16%23609
2.3%3
50%+ Added
+ Added