!function(){"use strict";var r="undefined"!=typeof window?window:void 0,e="undefined"!=typeof globalThis?globalThis:r;"undefined"==typeof self&&(e.self=e),"undefined"==typeof File&&(e.File=function(){}),null!=e&&e.XMLHttpRequest&&new e.XMLHttpRequest;var n=null!=r?r:{};function t(r,e,n,t,i,a,o){try{var u=r[a](o),c=u.value}catch(r){return void n(r)}u.done?e(c):Promise.resolve(c).then(t,i)}function i(r){return function(){var e=this,n=arguments;return new Promise((function(i,a){var o=r.apply(e,n);function u(r){t(o,i,a,u,c,"next",r)}function c(r){t(o,i,a,u,c,"throw",r)}u(void 0)}))}}function a(){return a=Object.assign?Object.assign.bind():function(r){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var t in n)({}).hasOwnProperty.call(n,t)&&(r[t]=n[t])}return r},a.apply(null,arguments)}var o,u,c,s={}.toString,l=Array.isArray||function(r){return"[object Array]"===s.call(r)},v=r=>void 0===r,f=r=>"[object String]"==s.call(r);function d(r){return null===r||"object"!=typeof r}function h(r,e){return{}.toString.call(r)==="[object "+e+"]"}function p(r){return"undefined"!=typeof Event&&function(r,e){try{return r instanceof e}catch(r){return!1}}(r,Event)}function y(r){var e=globalThis._posthogChunkIds;if(e){var n=Object.keys(e);return c&&n.length===u?c:(u=n.length,c=n.reduce(((n,t)=>{o||(o={});var i=o[t];if(i)n[i[0]]=i[1];else for(var a=r(t),u=a.length-1;u>=0;u--){var c=a[u],s=null==c?void 0:c.filename,l=e[t];if(s&&l){n[s]=l,o[t]=[s,l];break}}return n}),{}))}}var g="?";function w(r,e,n,t,i){var a={platform:r,filename:e,function:""===n?g:n,in_app:!0};return v(t)||(a.lineno=t),v(i)||(a.colno=i),a}var b=(r,e)=>{var n=-1!==r.indexOf("safari-extension"),t=-1!==r.indexOf("safari-web-extension");return n||t?[-1!==r.indexOf("@")?r.split("@")[0]:g,n?"safari-extension:"+e:"safari-web-extension:"+e]:[r,e]},m=/^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i,E=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,j=/\((\S*)(?::(\d+))(?::(\d+))\)/,k=(r,e)=>{var n=m.exec(r);if(n){var[,t,i,a]=n;return w(e,t,g,+i,+a)}var o=E.exec(r);if(o){if(o[2]&&0===o[2].indexOf("eval")){var u=j.exec(o[2]);u&&(o[2]=u[1],o[3]=u[2],o[4]=u[3])}var[c,s]=b(o[1]||g,o[2]);return w(e,s,c,o[3]?+o[3]:void 0,o[4]?+o[4]:void 0)}},x=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,O=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,A=(r,e)=>{var n=x.exec(r);if(n){if(n[3]&&n[3].indexOf(" > eval")>-1){var t=O.exec(n[3]);t&&(n[1]=n[1]||"eval",n[3]=t[1],n[4]=t[2],n[5]="")}var i=n[3],a=n[1]||g;return[a,i]=b(a,i),w(e,i,a,n[4]?+n[4]:void 0,n[5]?+n[5]:void 0)}},S=/\(error: (.*)\)/;var M=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;var R=["fatal","error","warning","log","info","debug"];function P(r,e){void 0===e&&(e=40);var n=Object.keys(r);if(n.sort(),!n.length)return"[object has no keys]";for(var t=n.length;t>0;t--){var i=n.slice(0,t).join(", ");if(e>=i.length)return t===n.length?i:i.length>e?i.slice(0,e)+"...":i}return""}var _=function(e,t){var{debugEnabled:i}=void 0===t?{}:t,a={k(t){if(r&&(n.POSTHOG_DEBUG||i)&&!v(r.console)&&r.console){for(var a=("__rrweb_original__"in r.console[t]?r.console[t].__rrweb_original__:r.console[t]),o=arguments.length,u=new Array(o>1?o-1:0),c=1;o>c;c++)u[c-1]=arguments[c];a(e,...u)}},debug(){for(var r=arguments.length,e=new Array(r),n=0;r>n;n++)e[n]=arguments[n];a.k("debug",...e)},info(){for(var r=arguments.length,e=new Array(r),n=0;r>n;n++)e[n]=arguments[n];a.k("log",...e)},warn(){for(var r=arguments.length,e=new Array(r),n=0;r>n;n++)e[n]=arguments[n];a.k("warn",...e)},error(){for(var r=arguments.length,e=new Array(r),n=0;r>n;n++)e[n]=arguments[n];a.k("error",...e)},critical(){for(var r=arguments.length,n=new Array(r),t=0;r>t;t++)n[t]=arguments[t];console.error(e,...n)},uninitializedWarning(r){a.error("You must initialize PostHog before calling "+r)},createLogger:(r,n)=>_(e+" "+r,n)};return a},C=_("[PostHog.js]").createLogger;C("[Error tracking]");var D=C("[ExceptionAutocapture]"),T=new class{constructor(r,e,n){void 0===n&&(n=[]),this.coercers=r,this.stackParser=e,this.modifiers=n}buildFromUnknown(r,e){void 0===e&&(e={});var n=e&&e.mechanism||{handled:!0,type:"generic"},t=this.buildCoercingContext(n,e,0).apply(r),i=this.buildParsingContext(e),a=this.parseStacktrace(t,i);return{$exception_list:this.convertToExceptionList(a,n),$exception_level:"error"}}modifyFrames(r){var e=this;return i((function*(){for(var n of r)n.stacktrace&&n.stacktrace.frames&&l(n.stacktrace.frames)&&(n.stacktrace.frames=yield e.applyModifiers(n.stacktrace.frames));return r}))()}coerceFallback(r){var e;return{type:"Error",value:"Unknown error",stack:null==(e=r.syntheticException)?void 0:e.stack,synthetic:!0}}parseStacktrace(r,e){var n,t;return null!=r.cause&&(n=this.parseStacktrace(r.cause,e)),""!=r.stack&&null!=r.stack&&(t=this.applyChunkIds(this.stackParser(r.stack,r.synthetic?e.skipFirstLines:0),e.chunkIdMap)),a({},r,{cause:n,stack:t})}applyChunkIds(r,e){return r.map((r=>(r.filename&&e&&(r.chunk_id=e[r.filename]),r)))}applyCoercers(r,e){for(var n of this.coercers)if(n.match(r))return n.coerce(r,e);return this.coerceFallback(e)}applyModifiers(r){var e=this;return i((function*(){var n=r;for(var t of e.modifiers)n=yield t(n);return n}))()}convertToExceptionList(r,e){var n,t,i,o={type:r.type,value:r.value,mechanism:{type:null!==(n=e.type)&&void 0!==n?n:"generic",handled:null===(t=e.handled)||void 0===t||t,synthetic:null!==(i=r.synthetic)&&void 0!==i&&i}};r.stack&&(o.stacktrace={type:"raw",frames:r.stack});var u=[o];return null!=r.cause&&u.push(...this.convertToExceptionList(r.cause,a({},e,{handled:!0}))),u}buildParsingContext(r){var e;return{chunkIdMap:y(this.stackParser),skipFirstLines:null!==(e=r.skipFirstLines)&&void 0!==e?e:1}}buildCoercingContext(r,e,n){void 0===n&&(n=0);var t=(n,t)=>{if(4>=t){var i=this.buildCoercingContext(r,e,t);return this.applyCoercers(n,i)}};return a({},e,{syntheticException:0==n?e.syntheticException:void 0,mechanism:r,apply:r=>t(r,n),next:r=>t(r,n+1)})}}([new class{match(r){return this.isDOMException(r)||this.isDOMError(r)}coerce(r,e){var n=f(r.stack);return{type:this.getType(r),value:this.getValue(r),stack:n?r.stack:void 0,cause:r.cause?e.next(r.cause):void 0,synthetic:!1}}getType(r){return this.isDOMError(r)?"DOMError":"DOMException"}getValue(r){var e=r.name||(this.isDOMError(r)?"DOMError":"DOMException");return r.message?e+": "+r.message:e}isDOMException(r){return h(r,"DOMException")}isDOMError(r){return h(r,"DOMError")}},new class{match(r){return h(r,"PromiseRejectionEvent")||this.isCustomEventWrappingRejection(r)}isCustomEventWrappingRejection(r){if(!p(r))return!1;try{var e=r.detail;return null!=e&&"object"==typeof e&&"reason"in e}catch(r){return!1}}coerce(r,e){var n,t=this.getUnhandledRejectionReason(r);return d(t)?{type:"UnhandledRejection",value:"Non-Error promise rejection captured with value: "+String(t),stack:null==(n=e.syntheticException)?void 0:n.stack,synthetic:!0}:e.apply(t)}getUnhandledRejectionReason(r){try{if("reason"in r)return r.reason;if("detail"in r&&null!=r.detail&&"object"==typeof r.detail&&"reason"in r.detail)return r.detail.reason}catch(r){}return r}},new class{constructor(){}match(r){return h(r,"ErrorEvent")&&null!=r.error}coerce(r,e){var n;return e.apply(r.error)||{type:"ErrorEvent",value:r.message,stack:null==(n=e.syntheticException)?void 0:n.stack,synthetic:!0}}},new class{match(r){return r instanceof Error}coerce(r,e){return{type:this.getType(r),value:this.getMessage(r,e),stack:this.getStack(r),cause:r.cause?e.next(r.cause):void 0,synthetic:!1}}getType(r){return r.name||r.constructor.name}getMessage(r,e){var n=r.message;return String(n.error&&"string"==typeof n.error.message?n.error.message:n)}getStack(r){return r.stacktrace||r.stack||void 0}},new class{match(r){return p(r)}coerce(r,e){var n,t=r.constructor.name;return{type:t,value:t+" captured as exception with keys: "+P(r),stack:null==(n=e.syntheticException)?void 0:n.stack,synthetic:!0}}},new class{match(r){return"object"==typeof r&&null!==r}coerce(r,e){var n,t=this.getErrorPropertyFromObject(r);return t?e.apply(t):{type:this.getType(r),value:this.getValue(r),stack:null==(n=e.syntheticException)?void 0:n.stack,level:this.isSeverityLevel(r.level)?r.level:"error",synthetic:!0}}getType(r){return p(r)?r.constructor.name:"Error"}getValue(r){if("name"in r&&"string"==typeof r.name){var e="'"+r.name+"' captured as exception";return"message"in r&&"string"==typeof r.message&&(e+=" with message: '"+r.message+"'"),e}if("message"in r&&"string"==typeof r.message)return r.message;var n=this.getObjectClassName(r);return(n&&"Object"!==n?"'"+n+"'":"Object")+" captured as exception with keys: "+P(r)}isSeverityLevel(r){return f(r)&&!(r=>f(r)&&0===r.trim().length)(r)&&R.indexOf(r)>=0}getErrorPropertyFromObject(r){for(var e in r)if({}.hasOwnProperty.call(r,e)){var n=r[e];if(n instanceof Error)return n}}getObjectClassName(r){try{var e=Object.getPrototypeOf(r);return e?e.constructor.name:void 0}catch(r){return}}},new class{match(r){return"string"==typeof r}coerce(r,e){var n,[t,i]=this.getInfos(r);return{type:null!=t?t:"Error",value:null!=i?i:r,stack:null==(n=e.syntheticException)?void 0:n.stack,synthetic:!0}}getInfos(r){var e="Error",n=r,t=r.match(M);return t&&(e=t[1],n=t[2]),[e,n]}},new class{match(r){return d(r)}coerce(r,e){var n;return{type:"Error",value:"Primitive value captured as exception: "+String(r),stack:null==(n=e.syntheticException)?void 0:n.stack,synthetic:!0}}}],function(r){for(var e=arguments.length,n=new Array(e>1?e-1:0),t=1;e>t;t++)n[t-1]=arguments[t];return function(e,t){void 0===t&&(t=0);for(var i=[],o=e.split("\n"),u=t;o.length>u;u++){var c=o[u];if(1024>=c.length){var s=S.test(c)?c.replace(S,"$1"):c;if(!s.match(/\S*Error: /)){for(var l of n){var v=l(s,r);if(v){i.push(v);break}}if(i.length>=50)break}}}return function(r){if(!r.length)return[];var e=Array.from(r);return e.reverse(),e.slice(0,50).map((r=>{return a({},r,{filename:r.filename||(n=e,n[n.length-1]||{}).filename,function:r.function||g});var n}))}(i)}}("web:javascript",k,A)),U={wrapOnError(e){var n=r;n||D.info("window not available, cannot wrap onerror");var t=n.onerror;return n.onerror=function(){for(var r,n=arguments.length,i=new Array(n),a=0;n>a;a++)i[a]=arguments[a];var o=T.buildFromUnknown(i[4]||i[0],{mechanism:{handled:!1}});return e(o),null!==(r=null==t?void 0:t(...i))&&void 0!==r&&r},n.onerror.__POSTHOG_INSTRUMENTED__=!0,()=>{var r;null==(r=n.onerror)||delete r.__POSTHOG_INSTRUMENTED__,n.onerror=t}},wrapUnhandledRejection(e){var n=r;n||D.info("window not available, cannot wrap onUnhandledRejection");var t=n.onunhandledrejection;return n.onunhandledrejection=function(r){var n,i=T.buildFromUnknown(r,{mechanism:{handled:!1}});return e(i),null!==(n=null==t?void 0:t(r))&&void 0!==n&&n},n.onunhandledrejection.__POSTHOG_INSTRUMENTED__=!0,()=>{var r;null==(r=n.onunhandledrejection)||delete r.__POSTHOG_INSTRUMENTED__,n.onunhandledrejection=t}},wrapConsoleError(r){var e=console;e||D.info("console not available, cannot wrap console.error");var n=e.error;return e.error=function(){for(var e,t=arguments.length,i=new Array(t),a=0;t>a;a++)i[a]=arguments[a];e=1==i.length?i[0]:i.join(" ");var o=i.find((r=>r instanceof Error)),u=T.buildFromUnknown(o||e,{mechanism:{handled:!1},syntheticException:new Error("PostHog syntheticException"),skipFirstLines:2});return r(u),null==n?void 0:n(...i)},e.error.__POSTHOG_INSTRUMENTED__=!0,()=>{var r;null==(r=e.error)||delete r.__POSTHOG_INSTRUMENTED__,e.error=n}}};n.__PosthogExtensions__=n.__PosthogExtensions__||{},n.__PosthogExtensions__.errorWrappingFunctions=U,n.posthogErrorWrappingFunctions=U}(); //# sourceMappingURL=exception-autocapture.js.map