posthog-js 1.85.2 → 1.85.4
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.
- package/dist/array.full.js +1 -1
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/es.js +1 -1
- package/dist/es.js.map +1 -1
- package/dist/exception-autocapture.js +2 -0
- package/dist/exception-autocapture.js.map +1 -0
- package/dist/module.d.ts +0 -32
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/recorder-v2.js.map +1 -1
- package/dist/recorder.js.map +1 -1
- package/dist/surveys.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/src/decide.js +23 -10
- package/lib/src/decide.js.map +1 -1
- package/lib/src/extensions/exception-autocapture/error-conversion.js.map +1 -0
- package/lib/src/extensions/{exceptions/exception-autocapture.d.ts → exception-autocapture/index.d.ts} +1 -1
- package/lib/src/extensions/{exceptions/exception-autocapture.js → exception-autocapture/index.js} +9 -36
- package/lib/src/extensions/exception-autocapture/index.js.map +1 -0
- package/lib/src/extensions/exception-autocapture/stack-trace.js.map +1 -0
- package/lib/src/extensions/exception-autocapture/type-checking.js.map +1 -0
- package/lib/src/extensions/replay/sessionrecording.d.ts +0 -1
- package/lib/src/extensions/replay/sessionrecording.js +0 -3
- package/lib/src/extensions/replay/sessionrecording.js.map +1 -1
- package/lib/src/extensions/sentry-integration.js.map +1 -1
- package/lib/src/extensions/toolbar.js +19 -4
- package/lib/src/extensions/toolbar.js.map +1 -1
- package/lib/src/loader-exception-autocapture.d.ts +2 -0
- package/lib/src/loader-exception-autocapture.js +6 -0
- package/lib/src/loader-exception-autocapture.js.map +1 -0
- package/lib/src/posthog-core.d.ts +0 -3
- package/lib/src/posthog-core.js +0 -16
- package/lib/src/posthog-core.js.map +1 -1
- package/lib/src/utils.d.ts +1 -0
- package/lib/src/utils.js +8 -0
- package/lib/src/utils.js.map +1 -1
- package/package.json +1 -1
- package/lib/src/extensions/exceptions/error-conversion.js.map +0 -1
- package/lib/src/extensions/exceptions/exception-autocapture.js.map +0 -1
- package/lib/src/extensions/exceptions/stack-trace.js.map +0 -1
- package/lib/src/extensions/exceptions/type-checking.js.map +0 -1
- /package/lib/src/extensions/{exceptions → exception-autocapture}/error-conversion.d.ts +0 -0
- /package/lib/src/extensions/{exceptions → exception-autocapture}/error-conversion.js +0 -0
- /package/lib/src/extensions/{exceptions → exception-autocapture}/stack-trace.d.ts +0 -0
- /package/lib/src/extensions/{exceptions → exception-autocapture}/stack-trace.js +0 -0
- /package/lib/src/extensions/{exceptions → exception-autocapture}/type-checking.d.ts +0 -0
- /package/lib/src/extensions/{exceptions → exception-autocapture}/type-checking.js +0 -0
|
@@ -20,8 +20,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import { _getHashParam, _register_event, loadScript, logger } from '../utils';
|
|
23
|
+
import { _getHashParam, _register_event, _try, loadScript, logger, window } from '../utils';
|
|
24
24
|
import { POSTHOG_MANAGED_HOSTS } from './cloud';
|
|
25
|
+
// TRICKY: Many web frameworks will modify the route on load, potentially before posthog is initialized.
|
|
26
|
+
// To get ahead of this we grab it as soon as the posthog-js is parsed
|
|
27
|
+
var STATE_FROM_WINDOW = window.location
|
|
28
|
+
? _getHashParam(window.location.hash, '__posthog') || _getHashParam(location.hash, 'state')
|
|
29
|
+
: null;
|
|
25
30
|
var Toolbar = /** @class */ (function () {
|
|
26
31
|
function Toolbar(instance) {
|
|
27
32
|
this.instance = instance;
|
|
@@ -58,10 +63,20 @@ var Toolbar = /** @class */ (function () {
|
|
|
58
63
|
// If localStorage was undefined, and localStorage is supported we set the default value
|
|
59
64
|
localStorage = window.localStorage;
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Info about the state
|
|
68
|
+
* The state is a json object
|
|
69
|
+
* 1. (Legacy) The state can be `state={}` as a urlencoded object of info. In this case
|
|
70
|
+
* 2. The state should now be found in `__posthog={}` and can be base64 encoded or urlencoded.
|
|
71
|
+
* 3. Base64 encoding is preferred and will gradually be rolled out everywhere
|
|
72
|
+
*/
|
|
73
|
+
var stateHash_1 = STATE_FROM_WINDOW || _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state');
|
|
64
74
|
var toolbarParams = void 0;
|
|
75
|
+
var state = stateHash_1
|
|
76
|
+
? _try(function () { return JSON.parse(atob(decodeURIComponent(stateHash_1))); }) ||
|
|
77
|
+
_try(function () { return JSON.parse(decodeURIComponent(stateHash_1)); })
|
|
78
|
+
: null;
|
|
79
|
+
var parseFromUrl = state && state['action'] === 'ph_authorize';
|
|
65
80
|
if (parseFromUrl) {
|
|
66
81
|
// happens if they are initializing the toolbar using an old snippet
|
|
67
82
|
toolbarParams = state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../../src/extensions/toolbar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAG7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE/C;IAEI,iBAAY,QAAiB;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC5B,CAAC;IAED,qCAAmB,GAAnB,UAAoB,QAAwB;QACxC,IAAM,aAAa,GACf,QAAQ,CAAC,eAAe,CAAC;YACzB,QAAQ,CAAC,cAAc,CAAC;YACxB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACtF,IACI,QAAQ,CAAC,iBAAiB,CAAC;YAC3B,aAAa,CAAC,gBAAgB,C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AAC,CAAC,aAAa,EAAE,KAAI,CAAC,QAAQ,CAAC,CAAA;QAC5G,CAAC,CAAC,CAAA;QACF,mGAAmG;QACnG,oGAAoG;QACpG,eAAe,CAAC,MAAM,EAAE,iBAAiB,EAAE;YACvC,CAAC;YAAC,MAAc,CAAC,uBAAuB,CAAC,GAAG,KAAK,CAAA;YACjD,KAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;QACnC,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACf,CAAC;IAED,6CAA6C;IAC7C,6BAAW,GAAX,UAAY,MAAqB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,kDAAkD;IAClD,iCAAe,GAAf,UACI,QAA0B,EAC1B,YAA6C,EAC7C,OAAwB;QAFxB,yBAAA,EAAA,WAAW,MAAM,CAAC,QAAQ;QAC1B,6BAAA,EAAA,wBAA6C;QAC7C,wBAAA,EAAA,UAAU,MAAM,CAAC,OAAO;QAExB,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;IACjE,CAAC;IACL,cAAC;AAAD,CAAC,AAhJD,IAgJC","sourcesContent":["import { _getHashParam, _register_event, loadScript, logger } from '../utils'\nimport { PostHog } from '../posthog-core'\nimport { DecideResponse, ToolbarParams } from '../types'\nimport { POSTHOG_MANAGED_HOSTS } from './cloud'\n\nexport class Toolbar {\n instance: PostHog\n constructor(instance: PostHog) {\n this.instance = instance\n }\n\n afterDecideResponse(response: DecideResponse) {\n const toolbarParams: ToolbarParams =\n response['toolbarParams'] ||\n response['editorParams'] ||\n (response['toolbarVersion'] ? { toolbarVersion: response['toolbarVersion'] } : {})\n if (\n response['isAuthenticated'] &&\n toolbarParams['toolbarVersion'] &&\n toolbarParams['toolbarVersion'].indexOf('toolbar') === 0\n ) {\n this.loadToolbar({\n ...toolbarParams,\n })\n }\n }\n\n /**\n * To load the toolbar, we need an access token and other state. That state comes from one of three places:\n * 1. In the URL hash params\n * 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page\n */\n maybeLoadToolbar(\n location = window.location,\n localStorage: Storage | undefined = undefined,\n history = window.history\n ): boolean {\n try {\n // Before running the code we check if we can access localStorage, if not we opt-out\n if (!localStorage) {\n try {\n window.localStorage.setItem('test', 'test')\n window.localStorage.removeItem('test')\n } catch (error) {\n return false\n }\n\n // If localStorage was undefined, and localStorage is supported we set the default value\n localStorage = window.localStorage\n }\n\n const stateHash = _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n const state = stateHash ? JSON.parse(decodeURIComponent(stateHash)) : null\n const parseFromUrl = state && state['action'] === 'ph_authorize'\n let toolbarParams: ToolbarParams\n\n if (parseFromUrl) {\n // happens if they are initializing the toolbar using an old snippet\n toolbarParams = state\n toolbarParams.source = 'url'\n\n if (toolbarParams && Object.keys(toolbarParams).length > 0) {\n if (state['desiredHash']) {\n // hash that was in the url before the redirect\n location.hash = state['desiredHash']\n } else if (history) {\n history.replaceState('', document.title, location.pathname + location.search) // completely remove hash\n } else {\n location.hash = '' // clear hash (but leaves # unfortunately)\n }\n }\n } else {\n // get credentials from localStorage from a previous initialzation\n toolbarParams = JSON.parse(localStorage.getItem('_postHogToolbarParams') || '{}')\n toolbarParams.source = 'localstorage'\n\n // delete \"add-action\" or other intent from toolbarParams, otherwise we'll have the same intent\n // every time we open the page (e.g. you just visiting your own site an hour later)\n delete toolbarParams.userIntent\n }\n\n if (toolbarParams['token'] && this.instance.config.token === toolbarParams['token']) {\n this.loadToolbar(toolbarParams)\n return true\n } else {\n return false\n }\n } catch (e) {\n return false\n }\n }\n\n loadToolbar(params?: ToolbarParams): boolean {\n if ((window as any)['_postHogToolbarLoaded']) {\n return false\n }\n // only load the toolbar once, even if there are multiple instances of PostHogLib\n ;(window as any)['_postHogToolbarLoaded'] = true\n\n const host = this.instance.config.api_host\n // toolbar.js is served from the PostHog CDN, this has a TTL of 24 hours.\n // the toolbar asset includes a rotating \"token\" that is valid for 5 minutes.\n const fiveMinutesInMillis = 5 * 60 * 1000\n // this ensures that we bust the cache periodically\n const timestampToNearestFiveMinutes = Math.floor(Date.now() / fiveMinutesInMillis) * fiveMinutesInMillis\n const toolbarUrl = `${host}${host.endsWith('/') ? '' : '/'}static/toolbar.js?t=${timestampToNearestFiveMinutes}`\n const disableToolbarMetrics =\n !POSTHOG_MANAGED_HOSTS.includes(this.instance.config.api_host) &&\n this.instance.config.advanced_disable_toolbar_metrics\n\n const toolbarParams = {\n token: this.instance.config.token,\n ...params,\n apiURL: host, // defaults to api_host from the instance config if nothing else set\n ...(disableToolbarMetrics ? { instrument: false } : {}),\n }\n\n const { source: _discard, ...paramsToPersist } = toolbarParams // eslint-disable-line\n window.localStorage.setItem('_postHogToolbarParams', JSON.stringify(paramsToPersist))\n\n loadScript(toolbarUrl, (err) => {\n if (err) {\n logger.error('Failed to load toolbar', err)\n return\n }\n ;((window as any)['ph_load_toolbar'] || (window as any)['ph_load_editor'])(toolbarParams, this.instance)\n })\n // Turbolinks doesn't fire an onload event but does replace the entire body, including the toolbar.\n // Thus, we ensure the toolbar is only loaded inside the body, and then reloaded on turbolinks:load.\n _register_event(window, 'turbolinks:load', () => {\n ;(window as any)['_postHogToolbarLoaded'] = false\n this.loadToolbar(toolbarParams)\n })\n return true\n }\n\n /** @deprecated Use \"loadToolbar\" instead. */\n _loadEditor(params: ToolbarParams): boolean {\n return this.loadToolbar(params)\n }\n\n /** @deprecated Use \"maybeLoadToolbar\" instead. */\n maybeLoadEditor(\n location = window.location,\n localStorage: Storage | undefined = undefined,\n history = window.history\n ): boolean {\n return this.maybeLoadToolbar(location, localStorage, history)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../../src/extensions/toolbar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,EA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AAC,CAAA;QACF,OAAO,IAAI,CAAA;IACf,CAAC;IAED,6CAA6C;IAC7C,6BAAW,GAAX,UAAY,MAAqB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,kDAAkD;IAClD,iCAAe,GAAf,UACI,QAA0B,EAC1B,YAA6C,EAC7C,OAAwB;QAFxB,yBAAA,EAAA,WAAW,MAAM,CAAC,QAAQ;QAC1B,6BAAA,EAAA,wBAA6C;QAC7C,wBAAA,EAAA,UAAU,MAAM,CAAC,OAAO;QAExB,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;IACjE,CAAC;IACL,cAAC;AAAD,CAAC,AA9JD,IA8JC","sourcesContent":["import { _getHashParam, _register_event, _try, loadScript, logger, window } from '../utils'\nimport { PostHog } from '../posthog-core'\nimport { DecideResponse, ToolbarParams } from '../types'\nimport { POSTHOG_MANAGED_HOSTS } from './cloud'\n\n// TRICKY: Many web frameworks will modify the route on load, potentially before posthog is initialized.\n// To get ahead of this we grab it as soon as the posthog-js is parsed\nconst STATE_FROM_WINDOW = window.location\n ? _getHashParam(window.location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n : null\n\nexport class Toolbar {\n instance: PostHog\n constructor(instance: PostHog) {\n this.instance = instance\n }\n\n afterDecideResponse(response: DecideResponse) {\n const toolbarParams: ToolbarParams =\n response['toolbarParams'] ||\n response['editorParams'] ||\n (response['toolbarVersion'] ? { toolbarVersion: response['toolbarVersion'] } : {})\n if (\n response['isAuthenticated'] &&\n toolbarParams['toolbarVersion'] &&\n toolbarParams['toolbarVersion'].indexOf('toolbar') === 0\n ) {\n this.loadToolbar({\n ...toolbarParams,\n })\n }\n }\n\n /**\n * To load the toolbar, we need an access token and other state. That state comes from one of three places:\n * 1. In the URL hash params\n * 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page\n */\n maybeLoadToolbar(\n location = window.location,\n localStorage: Storage | undefined = undefined,\n history = window.history\n ): boolean {\n try {\n // Before running the code we check if we can access localStorage, if not we opt-out\n if (!localStorage) {\n try {\n window.localStorage.setItem('test', 'test')\n window.localStorage.removeItem('test')\n } catch (error) {\n return false\n }\n\n // If localStorage was undefined, and localStorage is supported we set the default value\n localStorage = window.localStorage\n }\n\n /**\n * Info about the state\n * The state is a json object\n * 1. (Legacy) The state can be `state={}` as a urlencoded object of info. In this case\n * 2. The state should now be found in `__posthog={}` and can be base64 encoded or urlencoded.\n * 3. Base64 encoding is preferred and will gradually be rolled out everywhere\n */\n\n const stateHash =\n STATE_FROM_WINDOW || _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n\n let toolbarParams: ToolbarParams\n const state = stateHash\n ? _try(() => JSON.parse(atob(decodeURIComponent(stateHash)))) ||\n _try(() => JSON.parse(decodeURIComponent(stateHash)))\n : null\n\n const parseFromUrl = state && state['action'] === 'ph_authorize'\n\n if (parseFromUrl) {\n // happens if they are initializing the toolbar using an old snippet\n toolbarParams = state\n toolbarParams.source = 'url'\n\n if (toolbarParams && Object.keys(toolbarParams).length > 0) {\n if (state['desiredHash']) {\n // hash that was in the url before the redirect\n location.hash = state['desiredHash']\n } else if (history) {\n history.replaceState('', document.title, location.pathname + location.search) // completely remove hash\n } else {\n location.hash = '' // clear hash (but leaves # unfortunately)\n }\n }\n } else {\n // get credentials from localStorage from a previous initialzation\n toolbarParams = JSON.parse(localStorage.getItem('_postHogToolbarParams') || '{}')\n toolbarParams.source = 'localstorage'\n\n // delete \"add-action\" or other intent from toolbarParams, otherwise we'll have the same intent\n // every time we open the page (e.g. you just visiting your own site an hour later)\n delete toolbarParams.userIntent\n }\n\n if (toolbarParams['token'] && this.instance.config.token === toolbarParams['token']) {\n this.loadToolbar(toolbarParams)\n return true\n } else {\n return false\n }\n } catch (e) {\n return false\n }\n }\n\n loadToolbar(params?: ToolbarParams): boolean {\n if ((window as any)['_postHogToolbarLoaded']) {\n return false\n }\n // only load the toolbar once, even if there are multiple instances of PostHogLib\n ;(window as any)['_postHogToolbarLoaded'] = true\n\n const host = this.instance.config.api_host\n // toolbar.js is served from the PostHog CDN, this has a TTL of 24 hours.\n // the toolbar asset includes a rotating \"token\" that is valid for 5 minutes.\n const fiveMinutesInMillis = 5 * 60 * 1000\n // this ensures that we bust the cache periodically\n const timestampToNearestFiveMinutes = Math.floor(Date.now() / fiveMinutesInMillis) * fiveMinutesInMillis\n const toolbarUrl = `${host}${host.endsWith('/') ? '' : '/'}static/toolbar.js?t=${timestampToNearestFiveMinutes}`\n const disableToolbarMetrics =\n !POSTHOG_MANAGED_HOSTS.includes(this.instance.config.api_host) &&\n this.instance.config.advanced_disable_toolbar_metrics\n\n const toolbarParams = {\n token: this.instance.config.token,\n ...params,\n apiURL: host, // defaults to api_host from the instance config if nothing else set\n ...(disableToolbarMetrics ? { instrument: false } : {}),\n }\n\n const { source: _discard, ...paramsToPersist } = toolbarParams // eslint-disable-line\n window.localStorage.setItem('_postHogToolbarParams', JSON.stringify(paramsToPersist))\n\n loadScript(toolbarUrl, (err) => {\n if (err) {\n logger.error('Failed to load toolbar', err)\n return\n }\n ;((window as any)['ph_load_toolbar'] || (window as any)['ph_load_editor'])(toolbarParams, this.instance)\n })\n // Turbolinks doesn't fire an onload event but does replace the entire body, including the toolbar.\n // Thus, we ensure the toolbar is only loaded inside the body, and then reloaded on turbolinks:load.\n _register_event(window, 'turbolinks:load', () => {\n ;(window as any)['_postHogToolbarLoaded'] = false\n this.loadToolbar(toolbarParams)\n })\n return true\n }\n\n /** @deprecated Use \"loadToolbar\" instead. */\n _loadEditor(params: ToolbarParams): boolean {\n return this.loadToolbar(params)\n }\n\n /** @deprecated Use \"maybeLoadToolbar\" instead. */\n maybeLoadEditor(\n location = window.location,\n localStorage: Storage | undefined = undefined,\n history = window.history\n ): boolean {\n return this.maybeLoadToolbar(location, localStorage, history)\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { extendPostHog } from './extensions/exception-autocapture';
|
|
2
|
+
import { _isUndefined } from './utils';
|
|
3
|
+
var win = _isUndefined(window) ? {} : window;
|
|
4
|
+
win.extendPostHogWithExceptionAutoCapture = extendPostHog;
|
|
5
|
+
export default extendPostHog;
|
|
6
|
+
//# sourceMappingURL=loader-exception-autocapture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-exception-autocapture.js","sourceRoot":"","sources":["../../src/loader-exception-autocapture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,IAAM,GAAG,GAA+B,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,EAAoB,CAAC,CAAC,CAAC,MAAM,CAE5F;AAAC,GAAW,CAAC,qCAAqC,GAAG,aAAa,CAAA;AAEnE,eAAe,aAAa,CAAA","sourcesContent":["import { extendPostHog } from './extensions/exception-autocapture'\nimport { _isUndefined } from './utils'\n\nconst win: Window & typeof globalThis = _isUndefined(window) ? ({} as typeof window) : window\n\n;(win as any).extendPostHogWithExceptionAutoCapture = extendPostHog\n\nexport default extendPostHog\n"]}
|
|
@@ -9,7 +9,6 @@ import { SessionIdManager } from './sessionid';
|
|
|
9
9
|
import { AutocaptureConfig, CaptureOptions, CaptureResult, Compression, EarlyAccessFeatureCallback, GDPROptions, isFeatureEnabledOptions, JSC, JsonType, OptInOutCapturingOptions, PostHogConfig, Properties, Property, RequestCallback, SessionIdChangedCallback, SnippetArrayItem, ToolbarParams, XHROptions } from './types';
|
|
10
10
|
import { SentryIntegration } from './extensions/sentry-integration';
|
|
11
11
|
import { PageViewManager } from './page-view';
|
|
12
|
-
import { ExceptionObserver } from './extensions/exceptions/exception-autocapture';
|
|
13
12
|
import { PostHogSurveys } from './posthog-surveys';
|
|
14
13
|
import { RateLimiter } from './rate-limiter';
|
|
15
14
|
import { SurveyCallback } from './posthog-surveys-types';
|
|
@@ -33,7 +32,6 @@ export declare class PostHog {
|
|
|
33
32
|
_retryQueue?: RetryQueue;
|
|
34
33
|
sessionRecording?: SessionRecording;
|
|
35
34
|
webPerformance?: WebPerformanceObserver;
|
|
36
|
-
exceptionAutocapture?: ExceptionObserver;
|
|
37
35
|
_triggered_notifs: any;
|
|
38
36
|
compression: Partial<Record<Compression, boolean>>;
|
|
39
37
|
_jsc: JSC;
|
|
@@ -111,7 +109,6 @@ export declare class PostHog {
|
|
|
111
109
|
* @param {Array} item A [function_name, args...] array to be executed
|
|
112
110
|
*/
|
|
113
111
|
push(item: SnippetArrayItem): void;
|
|
114
|
-
captureException(exception: Error, properties?: Properties): void;
|
|
115
112
|
/**
|
|
116
113
|
* Capture an event. This is the most important and
|
|
117
114
|
* frequently used PostHog function.
|
package/lib/src/posthog-core.js
CHANGED
|
@@ -54,7 +54,6 @@ import { SessionIdManager } from './sessionid';
|
|
|
54
54
|
import { SentryIntegration } from './extensions/sentry-integration';
|
|
55
55
|
import { createSegmentIntegration } from './extensions/segment-integration';
|
|
56
56
|
import { PageViewManager } from './page-view';
|
|
57
|
-
import { ExceptionObserver } from './extensions/exceptions/exception-autocapture';
|
|
58
57
|
import { PostHogSurveys } from './posthog-surveys';
|
|
59
58
|
import { RateLimiter } from './rate-limiter';
|
|
60
59
|
import { uuidv7 } from './uuidv7';
|
|
@@ -200,7 +199,6 @@ var create_phlib = function (token, config, name, createComplete) {
|
|
|
200
199
|
if (instance.config.__preview_measure_pageview_stats) {
|
|
201
200
|
instance.pageViewManager.startMeasuringScrollPosition();
|
|
202
201
|
}
|
|
203
|
-
instance.exceptionAutocapture = new ExceptionObserver(instance);
|
|
204
202
|
instance.__autocapture = instance.config.autocapture;
|
|
205
203
|
autocapture._setIsAutocaptureEnabled(instance);
|
|
206
204
|
if (autocapture._isAutocaptureEnabled) {
|
|
@@ -678,20 +676,6 @@ var PostHog = /** @class */ (function () {
|
|
|
678
676
|
PostHog.prototype.push = function (item) {
|
|
679
677
|
this._execute_array([item]);
|
|
680
678
|
};
|
|
681
|
-
/*
|
|
682
|
-
* PostHog supports exception autocapture, however, this function
|
|
683
|
-
* is used to manually capture an exception
|
|
684
|
-
* and can be used to add more context to that exception
|
|
685
|
-
*
|
|
686
|
-
* Properties passed as the second option will be merged with the properties
|
|
687
|
-
* of the exception event.
|
|
688
|
-
* Where there is a key in both generated exception and passed properties,
|
|
689
|
-
* the generated exception property takes precedence.
|
|
690
|
-
*/
|
|
691
|
-
PostHog.prototype.captureException = function (exception, properties) {
|
|
692
|
-
var _a;
|
|
693
|
-
(_a = this.exceptionAutocapture) === null || _a === void 0 ? void 0 : _a.captureException([exception.name, undefined, undefined, undefined, exception], properties);
|
|
694
|
-
};
|
|
695
679
|
/**
|
|
696
680
|
* Capture an event. This is the most important and
|
|
697
681
|
* frequently used PostHog function.
|