posthog-js 1.90.2 → 1.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +1 -1
- package/dist/exception-autocapture.js.map +1 -1
- package/dist/module.d.ts +3 -4
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/recorder-v2.js +1 -1
- package/dist/recorder-v2.js.map +1 -1
- package/dist/recorder.js +1 -1
- package/dist/recorder.js.map +1 -1
- package/dist/surveys.js +1 -1
- package/dist/surveys.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/src/autocapture-utils.js +2 -1
- package/lib/src/autocapture-utils.js.map +1 -1
- package/lib/src/autocapture.js +11 -4
- package/lib/src/autocapture.js.map +1 -1
- package/lib/src/decide.js +2 -1
- package/lib/src/decide.js.map +1 -1
- package/lib/src/extensions/exception-autocapture/index.js +6 -3
- package/lib/src/extensions/exception-autocapture/index.js.map +1 -1
- package/lib/src/extensions/replay/sessionrecording.js +8 -8
- package/lib/src/extensions/replay/sessionrecording.js.map +1 -1
- package/lib/src/extensions/replay/web-performance.js +1 -0
- package/lib/src/extensions/replay/web-performance.js.map +1 -1
- package/lib/src/extensions/surveys.js +10 -2
- package/lib/src/extensions/surveys.js.map +1 -1
- package/lib/src/extensions/toolbar.d.ts +2 -2
- package/lib/src/extensions/toolbar.js +16 -13
- package/lib/src/extensions/toolbar.js.map +1 -1
- package/lib/src/gdpr-utils.js +2 -2
- package/lib/src/gdpr-utils.js.map +1 -1
- package/lib/src/loader-exception-autocapture.js +4 -3
- package/lib/src/loader-exception-autocapture.js.map +1 -1
- package/lib/src/loader-recorder-v2.js +7 -4
- package/lib/src/loader-recorder-v2.js.map +1 -1
- package/lib/src/loader-recorder.js +6 -6
- package/lib/src/loader-recorder.js.map +1 -1
- package/lib/src/loader-surveys.js +5 -3
- package/lib/src/loader-surveys.js.map +1 -1
- package/lib/src/page-view.js +14 -11
- package/lib/src/page-view.js.map +1 -1
- package/lib/src/posthog-core.js +21 -22
- package/lib/src/posthog-core.js.map +1 -1
- package/lib/src/posthog-surveys.js +7 -4
- package/lib/src/posthog-surveys.js.map +1 -1
- package/lib/src/retry-queue.js +2 -1
- package/lib/src/retry-queue.js.map +1 -1
- package/lib/src/session-props.d.ts +1 -2
- package/lib/src/session-props.js +2 -2
- package/lib/src/session-props.js.map +1 -1
- package/lib/src/sessionid.js +1 -1
- package/lib/src/sessionid.js.map +1 -1
- package/lib/src/storage.d.ts +1 -1
- package/lib/src/storage.js +18 -8
- package/lib/src/storage.js.map +1 -1
- package/lib/src/utils/event-utils.js +16 -10
- package/lib/src/utils/event-utils.js.map +1 -1
- package/lib/src/utils/globals.d.ts +5 -4
- package/lib/src/utils/globals.js +7 -5
- package/lib/src/utils/globals.js.map +1 -1
- package/lib/src/utils/index.js +7 -4
- package/lib/src/utils/index.js.map +1 -1
- package/lib/src/utils/logger.js +5 -2
- package/lib/src/utils/logger.js.map +1 -1
- package/lib/src/uuidv7.js +1 -1
- package/lib/src/uuidv7.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _each, _includes, _trim } from './utils';
|
|
2
2
|
import { _isNull, _isString, _isUndefined } from './utils/type-utils';
|
|
3
3
|
import { logger } from './utils/logger';
|
|
4
|
+
import { window } from './utils/globals';
|
|
4
5
|
export function getClassName(el) {
|
|
5
6
|
switch (typeof el.className) {
|
|
6
7
|
case 'string':
|
|
@@ -90,7 +91,7 @@ export var autocaptureCompatibleElements = ['a', 'button', 'form', 'input', 'sel
|
|
|
90
91
|
*/
|
|
91
92
|
export function shouldCaptureDomEvent(el, event, autocaptureConfig) {
|
|
92
93
|
if (autocaptureConfig === void 0) { autocaptureConfig = undefined; }
|
|
93
|
-
if (!el || isTag(el, 'html') || !isElementNode(el)) {
|
|
94
|
+
if (!window || !el || isTag(el, 'html') || !isElementNode(el)) {
|
|
94
95
|
return false;
|
|
95
96
|
}
|
|
96
97
|
if (autocaptureConfig === null || autocaptureConfig === void 0 ? void 0 : autocaptureConfig.url_allowlist) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocapture-utils.js","sourceRoot":"","sources":["../../src/autocapture-utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,MAAM,UAAU,YAAY,CAAC,EAAW;IACpC,QAAQ,OAAO,EAAE,CAAC,SAAS,EAAE;QACzB,KAAK,QAAQ;YACT,OAAO,EAAE,CAAC,SAAS,CAAA;QACvB,gCAAgC;QAChC,KAAK,QAAQ,EAAE,6EAA6E;YACxF,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAE,EAAE,CAAC,SAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;QAC/G;YACI,eAAe;YACf,OAAO,EAAE,CAAA;KAChB;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,EAAW;IACnC,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,oBAAoB,CAAC,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE;QAC9F,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK;YAChC,IAAI,UAAU,CAAC,KAAK,CA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AED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAe;IACtD,IAAI,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA;IAC9B,IAAI,GAAG,UAAG,IAAI,cAAI,iBAAiB,CAAC,MAAM,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;IACpD,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAC7C,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,IAAI,MAAM,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE;QACzD,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,KAAK;;YACpC,IAAI,KAAK,IAAI,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,WAAW,EAAE,MAAK,MAAM,EAAE;gBAClD,IAAI;oBACA,IAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;oBACnC,IAAI,GAAG,UAAG,IAAI,cAAI,QAAQ,CAAE,CAAC,IAAI,EAAE,CAAA;oBAEnC,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE;wBAC7C,IAAI,GAAG,UAAG,IAAI,cAAI,iBAAiB,CAAC,KAAK,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;qBACtD;iBACJ;gBAAC,OAAO,CAAC,EAAE;oBACR,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;iBAClB;aACJ;QACL,CAAC,CAAC,CAAA;KACL;IACD,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["/*\n * Get the className of an element, accounting for edge cases where element.className is an object\n * @param {Element} el - element to get the className of\n * @returns {string} the element's class\n */\nimport { AutocaptureConfig } from 'types'\nimport { _each, _includes, _trim } from './utils'\n\nimport { _isNull, _isString, _isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\n\nexport function getClassName(el: Element): string {\n switch (typeof el.className) {\n case 'string':\n return el.className\n // TODO: when is this ever used?\n case 'object': // handle cases where className might be SVGAnimatedString or some other type\n return ('baseVal' in el.className ? (el.className as any).baseVal : null) || el.getAttribute('class') || ''\n default:\n // future proof\n return ''\n }\n}\n\n/*\n * Get the direct text content of an element, protecting against sensitive data collection.\n * Concats textContent of each of the element's text node children; this avoids potential\n * collection of sensitive data that could happen if we used element.textContent and the\n * element had sensitive child elements, since element.textContent includes child content.\n * Scrubs values that look like they could be sensitive (i.e. cc or ssn number).\n * @param {Element} el - element to get the text of\n * @returns {string} the element's direct text content\n */\nexport function getSafeText(el: Element): string {\n let elText = ''\n\n if (shouldCaptureElement(el) && !isSensitiveElement(el) && el.childNodes && el.childNodes.length) {\n _each(el.childNodes, function (child) {\n if (isTextNode(child) && child.textContent) {\n elText += _trim(child.textContent)\n // scrub potentially sensitive values\n .split(/(\\s+)/)\n .filter(shouldCaptureValue)\n .join('')\n // normalize whitespace\n .replace(/[\\r\\n]/g, ' ')\n .replace(/[ ]+/g, ' ')\n // truncate\n .substring(0, 255)\n }\n })\n }\n\n return _trim(elText)\n}\n\n/*\n * Check whether an element has nodeType Node.ELEMENT_NODE\n * @param {Element} el - element to check\n * @returns {boolean} whether el is of the correct nodeType\n */\nexport function isElementNode(el: Element | undefined | null): el is HTMLElement {\n return !!el && el.nodeType === 1 // Node.ELEMENT_NODE - use integer constant for browser portability\n}\n\n/*\n * Check whether an element is of a given tag type.\n * Due to potential reference discrepancies (such as the webcomponents.js polyfill),\n * we want to match tagNames instead of specific references because something like\n * element === document.body won't always work because element might not be a native\n * element.\n * @param {Element} el - element to check\n * @param {string} tag - tag name (e.g., \"div\")\n * @returns {boolean} whether el is of the given tag type\n */\nexport function isTag(el: Element | undefined | null, tag: string): el is HTMLElement {\n return !!el && !!el.tagName && el.tagName.toLowerCase() === tag.toLowerCase()\n}\n\n/*\n * Check whether an element has nodeType Node.TEXT_NODE\n * @param {Element} el - element to check\n * @returns {boolean} whether el is of the correct nodeType\n */\nexport function isTextNode(el: Element | undefined | null): el is HTMLElement {\n return !!el && el.nodeType === 3 // Node.TEXT_NODE - use integer constant for browser portability\n}\n\n/*\n * Check whether an element has nodeType Node.DOCUMENT_FRAGMENT_NODE\n * @param {Element} el - element to check\n * @returns {boolean} whether el is of the correct nodeType\n */\nexport function isDocumentFragment(el: Element | ParentNode | undefined | null): el is DocumentFragment {\n return !!el && el.nodeType === 11 // Node.DOCUMENT_FRAGMENT_NODE - use integer constant for browser portability\n}\n\nexport const autocaptureCompatibleElements = ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']\n/*\n * Check whether a DOM event should be \"captured\" or if it may contain sentitive data\n * using a variety of heuristics.\n * @param {Element} el - element to check\n * @param {Event} event - event to check\n * @param {Object} autocaptureConfig - autocapture config\n * @returns {boolean} whether the event should be captured\n */\nexport function shouldCaptureDomEvent(\n el: Element,\n event: Event,\n autocaptureConfig: AutocaptureConfig | undefined = undefined\n): boolean {\n if (!el || isTag(el, 'html') || !isElementNode(el)) {\n return false\n }\n\n if (autocaptureConfig?.url_allowlist) {\n const url = window.location.href\n const allowlist = autocaptureConfig.url_allowlist\n if (allowlist && !allowlist.some((regex) => url.match(regex))) {\n return false\n }\n }\n\n if (autocaptureConfig?.dom_event_allowlist) {\n const allowlist = autocaptureConfig.dom_event_allowlist\n if (allowlist && !allowlist.some((eventType) => event.type === eventType)) {\n return false\n }\n }\n\n if (autocaptureConfig?.element_allowlist) {\n const allowlist = autocaptureConfig.element_allowlist\n if (allowlist && !allowlist.some((elementType) => el.tagName.toLowerCase() === elementType)) {\n return false\n }\n }\n\n if (autocaptureConfig?.css_selector_allowlist) {\n const allowlist = autocaptureConfig.css_selector_allowlist\n if (allowlist && !allowlist.some((selector) => el.matches(selector))) {\n return false\n }\n }\n\n let parentIsUsefulElement = false\n const targetElementList: Element[] = [el] // TODO: remove this var, it's never queried\n let parentNode: Element | boolean = true\n let curEl: Element = el\n while (curEl.parentNode && !isTag(curEl, 'body')) {\n // If element is a shadow root, we skip it\n if (isDocumentFragment(curEl.parentNode)) {\n targetElementList.push((curEl.parentNode as any).host)\n curEl = (curEl.parentNode as any).host\n continue\n }\n parentNode = (curEl.parentNode as Element) || false\n if (!parentNode) break\n if (autocaptureCompatibleElements.indexOf(parentNode.tagName.toLowerCase()) > -1) {\n parentIsUsefulElement = true\n } else {\n const compStyles = window.getComputedStyle(parentNode)\n if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer') {\n parentIsUsefulElement = true\n }\n }\n\n targetElementList.push(parentNode)\n curEl = parentNode\n }\n\n const compStyles = window.getComputedStyle(el)\n if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer' && event.type === 'click') {\n return true\n }\n\n const tag = el.tagName.toLowerCase()\n switch (tag) {\n case 'html':\n return false\n case 'form':\n return event.type === 'submit'\n case 'input':\n return event.type === 'change' || event.type === 'click'\n case 'select':\n case 'textarea':\n return event.type === 'change' || event.type === 'click'\n default:\n if (parentIsUsefulElement) return event.type === 'click'\n return (\n event.type === 'click' &&\n (autocaptureCompatibleElements.indexOf(tag) > -1 || el.getAttribute('contenteditable') === 'true')\n )\n }\n}\n\n/*\n * Check whether a DOM element should be \"captured\" or if it may contain sentitive data\n * using a variety of heuristics.\n * @param {Element} el - element to check\n * @returns {boolean} whether the element should be captured\n */\nexport function shouldCaptureElement(el: Element): boolean {\n for (let curEl = el; curEl.parentNode && !isTag(curEl, 'body'); curEl = curEl.parentNode as Element) {\n const classes = getClassName(curEl).split(' ')\n if (_includes(classes, 'ph-sensitive') || _includes(classes, 'ph-no-capture')) {\n return false\n }\n }\n\n if (_includes(getClassName(el).split(' '), 'ph-include')) {\n return true\n }\n\n // don't include hidden or password fields\n const type = (el as HTMLInputElement).type || ''\n if (_isString(type)) {\n // it's possible for el.type to be a DOM element if el is a form with a child input[name=\"type\"]\n switch (type.toLowerCase()) {\n case 'hidden':\n return false\n case 'password':\n return false\n }\n }\n\n // filter out data from fields that look like sensitive fields\n const name = (el as HTMLInputElement).name || el.id || ''\n // See https://github.com/posthog/posthog-js/issues/165\n // Under specific circumstances a bug caused .replace to be called on a DOM element\n // instead of a string, removing the element from the page. Ensure this issue is mitigated.\n if (_isString(name)) {\n // it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name=\"name\"]\n const sensitiveNameRegex =\n /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i\n if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) {\n return false\n }\n }\n\n return true\n}\n\n/*\n * Check whether a DOM element is 'sensitive' and we should only capture limited data\n * @param {Element} el - element to check\n * @returns {boolean} whether the element should be captured\n */\nexport function isSensitiveElement(el: Element): boolean {\n // don't send data from inputs or similar elements since there will always be\n // a risk of clientside javascript placing sensitive data in attributes\n const allowedInputTypes = ['button', 'checkbox', 'submit', 'reset']\n if (\n (isTag(el, 'input') && !allowedInputTypes.includes((el as HTMLInputElement).type)) ||\n isTag(el, 'select') ||\n isTag(el, 'textarea') ||\n el.getAttribute('contenteditable') === 'true'\n ) {\n return true\n }\n return false\n}\n\n/*\n * Check whether a string value should be \"captured\" or if it may contain sentitive data\n * using a variety of heuristics.\n * @param {string} value - string value to check\n * @returns {boolean} whether the element should be captured\n */\nexport function shouldCaptureValue(value: string): boolean {\n if (_isNull(value) || _isUndefined(value)) {\n return false\n }\n\n if (_isString(value)) {\n value = _trim(value)\n\n // check to see if input value looks like a credit card number\n // see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html\n const ccRegex =\n /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/\n if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {\n return false\n }\n\n // check to see if input value looks like a social security number\n const ssnRegex = /(^\\d{3}-?\\d{2}-?\\d{4}$)/\n if (ssnRegex.test(value)) {\n return false\n }\n }\n\n return true\n}\n\n/*\n * Check whether an attribute name is an Angular style attr (either _ngcontent or _nghost)\n * These update on each build and lead to noise in the element chain\n * More details on the attributes here: https://angular.io/guide/view-encapsulation\n * @param {string} attributeName - string value to check\n * @returns {boolean} whether the element is an angular tag\n */\nexport function isAngularStyleAttr(attributeName: string): boolean {\n if (_isString(attributeName)) {\n return attributeName.substring(0, 10) === '_ngcontent' || attributeName.substring(0, 7) === '_nghost'\n }\n return false\n}\n\n/*\n * Iterate through children of a target element looking for span tags\n * and return the text content of the span tags, separated by spaces,\n * along with the direct text content of the target element\n * @param {Element} target - element to check\n * @returns {string} text content of the target element and its child span tags\n */\nexport function getDirectAndNestedSpanText(target: Element): string {\n let text = getSafeText(target)\n text = `${text} ${getNestedSpanText(target)}`.trim()\n return shouldCaptureValue(text) ? text : ''\n}\n\n/*\n * Iterate through children of a target element looking for span tags\n * and return the text content of the span tags, separated by spaces\n * @param {Element} target - element to check\n * @returns {string} text content of span tags\n */\nexport function getNestedSpanText(target: Element): string {\n let text = ''\n if (target && target.childNodes && target.childNodes.length) {\n _each(target.childNodes, function (child) {\n if (child && child.tagName?.toLowerCase() === 'span') {\n try {\n const spanText = getSafeText(child)\n text = `${text} ${spanText}`.trim()\n\n if (child.childNodes && child.childNodes.length) {\n text = `${text} ${getNestedSpanText(child)}`.trim()\n }\n } catch (e) {\n logger.error(e)\n }\n }\n })\n }\n return text\n}\n"]}
|
|
1
|
+
{"version":3,"file":"autocapture-utils.js","sourceRoot":"","sources":["../../src/autocapture-utils.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,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M,UAAU,iBAAiB,CAAC,MAAe;IAC7C,IAAI,IAAI,GAAG,EAAE,CAAA;IACb,IAAI,MAAM,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE;QACzD,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,KAAK;;YACpC,IAAI,KAAK,IAAI,CAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,WAAW,EAAE,MAAK,MAAM,EAAE;gBAClD,IAAI;oBACA,IAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;oBACnC,IAAI,GAAG,UAAG,IAAI,cAAI,QAAQ,CAAE,CAAC,IAAI,EAAE,CAAA;oBAEnC,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE;wBAC7C,IAAI,GAAG,UAAG,IAAI,cAAI,iBAAiB,CAAC,KAAK,CAAC,CAAE,CAAC,IAAI,EAAE,CAAA;qBACtD;iBACJ;gBAAC,OAAO,CAAC,EAAE;oBACR,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;iBAClB;aACJ;QACL,CAAC,CAAC,CAAA;KACL;IACD,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["/*\n * Get the className of an element, accounting for edge cases where element.className is an object\n * @param {Element} el - element to get the className of\n * @returns {string} the element's class\n */\nimport { AutocaptureConfig } from 'types'\nimport { _each, _includes, _trim } from './utils'\n\nimport { _isNull, _isString, _isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window } from './utils/globals'\n\nexport function getClassName(el: Element): string {\n switch (typeof el.className) {\n case 'string':\n return el.className\n // TODO: when is this ever used?\n case 'object': // handle cases where className might be SVGAnimatedString or some other type\n return ('baseVal' in el.className ? (el.className as any).baseVal : null) || el.getAttribute('class') || ''\n default:\n // future proof\n return ''\n }\n}\n\n/*\n * Get the direct text content of an element, protecting against sensitive data collection.\n * Concats textContent of each of the element's text node children; this avoids potential\n * collection of sensitive data that could happen if we used element.textContent and the\n * element had sensitive child elements, since element.textContent includes child content.\n * Scrubs values that look like they could be sensitive (i.e. cc or ssn number).\n * @param {Element} el - element to get the text of\n * @returns {string} the element's direct text content\n */\nexport function getSafeText(el: Element): string {\n let elText = ''\n\n if (shouldCaptureElement(el) && !isSensitiveElement(el) && el.childNodes && el.childNodes.length) {\n _each(el.childNodes, function (child) {\n if (isTextNode(child) && child.textContent) {\n elText += _trim(child.textContent)\n // scrub potentially sensitive values\n .split(/(\\s+)/)\n .filter(shouldCaptureValue)\n .join('')\n // normalize whitespace\n .replace(/[\\r\\n]/g, ' ')\n .replace(/[ ]+/g, ' ')\n // truncate\n .substring(0, 255)\n }\n })\n }\n\n return _trim(elText)\n}\n\n/*\n * Check whether an element has nodeType Node.ELEMENT_NODE\n * @param {Element} el - element to check\n * @returns {boolean} whether el is of the correct nodeType\n */\nexport function isElementNode(el: Element | undefined | null): el is HTMLElement {\n return !!el && el.nodeType === 1 // Node.ELEMENT_NODE - use integer constant for browser portability\n}\n\n/*\n * Check whether an element is of a given tag type.\n * Due to potential reference discrepancies (such as the webcomponents.js polyfill),\n * we want to match tagNames instead of specific references because something like\n * element === document.body won't always work because element might not be a native\n * element.\n * @param {Element} el - element to check\n * @param {string} tag - tag name (e.g., \"div\")\n * @returns {boolean} whether el is of the given tag type\n */\nexport function isTag(el: Element | undefined | null, tag: string): el is HTMLElement {\n return !!el && !!el.tagName && el.tagName.toLowerCase() === tag.toLowerCase()\n}\n\n/*\n * Check whether an element has nodeType Node.TEXT_NODE\n * @param {Element} el - element to check\n * @returns {boolean} whether el is of the correct nodeType\n */\nexport function isTextNode(el: Element | undefined | null): el is HTMLElement {\n return !!el && el.nodeType === 3 // Node.TEXT_NODE - use integer constant for browser portability\n}\n\n/*\n * Check whether an element has nodeType Node.DOCUMENT_FRAGMENT_NODE\n * @param {Element} el - element to check\n * @returns {boolean} whether el is of the correct nodeType\n */\nexport function isDocumentFragment(el: Element | ParentNode | undefined | null): el is DocumentFragment {\n return !!el && el.nodeType === 11 // Node.DOCUMENT_FRAGMENT_NODE - use integer constant for browser portability\n}\n\nexport const autocaptureCompatibleElements = ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']\n/*\n * Check whether a DOM event should be \"captured\" or if it may contain sentitive data\n * using a variety of heuristics.\n * @param {Element} el - element to check\n * @param {Event} event - event to check\n * @param {Object} autocaptureConfig - autocapture config\n * @returns {boolean} whether the event should be captured\n */\nexport function shouldCaptureDomEvent(\n el: Element,\n event: Event,\n autocaptureConfig: AutocaptureConfig | undefined = undefined\n): boolean {\n if (!window || !el || isTag(el, 'html') || !isElementNode(el)) {\n return false\n }\n\n if (autocaptureConfig?.url_allowlist) {\n const url = window.location.href\n const allowlist = autocaptureConfig.url_allowlist\n if (allowlist && !allowlist.some((regex) => url.match(regex))) {\n return false\n }\n }\n\n if (autocaptureConfig?.dom_event_allowlist) {\n const allowlist = autocaptureConfig.dom_event_allowlist\n if (allowlist && !allowlist.some((eventType) => event.type === eventType)) {\n return false\n }\n }\n\n if (autocaptureConfig?.element_allowlist) {\n const allowlist = autocaptureConfig.element_allowlist\n if (allowlist && !allowlist.some((elementType) => el.tagName.toLowerCase() === elementType)) {\n return false\n }\n }\n\n if (autocaptureConfig?.css_selector_allowlist) {\n const allowlist = autocaptureConfig.css_selector_allowlist\n if (allowlist && !allowlist.some((selector) => el.matches(selector))) {\n return false\n }\n }\n\n let parentIsUsefulElement = false\n const targetElementList: Element[] = [el] // TODO: remove this var, it's never queried\n let parentNode: Element | boolean = true\n let curEl: Element = el\n while (curEl.parentNode && !isTag(curEl, 'body')) {\n // If element is a shadow root, we skip it\n if (isDocumentFragment(curEl.parentNode)) {\n targetElementList.push((curEl.parentNode as any).host)\n curEl = (curEl.parentNode as any).host\n continue\n }\n parentNode = (curEl.parentNode as Element) || false\n if (!parentNode) break\n if (autocaptureCompatibleElements.indexOf(parentNode.tagName.toLowerCase()) > -1) {\n parentIsUsefulElement = true\n } else {\n const compStyles = window.getComputedStyle(parentNode)\n if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer') {\n parentIsUsefulElement = true\n }\n }\n\n targetElementList.push(parentNode)\n curEl = parentNode\n }\n\n const compStyles = window.getComputedStyle(el)\n if (compStyles && compStyles.getPropertyValue('cursor') === 'pointer' && event.type === 'click') {\n return true\n }\n\n const tag = el.tagName.toLowerCase()\n switch (tag) {\n case 'html':\n return false\n case 'form':\n return event.type === 'submit'\n case 'input':\n return event.type === 'change' || event.type === 'click'\n case 'select':\n case 'textarea':\n return event.type === 'change' || event.type === 'click'\n default:\n if (parentIsUsefulElement) return event.type === 'click'\n return (\n event.type === 'click' &&\n (autocaptureCompatibleElements.indexOf(tag) > -1 || el.getAttribute('contenteditable') === 'true')\n )\n }\n}\n\n/*\n * Check whether a DOM element should be \"captured\" or if it may contain sentitive data\n * using a variety of heuristics.\n * @param {Element} el - element to check\n * @returns {boolean} whether the element should be captured\n */\nexport function shouldCaptureElement(el: Element): boolean {\n for (let curEl = el; curEl.parentNode && !isTag(curEl, 'body'); curEl = curEl.parentNode as Element) {\n const classes = getClassName(curEl).split(' ')\n if (_includes(classes, 'ph-sensitive') || _includes(classes, 'ph-no-capture')) {\n return false\n }\n }\n\n if (_includes(getClassName(el).split(' '), 'ph-include')) {\n return true\n }\n\n // don't include hidden or password fields\n const type = (el as HTMLInputElement).type || ''\n if (_isString(type)) {\n // it's possible for el.type to be a DOM element if el is a form with a child input[name=\"type\"]\n switch (type.toLowerCase()) {\n case 'hidden':\n return false\n case 'password':\n return false\n }\n }\n\n // filter out data from fields that look like sensitive fields\n const name = (el as HTMLInputElement).name || el.id || ''\n // See https://github.com/posthog/posthog-js/issues/165\n // Under specific circumstances a bug caused .replace to be called on a DOM element\n // instead of a string, removing the element from the page. Ensure this issue is mitigated.\n if (_isString(name)) {\n // it's possible for el.name or el.id to be a DOM element if el is a form with a child input[name=\"name\"]\n const sensitiveNameRegex =\n /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i\n if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) {\n return false\n }\n }\n\n return true\n}\n\n/*\n * Check whether a DOM element is 'sensitive' and we should only capture limited data\n * @param {Element} el - element to check\n * @returns {boolean} whether the element should be captured\n */\nexport function isSensitiveElement(el: Element): boolean {\n // don't send data from inputs or similar elements since there will always be\n // a risk of clientside javascript placing sensitive data in attributes\n const allowedInputTypes = ['button', 'checkbox', 'submit', 'reset']\n if (\n (isTag(el, 'input') && !allowedInputTypes.includes((el as HTMLInputElement).type)) ||\n isTag(el, 'select') ||\n isTag(el, 'textarea') ||\n el.getAttribute('contenteditable') === 'true'\n ) {\n return true\n }\n return false\n}\n\n/*\n * Check whether a string value should be \"captured\" or if it may contain sentitive data\n * using a variety of heuristics.\n * @param {string} value - string value to check\n * @returns {boolean} whether the element should be captured\n */\nexport function shouldCaptureValue(value: string): boolean {\n if (_isNull(value) || _isUndefined(value)) {\n return false\n }\n\n if (_isString(value)) {\n value = _trim(value)\n\n // check to see if input value looks like a credit card number\n // see: https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9781449327453/ch04s20.html\n const ccRegex =\n /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/\n if (ccRegex.test((value || '').replace(/[- ]/g, ''))) {\n return false\n }\n\n // check to see if input value looks like a social security number\n const ssnRegex = /(^\\d{3}-?\\d{2}-?\\d{4}$)/\n if (ssnRegex.test(value)) {\n return false\n }\n }\n\n return true\n}\n\n/*\n * Check whether an attribute name is an Angular style attr (either _ngcontent or _nghost)\n * These update on each build and lead to noise in the element chain\n * More details on the attributes here: https://angular.io/guide/view-encapsulation\n * @param {string} attributeName - string value to check\n * @returns {boolean} whether the element is an angular tag\n */\nexport function isAngularStyleAttr(attributeName: string): boolean {\n if (_isString(attributeName)) {\n return attributeName.substring(0, 10) === '_ngcontent' || attributeName.substring(0, 7) === '_nghost'\n }\n return false\n}\n\n/*\n * Iterate through children of a target element looking for span tags\n * and return the text content of the span tags, separated by spaces,\n * along with the direct text content of the target element\n * @param {Element} target - element to check\n * @returns {string} text content of the target element and its child span tags\n */\nexport function getDirectAndNestedSpanText(target: Element): string {\n let text = getSafeText(target)\n text = `${text} ${getNestedSpanText(target)}`.trim()\n return shouldCaptureValue(text) ? text : ''\n}\n\n/*\n * Iterate through children of a target element looking for span tags\n * and return the text content of the span tags, separated by spaces\n * @param {Element} target - element to check\n * @returns {string} text content of span tags\n */\nexport function getNestedSpanText(target: Element): string {\n let text = ''\n if (target && target.childNodes && target.childNodes.length) {\n _each(target.childNodes, function (child) {\n if (child && child.tagName?.toLowerCase() === 'span') {\n try {\n const spanText = getSafeText(child)\n text = `${text} ${spanText}`.trim()\n\n if (child.childNodes && child.childNodes.length) {\n text = `${text} ${getNestedSpanText(child)}`.trim()\n }\n } catch (e) {\n logger.error(e)\n }\n }\n })\n }\n return text\n}\n"]}
|
package/lib/src/autocapture.js
CHANGED
|
@@ -4,6 +4,7 @@ import RageClick from './extensions/rageclick';
|
|
|
4
4
|
import { AUTOCAPTURE_DISABLED_SERVER_SIDE } from './constants';
|
|
5
5
|
import { _isBoolean, _isFunction, _isNull, _isUndefined } from './utils/type-utils';
|
|
6
6
|
import { logger } from './utils/logger';
|
|
7
|
+
import { window, document } from './utils/globals';
|
|
7
8
|
function limitText(length, text) {
|
|
8
9
|
if (text.length > length) {
|
|
9
10
|
return text.slice(0, length) + '...';
|
|
@@ -104,7 +105,7 @@ var autocapture = {
|
|
|
104
105
|
},
|
|
105
106
|
_extractCustomPropertyValue: function (customProperty) {
|
|
106
107
|
var propValues = [];
|
|
107
|
-
_each(document.querySelectorAll(customProperty['css_selector']), function (matchedElem) {
|
|
108
|
+
_each(document === null || document === void 0 ? void 0 : document.querySelectorAll(customProperty['css_selector']), function (matchedElem) {
|
|
108
109
|
var value;
|
|
109
110
|
if (['input', 'select'].indexOf(matchedElem.tagName.toLowerCase()) > -1) {
|
|
110
111
|
value = matchedElem['value'];
|
|
@@ -124,7 +125,7 @@ var autocapture = {
|
|
|
124
125
|
var props = {}; // will be deleted
|
|
125
126
|
_each(this._customProperties, function (customProperty) {
|
|
126
127
|
_each(customProperty['event_selectors'], function (eventSelector) {
|
|
127
|
-
var eventElements = document.querySelectorAll(eventSelector);
|
|
128
|
+
var eventElements = document === null || document === void 0 ? void 0 : document.querySelectorAll(eventSelector);
|
|
128
129
|
_each(eventElements, function (eventElement) {
|
|
129
130
|
if (_includes(targetElementList, eventElement) && shouldCaptureElement(eventElement)) {
|
|
130
131
|
props[customProperty['name']] = _this._extractCustomPropertyValue(customProperty);
|
|
@@ -220,12 +221,18 @@ var autocapture = {
|
|
|
220
221
|
// only reason is to stub for unit tests
|
|
221
222
|
// since you can't override window.location props
|
|
222
223
|
_navigate: function (href) {
|
|
224
|
+
if (!window) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
223
227
|
window.location.href = href;
|
|
224
228
|
},
|
|
225
229
|
_addDomEventHandlers: function (instance) {
|
|
226
230
|
var _this = this;
|
|
231
|
+
if (!window || !document) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
227
234
|
var handler = function (e) {
|
|
228
|
-
e = e || window.event;
|
|
235
|
+
e = e || (window === null || window === void 0 ? void 0 : window.event);
|
|
229
236
|
_this._captureEvent(e, instance);
|
|
230
237
|
};
|
|
231
238
|
_register_event(document, 'submit', handler, false, true);
|
|
@@ -294,7 +301,7 @@ var autocapture = {
|
|
|
294
301
|
return charCodeSum % numBuckets < numEnabledBuckets;
|
|
295
302
|
},
|
|
296
303
|
isBrowserSupported: function () {
|
|
297
|
-
return _isFunction(document.querySelectorAll);
|
|
304
|
+
return _isFunction(document === null || document === void 0 ? void 0 : document.querySelectorAll);
|
|
298
305
|
},
|
|
299
306
|
};
|
|
300
307
|
_bind_instance_methods(autocapture);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocapture.js","sourceRoot":"","sources":["../../src/autocapture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AACxH,OAAO,EACH,YAAY,EACZ,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,KAAK,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,GAC7B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAG9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAA;AAE9D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,SAAS,SAAS,CAAC,MAAc,EAAE,IAAY;IAC3C,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,KAAK,CAAA;KACvC;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,IAAM,WAAW,GAAG;IAChB,kBAAkB,EAAE,EAAc;IAClC,qBAAqB,EAAE,IAAsB;IAC7C,qBAAqB,EAAE,KAAgB;IAEvC,wBAAwB,EAAE,UAAU,QAAiB;;QACjD,IAAM,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC;YAC5D,CAAC,CAAC,CAAC,CAAC,CAAA,MAAA,QAAQ,CAAC,WAAW,0CAAE,KAAK,CAAC,gCAAgC,CAAC,CAAA;YACjE,CAA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CAAC,CAAC,CAAA;SACrC;QACD,OAAO,WAAW,GAAG,UAAU,GAAG,iBAAiB,CAAA;IACvD,CAAC;IAED,kBAAkB,EAAE;QAChB,OAAO,WAAW,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;IACjD,CAAC;CACJ,CAAA;AAED,sBAAsB,CAAC,WAAW,CAAC,CAAA;AACnC,0BAA0B,CAAC,WAAW,CAAC,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,CAAA","sourcesContent":["import { _bind_instance_methods, _each, _extend, _includes, _register_event, _safewrap_instance_methods } from './utils'\nimport {\n getClassName,\n getSafeText,\n isElementNode,\n isSensitiveElement,\n isTag,\n isTextNode,\n shouldCaptureDomEvent,\n shouldCaptureElement,\n shouldCaptureValue,\n autocaptureCompatibleElements,\n isAngularStyleAttr,\n isDocumentFragment,\n getDirectAndNestedSpanText,\n} from './autocapture-utils'\nimport RageClick from './extensions/rageclick'\nimport { AutocaptureConfig, AutoCaptureCustomProperty, DecideResponse, Properties } from './types'\nimport { PostHog } from './posthog-core'\nimport { AUTOCAPTURE_DISABLED_SERVER_SIDE } from './constants'\n\nimport { _isBoolean, _isFunction, _isNull, _isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\n\nfunction limitText(length: number, text: string): string {\n if (text.length > length) {\n return text.slice(0, length) + '...'\n }\n return text\n}\n\nconst autocapture = {\n _initializedTokens: [] as string[],\n _isDisabledServerSide: null as boolean | null,\n _isAutocaptureEnabled: false as boolean,\n\n _setIsAutocaptureEnabled: function (instance: PostHog): void {\n const disabled_server_side = _isNull(this._isDisabledServerSide)\n ? !!instance.persistence?.props[AUTOCAPTURE_DISABLED_SERVER_SIDE]\n : this._isDisabledServerSide\n const enabled_client_side = !!instance.config.autocapture\n this._isAutocaptureEnabled = enabled_client_side && !disabled_server_side\n },\n\n _previousElementSibling: function (el: Element): Element | null {\n if (el.previousElementSibling) {\n return el.previousElementSibling\n } else {\n let _el: Element | null = el\n do {\n _el = _el.previousSibling as Element | null // resolves to ChildNode->Node, which is Element's parent class\n } while (_el && !isElementNode(_el))\n return _el\n }\n },\n\n _getAugmentPropertiesFromElement: function (elem: Element): Properties {\n const shouldCaptureEl = shouldCaptureElement(elem)\n if (!shouldCaptureEl) {\n return {}\n }\n\n const props: Properties = {}\n\n _each(elem.attributes, function (attr: Attr) {\n if (attr.name.indexOf('data-ph-capture-attribute') === 0) {\n const propertyKey = attr.name.replace('data-ph-capture-attribute-', '')\n const propertyValue = attr.value\n if (propertyKey && propertyValue && shouldCaptureValue(propertyValue)) {\n props[propertyKey] = propertyValue\n }\n }\n })\n return props\n },\n\n _getPropertiesFromElement: function (elem: Element, maskInputs: boolean, maskText: boolean): Properties {\n const tag_name = elem.tagName.toLowerCase()\n const props: Properties = {\n tag_name: tag_name,\n }\n if (autocaptureCompatibleElements.indexOf(tag_name) > -1 && !maskText) {\n if (tag_name.toLowerCase() === 'a' || tag_name.toLowerCase() === 'button') {\n props['$el_text'] = limitText(1024, getDirectAndNestedSpanText(elem))\n } else {\n props['$el_text'] = limitText(1024, getSafeText(elem))\n }\n }\n\n const classes = getClassName(elem)\n if (classes.length > 0)\n props['classes'] = classes.split(' ').filter(function (c) {\n return c !== ''\n })\n\n // capture the deny list here because this not-a-class class makes it tricky to use this.config in the function below\n const elementAttributeIgnorelist = this.config?.element_attribute_ignorelist\n _each(elem.attributes, function (attr: Attr) {\n // Only capture attributes we know are safe\n if (isSensitiveElement(elem) && ['name', 'id', 'class'].indexOf(attr.name) === -1) return\n\n if (elementAttributeIgnorelist?.includes(attr.name)) return\n\n if (!maskInputs && shouldCaptureValue(attr.value) && !isAngularStyleAttr(attr.name)) {\n props['attr__' + attr.name] = limitText(1024, attr.value)\n }\n })\n\n let nthChild = 1\n let nthOfType = 1\n let currentElem: Element | null = elem\n while ((currentElem = this._previousElementSibling(currentElem))) {\n // eslint-disable-line no-cond-assign\n nthChild++\n if (currentElem.tagName === elem.tagName) {\n nthOfType++\n }\n }\n props['nth_child'] = nthChild\n props['nth_of_type'] = nthOfType\n\n return props\n },\n\n _getDefaultProperties: function (eventType: string): Properties {\n return {\n $event_type: eventType,\n $ce_version: 1,\n }\n },\n\n _extractCustomPropertyValue: function (customProperty: AutoCaptureCustomProperty): string {\n const propValues: string[] = []\n _each(document.querySelectorAll(customProperty['css_selector']), function (matchedElem) {\n let value\n\n if (['input', 'select'].indexOf(matchedElem.tagName.toLowerCase()) > -1) {\n value = matchedElem['value']\n } else if (matchedElem['textContent']) {\n value = matchedElem['textContent']\n }\n\n if (shouldCaptureValue(value)) {\n propValues.push(value)\n }\n })\n return propValues.join(', ')\n },\n\n // TODO: delete custom_properties after changeless typescript refactor\n _getCustomProperties: function (targetElementList: Element[]): Properties {\n const props: Properties = {} // will be deleted\n _each(this._customProperties, (customProperty) => {\n _each(customProperty['event_selectors'], (eventSelector) => {\n const eventElements = document.querySelectorAll(eventSelector)\n _each(eventElements, (eventElement) => {\n if (_includes(targetElementList, eventElement) && shouldCaptureElement(eventElement)) {\n props[customProperty['name']] = this._extractCustomPropertyValue(customProperty)\n }\n })\n })\n })\n return props\n },\n\n _getEventTarget: function (e: Event): Element | null {\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/target#Compatibility_notes\n if (_isUndefined(e.target)) {\n return (e.srcElement as Element) || null\n } else {\n if ((e.target as HTMLElement)?.shadowRoot) {\n return (e.composedPath()[0] as Element) || null\n }\n return (e.target as Element) || null\n }\n },\n\n _captureEvent: function (e: Event, instance: PostHog, eventName = '$autocapture'): boolean | void {\n /*** Don't mess with this code without running IE8 tests on it ***/\n let target = this._getEventTarget(e)\n if (isTextNode(target)) {\n // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)\n target = (target.parentNode || null) as Element | null\n }\n\n if (eventName === '$autocapture' && e.type === 'click' && e instanceof MouseEvent) {\n if (this.rageclicks?.isRageClick(e.clientX, e.clientY, new Date().getTime())) {\n this._captureEvent(e, instance, '$rageclick')\n }\n }\n\n if (target && shouldCaptureDomEvent(target, e, this.config)) {\n const targetElementList = [target]\n let curEl = target\n while (curEl.parentNode && !isTag(curEl, 'body')) {\n if (isDocumentFragment(curEl.parentNode)) {\n targetElementList.push((curEl.parentNode as any).host)\n curEl = (curEl.parentNode as any).host\n continue\n }\n targetElementList.push(curEl.parentNode as Element)\n curEl = curEl.parentNode as Element\n }\n\n const elementsJson: Properties[] = []\n const autocaptureAugmentProperties: Properties = {}\n let href,\n explicitNoCapture = false\n _each(targetElementList, (el) => {\n const shouldCaptureEl = shouldCaptureElement(el)\n\n // if the element or a parent element is an anchor tag\n // include the href as a property\n if (el.tagName.toLowerCase() === 'a') {\n href = el.getAttribute('href')\n href = shouldCaptureEl && shouldCaptureValue(href) && href\n }\n\n // allow users to programmatically prevent capturing of elements by adding class 'ph-no-capture'\n const classes = getClassName(el).split(' ')\n if (_includes(classes, 'ph-no-capture')) {\n explicitNoCapture = true\n }\n\n elementsJson.push(\n this._getPropertiesFromElement(\n el,\n instance.config.mask_all_element_attributes,\n instance.config.mask_all_text\n )\n )\n\n const augmentProperties = this._getAugmentPropertiesFromElement(el)\n _extend(autocaptureAugmentProperties, augmentProperties)\n })\n\n if (!instance.config.mask_all_text) {\n // if the element is a button or anchor tag get the span text from any\n // children and include it as/with the text property on the parent element\n if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'button') {\n elementsJson[0]['$el_text'] = getDirectAndNestedSpanText(target)\n } else {\n elementsJson[0]['$el_text'] = getSafeText(target)\n }\n }\n\n if (href) {\n elementsJson[0]['attr__href'] = href\n }\n\n if (explicitNoCapture) {\n return false\n }\n\n const props = _extend(\n this._getDefaultProperties(e.type),\n {\n $elements: elementsJson,\n },\n elementsJson[0]?.['$el_text'] ? { $el_text: elementsJson[0]?.['$el_text'] } : {},\n this._getCustomProperties(targetElementList),\n autocaptureAugmentProperties\n )\n\n instance.capture(eventName, props)\n return true\n }\n },\n\n // only reason is to stub for unit tests\n // since you can't override window.location props\n _navigate: function (href: string): void {\n window.location.href = href\n },\n\n _addDomEventHandlers: function (instance: PostHog): void {\n const handler = (e: Event) => {\n e = e || window.event\n this._captureEvent(e, instance)\n }\n _register_event(document, 'submit', handler, false, true)\n _register_event(document, 'change', handler, false, true)\n _register_event(document, 'click', handler, false, true)\n },\n\n _customProperties: [] as AutoCaptureCustomProperty[],\n rageclicks: null as RageClick | null,\n config: undefined as AutocaptureConfig | undefined,\n\n init: function (instance: PostHog): void {\n if (!_isBoolean(instance.__autocapture)) {\n this.config = instance.__autocapture\n }\n\n // precompile the regex\n if (this.config?.url_allowlist) {\n this.config.url_allowlist = this.config.url_allowlist.map((url) => new RegExp(url))\n }\n\n this.rageclicks = new RageClick(instance.config.rageclick)\n },\n\n afterDecideResponse: function (response: DecideResponse, instance: PostHog): void {\n const token = instance.config.token\n if (this._initializedTokens.indexOf(token) > -1) {\n logger.info('autocapture already initialized for token \"' + token + '\"')\n return\n }\n\n if (instance.persistence) {\n instance.persistence.register({\n [AUTOCAPTURE_DISABLED_SERVER_SIDE]: !!response['autocapture_opt_out'],\n })\n }\n // store this in-memory incase persistence is disabled\n this._isDisabledServerSide = !!response['autocapture_opt_out']\n\n this._setIsAutocaptureEnabled(instance)\n\n this._initializedTokens.push(token)\n\n if (\n response &&\n response['config'] &&\n response['config']['enable_collect_everything'] &&\n this._isAutocaptureEnabled\n ) {\n // TODO: delete custom_properties after changeless typescript refactor\n if (response['custom_properties']) {\n this._customProperties = response['custom_properties']\n }\n this._addDomEventHandlers(instance)\n } else {\n instance['__autocapture'] = false\n }\n },\n\n // this is a mechanism to ramp up CE with no server-side interaction.\n // when CE is active, every page load results in a decide request. we\n // need to gently ramp this up, so we don't overload decide. this decides\n // deterministically if CE is enabled for this project by modding the char\n // value of the project token.\n enabledForProject: function (\n token: string | null | undefined,\n numBuckets: number,\n numEnabledBuckets: number\n ): boolean {\n if (!token) {\n return true\n }\n numBuckets = !_isUndefined(numBuckets) ? numBuckets : 10\n numEnabledBuckets = !_isUndefined(numEnabledBuckets) ? numEnabledBuckets : 10\n let charCodeSum = 0\n for (let i = 0; i < token.length; i++) {\n charCodeSum += token.charCodeAt(i)\n }\n return charCodeSum % numBuckets < numEnabledBuckets\n },\n\n isBrowserSupported: function (): boolean {\n return _isFunction(document.querySelectorAll)\n },\n}\n\n_bind_instance_methods(autocapture)\n_safewrap_instance_methods(autocapture)\n\nexport { autocapture }\n"]}
|
|
1
|
+
{"version":3,"file":"autocapture.js","sourceRoot":"","sources":["../../src/autocapture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AACxH,OAAO,EACH,YAAY,EACZ,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,KAAK,EACL,UAAU,EACV,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,GAC7B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAG9C,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAA;AAE9D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAElD,SAAS,SAAS,CAAC,MAAc,EAAE,IAAY;IAC3C,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,KAAK,CAAA;KACvC;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,IAAM,WAAW,GAAG;IAChB,kBAAkB,EAAE,EAAc;IAClC,qBAAqB,EAAE,IAAsB;IAC7C,qBAAqB,EAAE,KA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YACR,OAAO,IAAI,CAAA;SACd;QACD,UAAU,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAA;QACxD,iBAAiB,GAAG,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAA;QAC7E,IAAI,WAAW,GAAG,CAAC,CAAA;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,WAAW,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;SACrC;QACD,OAAO,WAAW,GAAG,UAAU,GAAG,iBAAiB,CAAA;IACvD,CAAC;IAED,kBAAkB,EAAE;QAChB,OAAO,WAAW,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,gBAAgB,CAAC,CAAA;IAClD,CAAC;CACJ,CAAA;AAED,sBAAsB,CAAC,WAAW,CAAC,CAAA;AACnC,0BAA0B,CAAC,WAAW,CAAC,CAAA;AAEvC,OAAO,EAAE,WAAW,EAAE,CAAA","sourcesContent":["import { _bind_instance_methods, _each, _extend, _includes, _register_event, _safewrap_instance_methods } from './utils'\nimport {\n getClassName,\n getSafeText,\n isElementNode,\n isSensitiveElement,\n isTag,\n isTextNode,\n shouldCaptureDomEvent,\n shouldCaptureElement,\n shouldCaptureValue,\n autocaptureCompatibleElements,\n isAngularStyleAttr,\n isDocumentFragment,\n getDirectAndNestedSpanText,\n} from './autocapture-utils'\nimport RageClick from './extensions/rageclick'\nimport { AutocaptureConfig, AutoCaptureCustomProperty, DecideResponse, Properties } from './types'\nimport { PostHog } from './posthog-core'\nimport { AUTOCAPTURE_DISABLED_SERVER_SIDE } from './constants'\n\nimport { _isBoolean, _isFunction, _isNull, _isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window, document } from './utils/globals'\n\nfunction limitText(length: number, text: string): string {\n if (text.length > length) {\n return text.slice(0, length) + '...'\n }\n return text\n}\n\nconst autocapture = {\n _initializedTokens: [] as string[],\n _isDisabledServerSide: null as boolean | null,\n _isAutocaptureEnabled: false as boolean,\n\n _setIsAutocaptureEnabled: function (instance: PostHog): void {\n const disabled_server_side = _isNull(this._isDisabledServerSide)\n ? !!instance.persistence?.props[AUTOCAPTURE_DISABLED_SERVER_SIDE]\n : this._isDisabledServerSide\n const enabled_client_side = !!instance.config.autocapture\n this._isAutocaptureEnabled = enabled_client_side && !disabled_server_side\n },\n\n _previousElementSibling: function (el: Element): Element | null {\n if (el.previousElementSibling) {\n return el.previousElementSibling\n } else {\n let _el: Element | null = el\n do {\n _el = _el.previousSibling as Element | null // resolves to ChildNode->Node, which is Element's parent class\n } while (_el && !isElementNode(_el))\n return _el\n }\n },\n\n _getAugmentPropertiesFromElement: function (elem: Element): Properties {\n const shouldCaptureEl = shouldCaptureElement(elem)\n if (!shouldCaptureEl) {\n return {}\n }\n\n const props: Properties = {}\n\n _each(elem.attributes, function (attr: Attr) {\n if (attr.name.indexOf('data-ph-capture-attribute') === 0) {\n const propertyKey = attr.name.replace('data-ph-capture-attribute-', '')\n const propertyValue = attr.value\n if (propertyKey && propertyValue && shouldCaptureValue(propertyValue)) {\n props[propertyKey] = propertyValue\n }\n }\n })\n return props\n },\n\n _getPropertiesFromElement: function (elem: Element, maskInputs: boolean, maskText: boolean): Properties {\n const tag_name = elem.tagName.toLowerCase()\n const props: Properties = {\n tag_name: tag_name,\n }\n if (autocaptureCompatibleElements.indexOf(tag_name) > -1 && !maskText) {\n if (tag_name.toLowerCase() === 'a' || tag_name.toLowerCase() === 'button') {\n props['$el_text'] = limitText(1024, getDirectAndNestedSpanText(elem))\n } else {\n props['$el_text'] = limitText(1024, getSafeText(elem))\n }\n }\n\n const classes = getClassName(elem)\n if (classes.length > 0)\n props['classes'] = classes.split(' ').filter(function (c) {\n return c !== ''\n })\n\n // capture the deny list here because this not-a-class class makes it tricky to use this.config in the function below\n const elementAttributeIgnorelist = this.config?.element_attribute_ignorelist\n _each(elem.attributes, function (attr: Attr) {\n // Only capture attributes we know are safe\n if (isSensitiveElement(elem) && ['name', 'id', 'class'].indexOf(attr.name) === -1) return\n\n if (elementAttributeIgnorelist?.includes(attr.name)) return\n\n if (!maskInputs && shouldCaptureValue(attr.value) && !isAngularStyleAttr(attr.name)) {\n props['attr__' + attr.name] = limitText(1024, attr.value)\n }\n })\n\n let nthChild = 1\n let nthOfType = 1\n let currentElem: Element | null = elem\n while ((currentElem = this._previousElementSibling(currentElem))) {\n // eslint-disable-line no-cond-assign\n nthChild++\n if (currentElem.tagName === elem.tagName) {\n nthOfType++\n }\n }\n props['nth_child'] = nthChild\n props['nth_of_type'] = nthOfType\n\n return props\n },\n\n _getDefaultProperties: function (eventType: string): Properties {\n return {\n $event_type: eventType,\n $ce_version: 1,\n }\n },\n\n _extractCustomPropertyValue: function (customProperty: AutoCaptureCustomProperty): string {\n const propValues: string[] = []\n _each(document?.querySelectorAll(customProperty['css_selector']), function (matchedElem) {\n let value\n\n if (['input', 'select'].indexOf(matchedElem.tagName.toLowerCase()) > -1) {\n value = matchedElem['value']\n } else if (matchedElem['textContent']) {\n value = matchedElem['textContent']\n }\n\n if (shouldCaptureValue(value)) {\n propValues.push(value)\n }\n })\n return propValues.join(', ')\n },\n\n // TODO: delete custom_properties after changeless typescript refactor\n _getCustomProperties: function (targetElementList: Element[]): Properties {\n const props: Properties = {} // will be deleted\n _each(this._customProperties, (customProperty) => {\n _each(customProperty['event_selectors'], (eventSelector) => {\n const eventElements = document?.querySelectorAll(eventSelector)\n _each(eventElements, (eventElement) => {\n if (_includes(targetElementList, eventElement) && shouldCaptureElement(eventElement)) {\n props[customProperty['name']] = this._extractCustomPropertyValue(customProperty)\n }\n })\n })\n })\n return props\n },\n\n _getEventTarget: function (e: Event): Element | null {\n // https://developer.mozilla.org/en-US/docs/Web/API/Event/target#Compatibility_notes\n if (_isUndefined(e.target)) {\n return (e.srcElement as Element) || null\n } else {\n if ((e.target as HTMLElement)?.shadowRoot) {\n return (e.composedPath()[0] as Element) || null\n }\n return (e.target as Element) || null\n }\n },\n\n _captureEvent: function (e: Event, instance: PostHog, eventName = '$autocapture'): boolean | void {\n /*** Don't mess with this code without running IE8 tests on it ***/\n let target = this._getEventTarget(e)\n if (isTextNode(target)) {\n // defeat Safari bug (see: http://www.quirksmode.org/js/events_properties.html)\n target = (target.parentNode || null) as Element | null\n }\n\n if (eventName === '$autocapture' && e.type === 'click' && e instanceof MouseEvent) {\n if (this.rageclicks?.isRageClick(e.clientX, e.clientY, new Date().getTime())) {\n this._captureEvent(e, instance, '$rageclick')\n }\n }\n\n if (target && shouldCaptureDomEvent(target, e, this.config)) {\n const targetElementList = [target]\n let curEl = target\n while (curEl.parentNode && !isTag(curEl, 'body')) {\n if (isDocumentFragment(curEl.parentNode)) {\n targetElementList.push((curEl.parentNode as any).host)\n curEl = (curEl.parentNode as any).host\n continue\n }\n targetElementList.push(curEl.parentNode as Element)\n curEl = curEl.parentNode as Element\n }\n\n const elementsJson: Properties[] = []\n const autocaptureAugmentProperties: Properties = {}\n let href,\n explicitNoCapture = false\n _each(targetElementList, (el) => {\n const shouldCaptureEl = shouldCaptureElement(el)\n\n // if the element or a parent element is an anchor tag\n // include the href as a property\n if (el.tagName.toLowerCase() === 'a') {\n href = el.getAttribute('href')\n href = shouldCaptureEl && shouldCaptureValue(href) && href\n }\n\n // allow users to programmatically prevent capturing of elements by adding class 'ph-no-capture'\n const classes = getClassName(el).split(' ')\n if (_includes(classes, 'ph-no-capture')) {\n explicitNoCapture = true\n }\n\n elementsJson.push(\n this._getPropertiesFromElement(\n el,\n instance.config.mask_all_element_attributes,\n instance.config.mask_all_text\n )\n )\n\n const augmentProperties = this._getAugmentPropertiesFromElement(el)\n _extend(autocaptureAugmentProperties, augmentProperties)\n })\n\n if (!instance.config.mask_all_text) {\n // if the element is a button or anchor tag get the span text from any\n // children and include it as/with the text property on the parent element\n if (target.tagName.toLowerCase() === 'a' || target.tagName.toLowerCase() === 'button') {\n elementsJson[0]['$el_text'] = getDirectAndNestedSpanText(target)\n } else {\n elementsJson[0]['$el_text'] = getSafeText(target)\n }\n }\n\n if (href) {\n elementsJson[0]['attr__href'] = href\n }\n\n if (explicitNoCapture) {\n return false\n }\n\n const props = _extend(\n this._getDefaultProperties(e.type),\n {\n $elements: elementsJson,\n },\n elementsJson[0]?.['$el_text'] ? { $el_text: elementsJson[0]?.['$el_text'] } : {},\n this._getCustomProperties(targetElementList),\n autocaptureAugmentProperties\n )\n\n instance.capture(eventName, props)\n return true\n }\n },\n\n // only reason is to stub for unit tests\n // since you can't override window.location props\n _navigate: function (href: string): void {\n if (!window) {\n return\n }\n window.location.href = href\n },\n\n _addDomEventHandlers: function (instance: PostHog): void {\n if (!window || !document) {\n return\n }\n const handler = (e: Event) => {\n e = e || window?.event\n this._captureEvent(e, instance)\n }\n _register_event(document, 'submit', handler, false, true)\n _register_event(document, 'change', handler, false, true)\n _register_event(document, 'click', handler, false, true)\n },\n\n _customProperties: [] as AutoCaptureCustomProperty[],\n rageclicks: null as RageClick | null,\n config: undefined as AutocaptureConfig | undefined,\n\n init: function (instance: PostHog): void {\n if (!_isBoolean(instance.__autocapture)) {\n this.config = instance.__autocapture\n }\n\n // precompile the regex\n if (this.config?.url_allowlist) {\n this.config.url_allowlist = this.config.url_allowlist.map((url) => new RegExp(url))\n }\n\n this.rageclicks = new RageClick(instance.config.rageclick)\n },\n\n afterDecideResponse: function (response: DecideResponse, instance: PostHog): void {\n const token = instance.config.token\n if (this._initializedTokens.indexOf(token) > -1) {\n logger.info('autocapture already initialized for token \"' + token + '\"')\n return\n }\n\n if (instance.persistence) {\n instance.persistence.register({\n [AUTOCAPTURE_DISABLED_SERVER_SIDE]: !!response['autocapture_opt_out'],\n })\n }\n // store this in-memory incase persistence is disabled\n this._isDisabledServerSide = !!response['autocapture_opt_out']\n\n this._setIsAutocaptureEnabled(instance)\n\n this._initializedTokens.push(token)\n\n if (\n response &&\n response['config'] &&\n response['config']['enable_collect_everything'] &&\n this._isAutocaptureEnabled\n ) {\n // TODO: delete custom_properties after changeless typescript refactor\n if (response['custom_properties']) {\n this._customProperties = response['custom_properties']\n }\n this._addDomEventHandlers(instance)\n } else {\n instance['__autocapture'] = false\n }\n },\n\n // this is a mechanism to ramp up CE with no server-side interaction.\n // when CE is active, every page load results in a decide request. we\n // need to gently ramp this up, so we don't overload decide. this decides\n // deterministically if CE is enabled for this project by modding the char\n // value of the project token.\n enabledForProject: function (\n token: string | null | undefined,\n numBuckets: number,\n numEnabledBuckets: number\n ): boolean {\n if (!token) {\n return true\n }\n numBuckets = !_isUndefined(numBuckets) ? numBuckets : 10\n numEnabledBuckets = !_isUndefined(numEnabledBuckets) ? numEnabledBuckets : 10\n let charCodeSum = 0\n for (let i = 0; i < token.length; i++) {\n charCodeSum += token.charCodeAt(i)\n }\n return charCodeSum % numBuckets < numEnabledBuckets\n },\n\n isBrowserSupported: function (): boolean {\n return _isFunction(document?.querySelectorAll)\n },\n}\n\n_bind_instance_methods(autocapture)\n_safewrap_instance_methods(autocapture)\n\nexport { autocapture }\n"]}
|
package/lib/src/decide.js
CHANGED
|
@@ -14,6 +14,7 @@ import { _base64Encode, loadScript } from './utils';
|
|
|
14
14
|
import { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants';
|
|
15
15
|
import { _isUndefined } from './utils/type-utils';
|
|
16
16
|
import { logger } from './utils/logger';
|
|
17
|
+
import { window, document, assignableWindow } from './utils/globals';
|
|
17
18
|
var Decide = /** @class */ (function () {
|
|
18
19
|
function Decide(instance) {
|
|
19
20
|
this.instance = instance;
|
|
@@ -100,7 +101,7 @@ var Decide = /** @class */ (function () {
|
|
|
100
101
|
apiHost,
|
|
101
102
|
apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,
|
|
102
103
|
].join('');
|
|
103
|
-
|
|
104
|
+
assignableWindow["__$$ph_site_app_".concat(id)] = this_1.instance;
|
|
104
105
|
loadScript(scriptUrl, function (err) {
|
|
105
106
|
if (err) {
|
|
106
107
|
logger.error("Error while initializing PostHog app with config id ".concat(id), err);
|
package/lib/src/decide.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/decide.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGnD,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/decide.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGnD,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAEvF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEpE;IAGI,gBAAY,QAAiB;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,qFAAqF;QACrF,IAAI,CAAC,QAAQ,CAAC,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC,4BAA4B,EAAE,CAAA;IACrF,CAAC;IAED,qBAAI,GAAJ;QAAA,iBAuBC;QAtBG;;UAEE;QACF,IAAM,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AAK,CAAC,8DAAuD,EAAE,CAAE,EAAE,GAAG,CAAC,CAAA;yBACjF;oBACL,CAAC,CAAC,CAAA;;;;oBAZN,KAA0B,IAAA,KAAA,SAAA,QAAQ,CAAC,UAAU,CAAC,CAAA,gBAAA;wBAAnC,IAAA,aAAW,EAAT,EAAE,QAAA,EAAE,GAAG,SAAA;gCAAP,EAAE,EAAE,GAAG;qBAanB;;;;;;;;;aACJ;iBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,MAAM,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;aACnG;SACJ;IACL,CAAC;IACL,aAAC;AAAD,CAAC,AAtHD,IAsHC","sourcesContent":["import { autocapture } from './autocapture'\nimport { _base64Encode, loadScript } from './utils'\nimport { PostHog } from './posthog-core'\nimport { DecideResponse } from './types'\nimport { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'\n\nimport { _isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window, document, assignableWindow } from './utils/globals'\n\nexport class Decide {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n // don't need to wait for `decide` to return if flags were provided on initialisation\n this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags()\n }\n\n call(): void {\n /*\n Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.\n */\n const json_data = JSON.stringify({\n token: this.instance.config.token,\n distinct_id: this.instance.get_distinct_id(),\n groups: this.instance.getGroups(),\n person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),\n group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),\n disable_flags:\n this.instance.config.advanced_disable_feature_flags ||\n this.instance.config.advanced_disable_feature_flags_on_first_load ||\n undefined,\n })\n\n const encoded_data = _base64Encode(json_data)\n this.instance._send_request(\n `${this.instance.config.api_host}/decide/?v=3`,\n { data: encoded_data, verbose: true },\n { method: 'POST' },\n (response) => this.parseDecideResponse(response as DecideResponse)\n )\n }\n\n parseDecideResponse(response: DecideResponse): void {\n this.instance.featureFlags.setReloadingPaused(false)\n // :TRICKY: Reload - start another request if queued!\n this.instance.featureFlags._startReloadTimer()\n\n if (response?.status === 0) {\n logger.error('Failed to fetch feature flags from PostHog.')\n return\n }\n if (!(document && document.body)) {\n logger.info('document not ready yet, trying again in 500 milliseconds...')\n setTimeout(() => {\n this.parseDecideResponse(response)\n }, 500)\n return\n }\n\n this.instance.toolbar.afterDecideResponse(response)\n this.instance.sessionRecording?.afterDecideResponse(response)\n autocapture.afterDecideResponse(response, this.instance)\n this.instance.webPerformance?.afterDecideResponse(response)\n this.instance._afterDecideResponse(response)\n\n if (!this.instance.config.advanced_disable_feature_flags_on_first_load) {\n this.instance.featureFlags.receivedFeatureFlags(response)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const surveysGenerator = window?.extendPostHogWithSurveys\n\n if (response['surveys'] && !surveysGenerator) {\n loadScript(this.instance.config.api_host + `/static/surveys.js`, (err) => {\n if (err) {\n return logger.error(`Could not load surveys script`, err)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.extendPostHogWithSurveys(this.instance)\n })\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const exceptionAutoCaptureAddedToWindow = window?.extendPostHogWithExceptionAutoCapture\n if (\n response['autocaptureExceptions'] &&\n !!response['autocaptureExceptions'] &&\n _isUndefined(exceptionAutoCaptureAddedToWindow)\n ) {\n loadScript(this.instance.config.api_host + `/static/exception-autocapture.js`, (err) => {\n if (err) {\n return logger.error(`Could not load exception autocapture script`, err)\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.extendPostHogWithExceptionAutocapture(this.instance, response)\n })\n }\n\n if (response['siteApps']) {\n if (this.instance.config.opt_in_site_apps) {\n const apiHost = this.instance.config.api_host\n for (const { id, url } of response['siteApps']) {\n const scriptUrl = [\n apiHost,\n apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,\n ].join('')\n\n assignableWindow[`__$$ph_site_app_${id}`] = this.instance\n\n loadScript(scriptUrl, (err) => {\n if (err) {\n logger.error(`Error while initializing PostHog app with config id ${id}`, err)\n }\n })\n }\n } else if (response['siteApps'].length > 0) {\n logger.error('PostHog site apps are disabled. Enable the \"opt_in_site_apps\" config to proceed.')\n }\n }\n }\n}\n"]}
|
|
@@ -29,7 +29,7 @@ var ExceptionObserver = /** @class */ (function () {
|
|
|
29
29
|
}
|
|
30
30
|
ExceptionObserver.prototype.startCapturing = function () {
|
|
31
31
|
var _a;
|
|
32
|
-
if (!this.isEnabled() || ((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__)) {
|
|
32
|
+
if (!window || !this.isEnabled() || ((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__)) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
@@ -55,7 +55,7 @@ var ExceptionObserver = /** @class */ (function () {
|
|
|
55
55
|
}
|
|
56
56
|
var errorProperties = unhandledRejectionToProperties(args);
|
|
57
57
|
this.sendExceptionEvent(errorProperties);
|
|
58
|
-
if (this.originalOnUnhandledRejectionHandler) {
|
|
58
|
+
if (window && this.originalOnUnhandledRejectionHandler) {
|
|
59
59
|
// eslint-disable-next-line prefer-rest-params
|
|
60
60
|
return this.originalOnUnhandledRejectionHandler.apply(window, args);
|
|
61
61
|
}
|
|
@@ -70,6 +70,9 @@ var ExceptionObserver = /** @class */ (function () {
|
|
|
70
70
|
};
|
|
71
71
|
ExceptionObserver.prototype.stopCapturing = function () {
|
|
72
72
|
var _a, _b;
|
|
73
|
+
if (!window) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
73
76
|
if (!_isUndefined(this.originalOnErrorHandler)) {
|
|
74
77
|
window.onerror = this.originalOnErrorHandler;
|
|
75
78
|
this.originalOnErrorHandler = null;
|
|
@@ -83,7 +86,7 @@ var ExceptionObserver = /** @class */ (function () {
|
|
|
83
86
|
};
|
|
84
87
|
ExceptionObserver.prototype.isCapturing = function () {
|
|
85
88
|
var _a;
|
|
86
|
-
return !!((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__);
|
|
89
|
+
return !!((_a = window === null || window === void 0 ? void 0 : window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__);
|
|
87
90
|
};
|
|
88
91
|
ExceptionObserver.prototype.isEnabled = function () {
|
|
89
92
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/exception-autocapture/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAG5C,OAAO,EAAmC,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAA;AACvH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3C,IAAM,4BAA4B,GAAG,KAAK,CAAA;AAE1C,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,QAAiB,EAAE,QAAwB;IACrE,IAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IACzD,iBAAiB,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAC/C,OAAO,iBAAiB,CAAA;AAC5B,CAAC,CAAA;AAED;IAQI,2BAAY,QAAiB;QALrB,2BAAsB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/exception-autocapture/index.ts"],"names":[],"mappings":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A;QAE/C,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB,IAAI,EAAE,CAAC,EAApD,CAAoD,CAAC,EAAE;YAC3F,MAAM,CAAC,IAAI,CAAC,+DAA+D,EAAE,eAAe,CAAC,CAAA;YAC7F,OAAM;SACT;QAED,IAAM,gBAAgB,yBAAQ,UAAU,GAAK,eAAe,CAAE,CAAA;QAE9D,IAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAA;QACjF,eAAe,CAAC,oBAAoB,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAA;QAEjG,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IAC7C,CAAC;IAED;;OAEG;IACH,8CAAkB,GAAlB,UAAmB,UAAkC;QACjD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE;YAC5C,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,4BAA4B;YACtC,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,gBAAgB;SAC9B,CAAC,CAAA;IACN,CAAC;IACL,wBAAC;AAAD,CAAC,AApID,IAoIC","sourcesContent":["import { window } from '../../utils/globals'\nimport { PostHog } from '../../posthog-core'\nimport { DecideResponse, Properties } from '../../types'\nimport { ErrorEventArgs, ErrorProperties, errorToProperties, unhandledRejectionToProperties } from './error-conversion'\nimport { isPrimitive } from './type-checking'\n\nimport { _isArray, _isObject, _isUndefined } from '../../utils/type-utils'\nimport { logger } from '../../utils/logger'\n\nconst EXCEPTION_INGESTION_ENDPOINT = '/e/'\n\nexport const extendPostHog = (instance: PostHog, response: DecideResponse) => {\n const exceptionObserver = new ExceptionObserver(instance)\n exceptionObserver.afterDecideResponse(response)\n return exceptionObserver\n}\n\nexport class ExceptionObserver {\n instance: PostHog\n remoteEnabled: boolean | undefined\n private originalOnErrorHandler: Window['onerror'] | null | undefined = undefined\n private originalOnUnhandledRejectionHandler: Window['onunhandledrejection'] | null | undefined = undefined\n\n private errorsToIgnore: RegExp[] = []\n\n constructor(instance: PostHog) {\n this.instance = instance\n }\n\n startCapturing() {\n if (!window || !this.isEnabled() || (window.onerror as any)?.__POSTHOG_INSTRUMENTED__) {\n return\n }\n\n try {\n this.originalOnErrorHandler = window.onerror\n\n window.onerror = function (this: ExceptionObserver, ...args: ErrorEventArgs): boolean {\n this.captureException(args)\n\n if (this.originalOnErrorHandler) {\n // eslint-disable-next-line prefer-rest-params\n return this.originalOnErrorHandler.apply(this, args)\n }\n\n return false\n }.bind(this)\n ;(window.onerror as any).__POSTHOG_INSTRUMENTED__ = true\n\n this.originalOnUnhandledRejectionHandler = window.onunhandledrejection\n\n window.onunhandledrejection = function (\n this: ExceptionObserver,\n ...args: [ev: PromiseRejectionEvent]\n ): boolean {\n const errorProperties: ErrorProperties = unhandledRejectionToProperties(args)\n this.sendExceptionEvent(errorProperties)\n\n if (window && this.originalOnUnhandledRejectionHandler) {\n // eslint-disable-next-line prefer-rest-params\n return this.originalOnUnhandledRejectionHandler.apply(window, args)\n }\n\n return true\n }.bind(this)\n ;(window.onunhandledrejection as any).__POSTHOG_INSTRUMENTED__ = true\n } catch (e) {\n logger.error('PostHog failed to start exception autocapture', e)\n this.stopCapturing()\n }\n }\n\n stopCapturing() {\n if (!window) {\n return\n }\n if (!_isUndefined(this.originalOnErrorHandler)) {\n window.onerror = this.originalOnErrorHandler\n this.originalOnErrorHandler = null\n }\n delete (window.onerror as any)?.__POSTHOG_INSTRUMENTED__\n\n if (!_isUndefined(this.originalOnUnhandledRejectionHandler)) {\n window.onunhandledrejection = this.originalOnUnhandledRejectionHandler\n this.originalOnUnhandledRejectionHandler = null\n }\n delete (window.onunhandledrejection as any)?.__POSTHOG_INSTRUMENTED__\n }\n\n isCapturing() {\n return !!(window?.onerror as any)?.__POSTHOG_INSTRUMENTED__\n }\n\n isEnabled() {\n return this.remoteEnabled ?? false\n }\n\n afterDecideResponse(response: DecideResponse) {\n const autocaptureExceptionsResponse = response.autocaptureExceptions\n this.remoteEnabled = !!autocaptureExceptionsResponse || false\n if (\n !isPrimitive(autocaptureExceptionsResponse) &&\n 'errors_to_ignore' in autocaptureExceptionsResponse &&\n _isArray(autocaptureExceptionsResponse.errors_to_ignore)\n ) {\n const dropRules = autocaptureExceptionsResponse.errors_to_ignore\n\n this.errorsToIgnore = dropRules.map((rule) => {\n return new RegExp(rule)\n })\n }\n\n if (this.isEnabled()) {\n this.startCapturing()\n logger.info(\n '[Exception Capture] Remote config for exception autocapture is enabled, starting with config: ',\n _isObject(autocaptureExceptionsResponse) ? autocaptureExceptionsResponse : {}\n )\n }\n }\n\n captureException(args: ErrorEventArgs, properties?: Properties) {\n const errorProperties = errorToProperties(args)\n\n if (this.errorsToIgnore.some((regex) => regex.test(errorProperties.$exception_message || ''))) {\n logger.info('[Exception Capture] Ignoring exception based on remote config', errorProperties)\n return\n }\n\n const propertiesToSend = { ...properties, ...errorProperties }\n\n const posthogHost = this.instance.config.ui_host || this.instance.config.api_host\n errorProperties.$exception_personURL = posthogHost + '/person/' + this.instance.get_distinct_id()\n\n this.sendExceptionEvent(propertiesToSend)\n }\n\n /**\n * :TRICKY: Make sure we batch these requests\n */\n sendExceptionEvent(properties: { [key: string]: any }) {\n this.instance.capture('$exception', properties, {\n transport: 'XHR',\n method: 'POST',\n endpoint: EXCEPTION_INGESTION_ENDPOINT,\n _noTruncate: true,\n _batchKey: 'exceptionEvent',\n })\n }\n}\n"]}
|
|
@@ -43,7 +43,7 @@ import Config from '../../config';
|
|
|
43
43
|
import { _timestamp, loadScript } from '../../utils';
|
|
44
44
|
import { _isBoolean, _isFunction, _isNull, _isNumber, _isObject, _isString, _isUndefined } from '../../utils/type-utils';
|
|
45
45
|
import { logger } from '../../utils/logger';
|
|
46
|
-
import { window } from '../../utils/globals';
|
|
46
|
+
import { assignableWindow, window } from '../../utils/globals';
|
|
47
47
|
import { buildNetworkRequestOptions } from './config';
|
|
48
48
|
var BASE_ENDPOINT = '/s/';
|
|
49
49
|
export var RECORDING_IDLE_ACTIVITY_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
|
|
@@ -99,7 +99,7 @@ var SessionRecording = /** @class */ (function () {
|
|
|
99
99
|
this._endpoint = BASE_ENDPOINT;
|
|
100
100
|
this.stopRrweb = undefined;
|
|
101
101
|
this.receivedDecide = false;
|
|
102
|
-
window.addEventListener('beforeunload', function () {
|
|
102
|
+
window === null || window === void 0 ? void 0 : window.addEventListener('beforeunload', function () {
|
|
103
103
|
_this._flushBuffer();
|
|
104
104
|
});
|
|
105
105
|
if (!this.instance.sessionManager) {
|
|
@@ -153,7 +153,7 @@ var SessionRecording = /** @class */ (function () {
|
|
|
153
153
|
get: function () {
|
|
154
154
|
var enabled_server_side = !!this.instance.get_property(SESSION_RECORDING_ENABLED_SERVER_SIDE);
|
|
155
155
|
var enabled_client_side = !this.instance.config.disable_session_recording;
|
|
156
|
-
return enabled_server_side && enabled_client_side;
|
|
156
|
+
return window && enabled_server_side && enabled_client_side;
|
|
157
157
|
},
|
|
158
158
|
enumerable: false,
|
|
159
159
|
configurable: true
|
|
@@ -470,11 +470,11 @@ var SessionRecording = /** @class */ (function () {
|
|
|
470
470
|
},
|
|
471
471
|
});
|
|
472
472
|
var plugins = [];
|
|
473
|
-
if (
|
|
474
|
-
plugins.push(
|
|
473
|
+
if (assignableWindow.rrwebConsoleRecord && this.isConsoleLogCaptureEnabled) {
|
|
474
|
+
plugins.push(assignableWindow.rrwebConsoleRecord.getRecordConsolePlugin());
|
|
475
475
|
}
|
|
476
|
-
if (this.networkPayloadCapture && _isFunction(
|
|
477
|
-
plugins.push(
|
|
476
|
+
if (this.networkPayloadCapture && _isFunction(assignableWindow.getRecordNetworkPlugin)) {
|
|
477
|
+
plugins.push(assignableWindow.getRecordNetworkPlugin(buildNetworkRequestOptions(this.instance.config, this.networkPayloadCapture)));
|
|
478
478
|
}
|
|
479
479
|
this.stopRrweb = this.rrwebRecord(__assign({ emit: function (event) {
|
|
480
480
|
_this.onRRwebEmit(event);
|
|
@@ -487,7 +487,7 @@ var SessionRecording = /** @class */ (function () {
|
|
|
487
487
|
// so we catch all errors.
|
|
488
488
|
try {
|
|
489
489
|
if (eventName === '$pageview') {
|
|
490
|
-
var href = _this._maskUrl(window.location.href);
|
|
490
|
+
var href = window ? _this._maskUrl(window.location.href) : '';
|
|
491
491
|
if (!href) {
|
|
492
492
|
return;
|
|
493
493
|
}
|