posthog-js 1.429.2 → 1.429.3

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 (61) hide show
  1. package/dist/all-external-dependencies.js +1 -1
  2. package/dist/all-external-dependencies.js.map +1 -1
  3. package/dist/array.full.es5.js +1 -1
  4. package/dist/array.full.es5.js.map +1 -1
  5. package/dist/array.full.js +1 -1
  6. package/dist/array.full.js.map +1 -1
  7. package/dist/array.full.no-external.js +1 -1
  8. package/dist/array.full.no-external.js.map +1 -1
  9. package/dist/array.js +1 -1
  10. package/dist/array.js.map +1 -1
  11. package/dist/array.no-external.js +1 -1
  12. package/dist/array.no-external.js.map +1 -1
  13. package/dist/conversations.js +1 -1
  14. package/dist/customizations.d.ts +2 -0
  15. package/dist/customizations.full.js +1 -1
  16. package/dist/customizations.js +1 -1
  17. package/dist/dead-clicks-autocapture.js +1 -1
  18. package/dist/default-extensions.js +1 -1
  19. package/dist/default-extensions.js.map +1 -1
  20. package/dist/exception-autocapture.js +1 -1
  21. package/dist/extension-bundles.js +1 -1
  22. package/dist/extension-bundles.js.map +1 -1
  23. package/dist/lazy-recorder.js +1 -1
  24. package/dist/main.d.ts +2 -0
  25. package/dist/main.js +1 -1
  26. package/dist/main.js.map +1 -1
  27. package/dist/module.d.ts +2 -0
  28. package/dist/module.full.d.ts +2 -0
  29. package/dist/module.full.js +1 -1
  30. package/dist/module.full.js.map +1 -1
  31. package/dist/module.full.no-external.d.ts +2 -0
  32. package/dist/module.full.no-external.js +1 -1
  33. package/dist/module.full.no-external.js.map +1 -1
  34. package/dist/module.js +1 -1
  35. package/dist/module.js.map +1 -1
  36. package/dist/module.mjs +1 -1
  37. package/dist/module.mjs.map +1 -1
  38. package/dist/module.no-external.d.ts +2 -0
  39. package/dist/module.no-external.js +1 -1
  40. package/dist/module.no-external.js.map +1 -1
  41. package/dist/module.slim.js +1 -1
  42. package/dist/module.slim.js.map +1 -1
  43. package/dist/module.slim.no-external.d.ts +2 -0
  44. package/dist/module.slim.no-external.js +1 -1
  45. package/dist/module.slim.no-external.js.map +1 -1
  46. package/dist/posthog-recorder.js +1 -1
  47. package/dist/product-tours.js +1 -1
  48. package/dist/src/extensions/surveys.d.ts +2 -0
  49. package/dist/surveys-preview.js.map +1 -1
  50. package/dist/surveys.d.ts +2 -0
  51. package/dist/surveys.js +1 -1
  52. package/dist/surveys.js.map +1 -1
  53. package/lib/package.json +1 -1
  54. package/lib/src/extensions/surveys.d.ts +2 -0
  55. package/lib/src/extensions/surveys.js +18 -1
  56. package/lib/src/extensions/surveys.js.map +1 -1
  57. package/lib/src/feature-flags-config.js +5 -5
  58. package/lib/src/feature-flags-config.js.map +1 -1
  59. package/lib/src/posthog-core.js +3 -7
  60. package/lib/src/posthog-core.js.map +1 -1
  61. package/package.json +4 -4
@@ -1,2 +1,2 @@
1
- !function(){const t="u">typeof window?window:void 0,n="u">typeof globalThis?globalThis:t;null!=n&&n.XMLHttpRequest&&new n.XMLHttpRequest;const e="undefined"!=typeof globalThis?globalThis:t;e&&"undefined"==typeof self&&(e.self=e),e&&"undefined"==typeof File&&(e.File=function(){});const r=null!=t?t:{},o=Object.prototype.toString,i=Array.isArray||function(t){return"[object Array]"===o.call(t)},c=t=>"function"==typeof t,s=t=>void 0===t,u=t=>"[object String]"==o.call(t),a=t=>u(t)&&0===t.trim().length;function l(t){return null===t||"object"!=typeof t}function f(t,n){return{}.toString.call(t)===`[object ${n}]`}function d(t){switch({}.toString.call(t)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object DOMError]":case"[object WebAssembly.Exception]":return!0;default:return h(t,Error)}}function v(t){return"u">typeof Event&&h(t,Event)}function h(t,n){try{return t instanceof n}catch(t){return!1}}function p(t,n,e,r,o,i,c){try{var s=t[i](c),u=s.value}catch(t){return void e(t)}s.done?n(u):Promise.resolve(u).then(r,o)}function y(t){return function(){var n=this,e=arguments;return new Promise(function(r,o){var i=t.apply(n,e);function c(t){p(i,r,o,c,s,"next",t)}function s(t){p(i,r,o,c,s,"throw",t)}c(void 0)})}}let b,g,m;function w(t){const n=globalThis._posthogChunkIds;if(!n)return;const e=Object.keys(n);return m&&e.length===g||(g=e.length,m=e.reduce((e,r)=>{b||(b={});const o=b[r];if(o)e[o[0]]=o[1];else{const o=t(r);for(let t=o.length-1;t>=0;t--){const i=o[t],c=null==i?void 0:i.filename,s=n[r];if(c&&s){e[c]=s,b[r]=[c,s];break}}}return e},{})),m}function E(t){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(t)}function j(t,n,e){return(n=function(t){var n=function(t){if("object"!=E(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=E(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==E(n)?n:n+""}(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function x(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),e.push.apply(e,r)}return e}function k(t){for(var n=1;arguments.length>n;n++){var e=null!=arguments[n]?arguments[n]:{};n%2?x(Object(e),!0).forEach(function(n){j(t,n,e[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):x(Object(e)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})}return t}function O(t,n,e,r,o){const i={platform:t,filename:n,function:"<anonymous>"===e?"?":e,in_app:!!n&&!n.startsWith("webkit-masked-url://")&&"<anonymous>"!==n};return s(r)||(i.lineno=r),s(o)||(i.colno=o),i}const S=(t,n)=>{const e=-1!==t.indexOf("safari-extension"),r=-1!==t.indexOf("safari-web-extension");return e||r?[-1!==t.indexOf("@")?t.split("@")[0]:"?",e?`safari-extension:${n}`:`safari-web-extension:${n}`]:[t,n]},M=/^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i,_=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,T=/\((\S*)(?::(\d+))(?::(\d+))\)/,R=(t,n)=>{const e=M.exec(t);if(e){const[,t,r,o]=e;return O(n,t,"?",+r,+o)}const r=_.exec(t);if(r){if(r[2]&&0===r[2].indexOf("eval")){const t=T.exec(r[2]);t&&(r[2]=t[1],r[3]=t[2],r[4]=t[3])}const[t,e]=S(r[1]||"?",r[2]);return O(n,e,t,r[3]?+r[3]:void 0,r[4]?+r[4]:void 0)}},D=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,P=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,U=(t,n)=>{const e=D.exec(t);if(e){if(e[3]&&e[3].indexOf(" > eval")>-1){const t=P.exec(e[3]);t&&(e[1]=e[1]||"eval",e[3]=t[1],e[4]=t[2],e[5]="")}let t=e[3],r=e[1]||"?";return[r,t]=S(r,t),O(n,t,r,e[4]?+e[4]:void 0,e[5]?+e[5]:void 0)}},C=/\(error: (.*)\)/;function F(t,n){return t.filename===n.filename&&t.function===n.function&&t.module===n.module&&t.lineno===n.lineno&&t.colno===n.colno}function I(t){for(let n=1;10>=n;n++){const e=t.length-2*n;if(0>e)break;let r=!0;for(let o=0;n>o;o++)if(!F(t[e+o],t[e+n+o])){r=!1;break}if(r){for(let r=0;n>r;r++)t[e+r]=t[e+n+r];return t.length=e+n,{start:e,length:n}}}}function L(t,n){const e=n.start+n.length,r=z(t,n);r&&t.splice(e+r===t.length?e:n.start,r)}function A(t,n){let e=n.start;for(;e>0&&F(t[e-1],t[e-1+n.length]);)e--;return n.start-e}function z(t,n){const e=n.start+n.length;let r=e;for(;t.length>r&&F(t[r],t[r-n.length]);)r++;return r-e}function H(t,n){const e=n[0];let r=t.length-(e?A(t,e):0);for(const e of n)r-=z(t,e);return r}function W(t,n,e){for(let r=0;t.length>r;r++){const o=t[(n+r)%t.length],i=t[(e+r)%t.length];if(o!==i)return i>o}return!1}const N=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;const V=["fatal","error","warning","log","info","debug"];function K(t,n=40){const e=Object.keys(t);if(e.sort(),!e.length)return"[object has no keys]";for(let t=e.length;t>0;t--){const r=e.slice(0,t).join(", ");if(n>=r.length)return t===e.length?r:r.length>n?`${r.slice(0,n)}...`:r}return""}const Y=(n,{debugEnabled:e}={})=>{const r={N(r,...o){t&&(t.POSTHOG_DEBUG||e)&&!s(t.console)&&t.console&&("__rrweb_original__"in t.console[r]?t.console[r].__rrweb_original__:t.console[r])(n,...o)},debug(...t){r.N("debug",...t)},info(...t){r.N("log",...t)},warn(...t){r.N("warn",...t)},error(...t){r.N("error",...t)},critical(...t){console.error(n,...t)},uninitializedWarning(t){r.error(`You must initialize PostHog before calling ${t}`)},createLogger:(t,e)=>Y(`${n} ${t}`,e)};return r},q=Y("[PostHog.js]").createLogger;q("[Error tracking]");const B=q("[ExceptionAutocapture]"),G=new class{constructor(t,n,e=[]){this.coercers=t,this.stackParser=n,this.modifiers=e}buildFromUnknown(t,n={}){const e=n&&n.mechanism||{handled:!0,type:"generic"},r=this.buildCoercingContext(e,n,0).apply(t),o=this.buildParsingContext(n),i=this.parseStacktrace(r,o);return{$exception_list:this.convertToExceptionList(i,e),$exception_level:"error"}}modifyFrames(t){var n=this;return y(function*(){for(const e of t)e.stacktrace&&e.stacktrace.frames&&i(e.stacktrace.frames)&&(e.stacktrace.frames=yield n.applyModifiers(e.stacktrace.frames));return t})()}coerceFallback(t){var n;return{type:"Error",value:"Unknown error",stack:null===(n=t.syntheticException)||void 0===n?void 0:n.stack,synthetic:!0}}parseStacktrace(t,n){let e,r;return null!=t.cause&&(e=this.parseStacktrace(t.cause,n)),""!=t.stack&&null!=t.stack&&(r=this.applyChunkIds(this.stackParser(t.stack,t.synthetic?n.skipFirstLines:0),n.chunkIdMap)),k(k({},t),{},{cause:e,stack:r})}applyChunkIds(t,n){return t.map(t=>(t.filename&&n&&(t.chunk_id=n[t.filename]),t))}applyCoercers(t,n){for(const e of this.coercers)if(e.match(t))return e.coerce(t,n);return this.coerceFallback(n)}applyModifiers(t){var n=this;return y(function*(){let e=t;for(const t of n.modifiers)e=yield t(e);return e})()}convertToExceptionList(t,n){var e,r,o;const i={type:t.type,value:t.value,mechanism:{type:null!==(e=n.type)&&void 0!==e?e:"generic",handled:null===(r=n.handled)||void 0===r||r,synthetic:null!==(o=t.synthetic)&&void 0!==o&&o}};t.stack&&(i.stacktrace={type:"raw",frames:t.stack});const c=[i];return null!=t.cause&&c.push(...this.convertToExceptionList(t.cause,k(k({},n),{},{handled:!0}))),c}buildParsingContext(t){var n;return{chunkIdMap:w(this.stackParser),skipFirstLines:null!==(n=t.skipFirstLines)&&void 0!==n?n:1}}buildCoercingContext(t,n,e=0){const r=(e,r)=>{if(4>=r){const o=this.buildCoercingContext(t,n,r);return this.applyCoercers(e,o)}};return k(k({},n),{},{syntheticException:0==e?n.syntheticException:void 0,mechanism:t,apply:t=>r(t,e),next:t=>r(t,e+1)})}}([new class{match(t){return this.isDOMException(t)||this.isDOMError(t)}coerce(t,n){const e=u(t.stack);return{type:this.getType(t),value:this.getValue(t),stack:e?t.stack:void 0,cause:t.cause?n.next(t.cause):void 0,synthetic:!1}}getType(t){return this.isDOMError(t)?"DOMError":"DOMException"}getValue(t){const n=t.name||(this.isDOMError(t)?"DOMError":"DOMException");return t.message?`${n}: ${t.message}`:n}isDOMException(t){return f(t,"DOMException")}isDOMError(t){return f(t,"DOMError")}},new class{match(t){return f(t,"PromiseRejectionEvent")||this.isCustomEventWrappingRejection(t)}isCustomEventWrappingRejection(t){if(!v(t))return!1;try{const n=t.detail;return null!=n&&"object"==typeof n&&"reason"in n}catch(t){return!1}}coerce(t,n){var e;const r=this.getUnhandledRejectionReason(t);return l(r)?{type:"UnhandledRejection",value:`Non-Error promise rejection captured with value: ${String(r)}`,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}:n.apply(r)}getUnhandledRejectionReason(t){try{if("reason"in t)return t.reason;if("detail"in t&&null!=t.detail&&"object"==typeof t.detail&&"reason"in t.detail)return t.detail.reason}catch(t){}return t}},new class{match(t){return!!f(t,"ErrorEvent")&&(null!=t.error||this.sr(t))}coerce(t,n){var e;if(null!=t.error)return n.apply(t.error);const r=n.apply(t.message);return k(k({},r),{},{stack:null!==(e=this.ar(t))&&void 0!==e?e:r.stack,synthetic:!0})}sr(t){return u(t.message)&&t.message.length>0}ar(t){var n,e;const r=t,o=null!==(n=r.lineno)&&void 0!==n?n:0,i=null!==(e=r.colno)&&void 0!==e?e:0;if(u(r.filename)&&0!==r.filename.length&&0!==o)return`Error\n at ${r.filename}:${o}:${i}`}},new class{match(t){return d(t)}coerce(t,n){var e;const r=this.getStack(t),o=void 0===r;return{type:this.getType(t),value:this.getMessage(t,n),stack:null!=r?r:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,cause:t.cause?n.next(t.cause):void 0,synthetic:o}}getType(t){return t.name||t.constructor.name}getMessage(t,n){const e=t.message;return String(e.error&&"string"==typeof e.error.message?e.error.message:e)}getStack(t){return t.stacktrace||t.stack||void 0}},new class{match(t){return v(t)}coerce(t,n){var e;const r=t.constructor.name;return{type:r,value:`${r} captured as exception with keys: ${K(t)}`,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}}},new class{match(t){return"object"==typeof t&&null!==t}coerce(t,n){var e,r;const o=this.getErrorPropertyFromObject(t);return o?n.apply(o):{type:this.getType(t),value:this.getValue(t),stack:null!==(e=this.getStack(t))&&void 0!==e?e:null===(r=n.syntheticException)||void 0===r?void 0:r.stack,level:this.isSeverityLevel(t.level)?t.level:"error",synthetic:!0}}getType(t){if(v(t))return t.constructor.name;const n="name"in t?t.name:void 0;return u(n)&&!a(n)?n:"Error"}getValue(t){if("name"in t&&"string"==typeof t.name){let n=`'${t.name}' captured as exception`;return"message"in t&&"string"==typeof t.message&&(n+=` with message: '${t.message}'`),n}if("message"in t&&"string"==typeof t.message)return t.message;const n=this.getObjectClassName(t);return`${n&&"Object"!==n?`'${n}'`:"Object"} captured as exception with keys: ${K(t)}`}isSeverityLevel(t){return u(t)&&!a(t)&&V.indexOf(t)>=0}getStack(t){try{return u(t.stacktrace)&&t.stacktrace.length>0?t.stacktrace:u(t.stack)&&t.stack.length>0?t.stack:void 0}catch(t){return}}getErrorPropertyFromObject(t){for(const n in t)if({}.hasOwnProperty.call(t,n)){const e=t[n];if(d(e))return e}}getObjectClassName(t){try{const n=Object.getPrototypeOf(t);return n?n.constructor.name:void 0}catch(t){return}}},new class{match(t){return"string"==typeof t}coerce(t,n){var e;const[r,o]=this.getInfos(t);return{type:null!=r?r:"Error",value:null!=o?o:t,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}}getInfos(t){let n="Error",e=t;const r=t.match(N);return r&&(n=r[1],e=r[2]),[n,e]}},new class{match(t){return l(t)}coerce(t,n){var e;return{type:"Error",value:`Primitive value captured as exception: ${String(t)}`,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}}}],function(t,...n){return(e,r=0)=>{const o=[],i=e.split("\n"),c=Math.min(i.length,r+1e3),s=[];for(let e=r;c>e;e++){const r=i[e];if(r.length>1024)continue;const c=C.test(r)?r.replace(C,"$1"):r;if(!c.match(/\S*Error: /)){for(const e of n){const n=e(c,t);if(n){o.push(n);const t=I(o);if(t){for(let n=s.length-1;n>=0;n--){const e=s[n];if(t.start>=e.start+e.length)break;s.pop()}s.push(t)}break}}if(H(o,s)>=50)break}}const u=[...s].sort((t,n)=>n.start-t.start),a=u[u.length-1];if(a){const t=A(o,a);o.splice(a.start-t,t);for(const n of u)n.start-=t}for(const t of u)L(o,t);return s.some(t=>0===t.start&&o.length===t.length)&&function(t){const n=t.map(t=>`${t.function}|${t.filename}|${t.lineno}|${t.colno}|${t.module}`);let e=0;for(let t=1;n.length>t;t++)W(n,t,e)&&(e=t);t.push(...t.splice(0,e))}(o),function(t){if(!t.length)return[];const n=Array.from(t);return n.reverse(),n.slice(0,50).map(t=>{return k(k({},t),{},{filename:t.filename||(e=n,e[e.length-1]||{}).filename,function:t.function||"?"});var e})}(o)}}("web:javascript",R,U)),J=(t,n)=>{try{return t()}catch(t){return n}},Q=(t,n)=>J(()=>t(n()),void 0),X=t=>J(()=>c(t)&&c(t.call),!1),Z=(t,n)=>J(()=>{t[n].__POSTHOG_INSTRUMENTED__=!0},void 0),tt=(t,n,e)=>{J(()=>{var e;null===(e=t[n])||void 0===e||delete e.__POSTHOG_INSTRUMENTED__},void 0),J(()=>{t[n]=e},void 0)},nt=n=>{const e=t;e||B.info("window not available, cannot wrap onerror");const r=J(()=>e.onerror,void 0);return e.onerror=function(...t){var e;return Q(n,()=>G.buildFromUnknown((([t,n,e,r,o])=>{if(null!=o)return o;if(u(t)&&u(n)&&n.length>0&&"undefined"!=typeof ErrorEvent)try{return new ErrorEvent("error",{message:t,filename:n,lineno:e,colno:r})}catch(n){return t}return t})(t),{mechanism:{handled:!1}})),!!X(r)&&null!==(e=r(...t))&&void 0!==e&&e},Z(e,"onerror"),()=>tt(e,"onerror",r)},et=(n,e=!1)=>{const r=t;r||B.info("window not available, cannot wrap onUnhandledRejection");const o=J(()=>r.onunhandledrejection,void 0);return r.onunhandledrejection=function(t){var r;return Q(n,()=>G.buildFromUnknown(t,{mechanism:{handled:!1}})),X(o)?null!==(r=o(t))&&void 0!==r&&r:e},Z(r,"onunhandledrejection"),()=>tt(r,"onunhandledrejection",o)},rt={wrapOnError:nt,wrapUnhandledRejection:et,wrapConsoleError(t){const n=console;n||B.info("console not available, cannot wrap console.error");const e=J(()=>n.error,void 0);return n.error=function(...n){Q(t,()=>{let t;t=1==n.length?n[0]:n.join(" ");const e=n.find(t=>t instanceof Error);return G.buildFromUnknown(e||t,{mechanism:{handled:!1},syntheticException:new Error("PostHog syntheticException"),skipFirstLines:2})}),X(e)&&e(...n)},Z(n,"error"),()=>tt(n,"error",e)}};r.__PosthogExtensions__=r.__PosthogExtensions__||{},r.__PosthogExtensions__.errorWrappingFunctions=rt,r.posthogErrorWrappingFunctions=rt;const ot=(t,n)=>{if(!c(null==t?void 0:t.capture))return;const e=null==n?void 0:n.autocaptureExceptions,r=null!==e&&"object"==typeof e&&i(e.errors_to_ignore)?e.errors_to_ignore.reduce((t,n)=>{try{t.push(new RegExp(n))}catch(t){B.error("Ignoring invalid legacy exception exclusion rule",n,t)}return t},[]):[],o=n=>{try{var e;null===(e=t.capture)||void 0===e||e.call(t,"$exception",n,{_noTruncate:!0,_batchKey:"exceptionEvent",_noHeatmaps:!0})}catch(t){B.error("Failed to capture exception for a legacy client",t)}};nt(t=>{r.some(n=>t.$exception_list.some(t=>n.test(t.value||"")))||o(t)}),et(o,!0)};r.extendPostHogWithExceptionAutoCapture=ot,r.extendPostHogWithExceptionAutocapture=ot}();
1
+ !function(){const t="u">typeof window?window:void 0,n="u">typeof globalThis?globalThis:t;null!=n&&n.XMLHttpRequest&&new n.XMLHttpRequest;const e="undefined"!=typeof globalThis?globalThis:t;e&&"undefined"==typeof self&&(e.self=e),e&&"undefined"==typeof File&&(e.File=function(){});const r=null!=t?t:{},o=Object.prototype.toString,i=Array.isArray||function(t){return"[object Array]"===o.call(t)},c=t=>"function"==typeof t,s=t=>void 0===t,u=t=>"[object String]"==o.call(t),a=t=>u(t)&&0===t.trim().length;function l(t){return null===t||"object"!=typeof t}function f(t,n){return{}.toString.call(t)===`[object ${n}]`}function d(t){switch({}.toString.call(t)){case"[object Error]":case"[object Exception]":case"[object DOMException]":case"[object DOMError]":case"[object WebAssembly.Exception]":return!0;default:return h(t,Error)}}function v(t){return"u">typeof Event&&h(t,Event)}function h(t,n){try{return t instanceof n}catch(t){return!1}}function p(t,n,e,r,o,i,c){try{var s=t[i](c),u=s.value}catch(t){return void e(t)}s.done?n(u):Promise.resolve(u).then(r,o)}function y(t){return function(){var n=this,e=arguments;return new Promise(function(r,o){var i=t.apply(n,e);function c(t){p(i,r,o,c,s,"next",t)}function s(t){p(i,r,o,c,s,"throw",t)}c(void 0)})}}let b,g,m;function w(t){const n=globalThis._posthogChunkIds;if(!n)return;const e=Object.keys(n);return m&&e.length===g||(g=e.length,m=e.reduce((e,r)=>{b||(b={});const o=b[r];if(o)e[o[0]]=o[1];else{const o=t(r);for(let t=o.length-1;t>=0;t--){const i=o[t],c=null==i?void 0:i.filename,s=n[r];if(c&&s){e[c]=s,b[r]=[c,s];break}}}return e},{})),m}function E(t){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},E(t)}function j(t,n,e){return(n=function(t){var n=function(t){if("object"!=E(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,"string");if("object"!=E(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==E(n)?n:n+""}(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function x(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),e.push.apply(e,r)}return e}function k(t){for(var n=1;arguments.length>n;n++){var e=null!=arguments[n]?arguments[n]:{};n%2?x(Object(e),!0).forEach(function(n){j(t,n,e[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):x(Object(e)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))})}return t}function O(t,n,e,r,o){const i={platform:t,filename:n,function:"<anonymous>"===e?"?":e,in_app:!!n&&!n.startsWith("webkit-masked-url://")&&"<anonymous>"!==n};return s(r)||(i.lineno=r),s(o)||(i.colno=o),i}const S=(t,n)=>{const e=-1!==t.indexOf("safari-extension"),r=-1!==t.indexOf("safari-web-extension");return e||r?[-1!==t.indexOf("@")?t.split("@")[0]:"?",e?`safari-extension:${n}`:`safari-web-extension:${n}`]:[t,n]},M=/^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i,_=/^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,T=/\((\S*)(?::(\d+))(?::(\d+))\)/,R=(t,n)=>{const e=M.exec(t);if(e){const[,t,r,o]=e;return O(n,t,"?",+r,+o)}const r=_.exec(t);if(r){if(r[2]&&0===r[2].indexOf("eval")){const t=T.exec(r[2]);t&&(r[2]=t[1],r[3]=t[2],r[4]=t[3])}const[t,e]=S(r[1]||"?",r[2]);return O(n,e,t,r[3]?+r[3]:void 0,r[4]?+r[4]:void 0)}},D=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,P=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,U=(t,n)=>{const e=D.exec(t);if(e){if(e[3]&&e[3].indexOf(" > eval")>-1){const t=P.exec(e[3]);t&&(e[1]=e[1]||"eval",e[3]=t[1],e[4]=t[2],e[5]="")}let t=e[3],r=e[1]||"?";return[r,t]=S(r,t),O(n,t,r,e[4]?+e[4]:void 0,e[5]?+e[5]:void 0)}},C=/\(error: (.*)\)/;function F(t,n){return t.filename===n.filename&&t.function===n.function&&t.module===n.module&&t.lineno===n.lineno&&t.colno===n.colno}function I(t){for(let n=1;10>=n;n++){const e=t.length-2*n;if(0>e)break;let r=!0;for(let o=0;n>o;o++)if(!F(t[e+o],t[e+n+o])){r=!1;break}if(r){for(let r=0;n>r;r++)t[e+r]=t[e+n+r];return t.length=e+n,{start:e,length:n}}}}function L(t,n){const e=n.start+n.length,r=z(t,n);r&&t.splice(e+r===t.length?e:n.start,r)}function A(t,n){let e=n.start;for(;e>0&&F(t[e-1],t[e-1+n.length]);)e--;return n.start-e}function z(t,n){const e=n.start+n.length;let r=e;for(;t.length>r&&F(t[r],t[r-n.length]);)r++;return r-e}function H(t,n){const e=n[0];let r=t.length-(e?A(t,e):0);for(const e of n)r-=z(t,e);return r}function W(t,n,e){for(let r=0;t.length>r;r++){const o=t[(n+r)%t.length],i=t[(e+r)%t.length];if(o!==i)return i>o}return!1}const N=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;const V=["fatal","error","warning","log","info","debug"];function K(t,n=40){const e=Object.keys(t);if(e.sort(),!e.length)return"[object has no keys]";for(let t=e.length;t>0;t--){const r=e.slice(0,t).join(", ");if(n>=r.length)return t===e.length?r:r.length>n?`${r.slice(0,n)}...`:r}return""}const Y=(n,{debugEnabled:e}={})=>{const r={N(r,...o){t&&(t.POSTHOG_DEBUG||e)&&!s(t.console)&&t.console&&("__rrweb_original__"in t.console[r]?t.console[r].__rrweb_original__:t.console[r])(n,...o)},debug(...t){r.N("debug",...t)},info(...t){r.N("log",...t)},warn(...t){r.N("warn",...t)},error(...t){r.N("error",...t)},critical(...t){console.error(n,...t)},uninitializedWarning(t){r.error(`You must initialize PostHog before calling ${t}`)},createLogger:(t,e)=>Y(`${n} ${t}`,e)};return r},q=Y("[PostHog.js]").createLogger;q("[Error tracking]");const B=q("[ExceptionAutocapture]"),G=new class{constructor(t,n,e=[]){this.coercers=t,this.stackParser=n,this.modifiers=e}buildFromUnknown(t,n={}){const e=n&&n.mechanism||{handled:!0,type:"generic"},r=this.buildCoercingContext(e,n,0).apply(t),o=this.buildParsingContext(n),i=this.parseStacktrace(r,o);return{$exception_list:this.convertToExceptionList(i,e),$exception_level:"error"}}modifyFrames(t){var n=this;return y(function*(){for(const e of t)e.stacktrace&&e.stacktrace.frames&&i(e.stacktrace.frames)&&(e.stacktrace.frames=yield n.applyModifiers(e.stacktrace.frames));return t})()}coerceFallback(t){var n;return{type:"Error",value:"Unknown error",stack:null===(n=t.syntheticException)||void 0===n?void 0:n.stack,synthetic:!0}}parseStacktrace(t,n){let e,r;return null!=t.cause&&(e=this.parseStacktrace(t.cause,n)),""!=t.stack&&null!=t.stack&&(r=this.applyChunkIds(this.stackParser(t.stack,t.synthetic?n.skipFirstLines:0),n.chunkIdMap)),k(k({},t),{},{cause:e,stack:r})}applyChunkIds(t,n){return t.map(t=>(t.filename&&n&&(t.chunk_id=n[t.filename]),t))}applyCoercers(t,n){for(const e of this.coercers)if(e.match(t))return e.coerce(t,n);return this.coerceFallback(n)}applyModifiers(t){var n=this;return y(function*(){let e=t;for(const t of n.modifiers)e=yield t(e);return e})()}convertToExceptionList(t,n){var e,r,o;const i={type:t.type,value:t.value,mechanism:{type:null!==(e=n.type)&&void 0!==e?e:"generic",handled:null===(r=n.handled)||void 0===r||r,synthetic:null!==(o=t.synthetic)&&void 0!==o&&o}};t.stack&&(i.stacktrace={type:"raw",frames:t.stack});const c=[i];return null!=t.cause&&c.push(...this.convertToExceptionList(t.cause,k(k({},n),{},{handled:!0}))),c}buildParsingContext(t){var n;return{chunkIdMap:w(this.stackParser),skipFirstLines:null!==(n=t.skipFirstLines)&&void 0!==n?n:1}}buildCoercingContext(t,n,e=0){const r=(e,r)=>{if(4>=r){const o=this.buildCoercingContext(t,n,r);return this.applyCoercers(e,o)}};return k(k({},n),{},{syntheticException:0==e?n.syntheticException:void 0,mechanism:t,apply:t=>r(t,e),next:t=>r(t,e+1)})}}([new class{match(t){return this.isDOMException(t)||this.isDOMError(t)}coerce(t,n){const e=u(t.stack);return{type:this.getType(t),value:this.getValue(t),stack:e?t.stack:void 0,cause:t.cause?n.next(t.cause):void 0,synthetic:!1}}getType(t){return this.isDOMError(t)?"DOMError":"DOMException"}getValue(t){const n=t.name||(this.isDOMError(t)?"DOMError":"DOMException");return t.message?`${n}: ${t.message}`:n}isDOMException(t){return f(t,"DOMException")}isDOMError(t){return f(t,"DOMError")}},new class{match(t){return f(t,"PromiseRejectionEvent")||this.isCustomEventWrappingRejection(t)}isCustomEventWrappingRejection(t){if(!v(t))return!1;try{const n=t.detail;return null!=n&&"object"==typeof n&&"reason"in n}catch(t){return!1}}coerce(t,n){var e;const r=this.getUnhandledRejectionReason(t);return l(r)?{type:"UnhandledRejection",value:`Non-Error promise rejection captured with value: ${String(r)}`,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}:n.apply(r)}getUnhandledRejectionReason(t){try{if("reason"in t)return t.reason;if("detail"in t&&null!=t.detail&&"object"==typeof t.detail&&"reason"in t.detail)return t.detail.reason}catch(t){}return t}},new class{match(t){return!!f(t,"ErrorEvent")&&(null!=t.error||this.lr(t))}coerce(t,n){var e;if(null!=t.error)return n.apply(t.error);const r=n.apply(t.message);return k(k({},r),{},{stack:null!==(e=this.ur(t))&&void 0!==e?e:r.stack,synthetic:!0})}lr(t){return u(t.message)&&t.message.length>0}ur(t){var n,e;const r=t,o=null!==(n=r.lineno)&&void 0!==n?n:0,i=null!==(e=r.colno)&&void 0!==e?e:0;if(u(r.filename)&&0!==r.filename.length&&0!==o)return`Error\n at ${r.filename}:${o}:${i}`}},new class{match(t){return d(t)}coerce(t,n){var e;const r=this.getStack(t),o=void 0===r;return{type:this.getType(t),value:this.getMessage(t,n),stack:null!=r?r:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,cause:t.cause?n.next(t.cause):void 0,synthetic:o}}getType(t){return t.name||t.constructor.name}getMessage(t,n){const e=t.message;return String(e.error&&"string"==typeof e.error.message?e.error.message:e)}getStack(t){return t.stacktrace||t.stack||void 0}},new class{match(t){return v(t)}coerce(t,n){var e;const r=t.constructor.name;return{type:r,value:`${r} captured as exception with keys: ${K(t)}`,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}}},new class{match(t){return"object"==typeof t&&null!==t}coerce(t,n){var e,r;const o=this.getErrorPropertyFromObject(t);return o?n.apply(o):{type:this.getType(t),value:this.getValue(t),stack:null!==(e=this.getStack(t))&&void 0!==e?e:null===(r=n.syntheticException)||void 0===r?void 0:r.stack,level:this.isSeverityLevel(t.level)?t.level:"error",synthetic:!0}}getType(t){if(v(t))return t.constructor.name;const n="name"in t?t.name:void 0;return u(n)&&!a(n)?n:"Error"}getValue(t){if("name"in t&&"string"==typeof t.name){let n=`'${t.name}' captured as exception`;return"message"in t&&"string"==typeof t.message&&(n+=` with message: '${t.message}'`),n}if("message"in t&&"string"==typeof t.message)return t.message;const n=this.getObjectClassName(t);return`${n&&"Object"!==n?`'${n}'`:"Object"} captured as exception with keys: ${K(t)}`}isSeverityLevel(t){return u(t)&&!a(t)&&V.indexOf(t)>=0}getStack(t){try{return u(t.stacktrace)&&t.stacktrace.length>0?t.stacktrace:u(t.stack)&&t.stack.length>0?t.stack:void 0}catch(t){return}}getErrorPropertyFromObject(t){for(const n in t)if({}.hasOwnProperty.call(t,n)){const e=t[n];if(d(e))return e}}getObjectClassName(t){try{const n=Object.getPrototypeOf(t);return n?n.constructor.name:void 0}catch(t){return}}},new class{match(t){return"string"==typeof t}coerce(t,n){var e;const[r,o]=this.getInfos(t);return{type:null!=r?r:"Error",value:null!=o?o:t,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}}getInfos(t){let n="Error",e=t;const r=t.match(N);return r&&(n=r[1],e=r[2]),[n,e]}},new class{match(t){return l(t)}coerce(t,n){var e;return{type:"Error",value:`Primitive value captured as exception: ${String(t)}`,stack:null===(e=n.syntheticException)||void 0===e?void 0:e.stack,synthetic:!0}}}],function(t,...n){return(e,r=0)=>{const o=[],i=e.split("\n"),c=Math.min(i.length,r+1e3),s=[];for(let e=r;c>e;e++){const r=i[e];if(r.length>1024)continue;const c=C.test(r)?r.replace(C,"$1"):r;if(!c.match(/\S*Error: /)){for(const e of n){const n=e(c,t);if(n){o.push(n);const t=I(o);if(t){for(let n=s.length-1;n>=0;n--){const e=s[n];if(t.start>=e.start+e.length)break;s.pop()}s.push(t)}break}}if(H(o,s)>=50)break}}const u=[...s].sort((t,n)=>n.start-t.start),a=u[u.length-1];if(a){const t=A(o,a);o.splice(a.start-t,t);for(const n of u)n.start-=t}for(const t of u)L(o,t);return s.some(t=>0===t.start&&o.length===t.length)&&function(t){const n=t.map(t=>`${t.function}|${t.filename}|${t.lineno}|${t.colno}|${t.module}`);let e=0;for(let t=1;n.length>t;t++)W(n,t,e)&&(e=t);t.push(...t.splice(0,e))}(o),function(t){if(!t.length)return[];const n=Array.from(t);return n.reverse(),n.slice(0,50).map(t=>{return k(k({},t),{},{filename:t.filename||(e=n,e[e.length-1]||{}).filename,function:t.function||"?"});var e})}(o)}}("web:javascript",R,U)),J=(t,n)=>{try{return t()}catch(t){return n}},Q=(t,n)=>J(()=>t(n()),void 0),X=t=>J(()=>c(t)&&c(t.call),!1),Z=(t,n)=>J(()=>{t[n].__POSTHOG_INSTRUMENTED__=!0},void 0),tt=(t,n,e)=>{J(()=>{var e;null===(e=t[n])||void 0===e||delete e.__POSTHOG_INSTRUMENTED__},void 0),J(()=>{t[n]=e},void 0)},nt=n=>{const e=t;e||B.info("window not available, cannot wrap onerror");const r=J(()=>e.onerror,void 0);return e.onerror=function(...t){var e;return Q(n,()=>G.buildFromUnknown((([t,n,e,r,o])=>{if(null!=o)return o;if(u(t)&&u(n)&&n.length>0&&"undefined"!=typeof ErrorEvent)try{return new ErrorEvent("error",{message:t,filename:n,lineno:e,colno:r})}catch(n){return t}return t})(t),{mechanism:{handled:!1}})),!!X(r)&&null!==(e=r(...t))&&void 0!==e&&e},Z(e,"onerror"),()=>tt(e,"onerror",r)},et=(n,e=!1)=>{const r=t;r||B.info("window not available, cannot wrap onUnhandledRejection");const o=J(()=>r.onunhandledrejection,void 0);return r.onunhandledrejection=function(t){var r;return Q(n,()=>G.buildFromUnknown(t,{mechanism:{handled:!1}})),X(o)?null!==(r=o(t))&&void 0!==r&&r:e},Z(r,"onunhandledrejection"),()=>tt(r,"onunhandledrejection",o)},rt={wrapOnError:nt,wrapUnhandledRejection:et,wrapConsoleError(t){const n=console;n||B.info("console not available, cannot wrap console.error");const e=J(()=>n.error,void 0);return n.error=function(...n){Q(t,()=>{let t;t=1==n.length?n[0]:n.join(" ");const e=n.find(t=>t instanceof Error);return G.buildFromUnknown(e||t,{mechanism:{handled:!1},syntheticException:new Error("PostHog syntheticException"),skipFirstLines:2})}),X(e)&&e(...n)},Z(n,"error"),()=>tt(n,"error",e)}};r.__PosthogExtensions__=r.__PosthogExtensions__||{},r.__PosthogExtensions__.errorWrappingFunctions=rt,r.posthogErrorWrappingFunctions=rt;const ot=(t,n)=>{if(!c(null==t?void 0:t.capture))return;const e=null==n?void 0:n.autocaptureExceptions,r=null!==e&&"object"==typeof e&&i(e.errors_to_ignore)?e.errors_to_ignore.reduce((t,n)=>{try{t.push(new RegExp(n))}catch(t){B.error("Ignoring invalid legacy exception exclusion rule",n,t)}return t},[]):[],o=n=>{try{var e;null===(e=t.capture)||void 0===e||e.call(t,"$exception",n,{_noTruncate:!0,_batchKey:"exceptionEvent",_noHeatmaps:!0})}catch(t){B.error("Failed to capture exception for a legacy client",t)}};nt(t=>{r.some(n=>t.$exception_list.some(t=>n.test(t.value||"")))||o(t)}),et(o,!0)};r.extendPostHogWithExceptionAutoCapture=ot,r.extendPostHogWithExceptionAutocapture=ot}();
2
2
  //# sourceMappingURL=exception-autocapture.js.map