@amplitude/plugin-autocapture-browser 1.11.1 → 1.12.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.
Files changed (86) hide show
  1. package/README.md +6 -0
  2. package/lib/cjs/autocapture-plugin.d.ts.map +1 -1
  3. package/lib/cjs/autocapture-plugin.js +23 -5
  4. package/lib/cjs/autocapture-plugin.js.map +1 -1
  5. package/lib/cjs/constants.d.ts +3 -0
  6. package/lib/cjs/constants.d.ts.map +1 -1
  7. package/lib/cjs/constants.js +6 -1
  8. package/lib/cjs/constants.js.map +1 -1
  9. package/lib/cjs/data-extractor.d.ts +3 -2
  10. package/lib/cjs/data-extractor.d.ts.map +1 -1
  11. package/lib/cjs/data-extractor.js +92 -52
  12. package/lib/cjs/data-extractor.js.map +1 -1
  13. package/lib/cjs/helpers.d.ts +15 -1
  14. package/lib/cjs/helpers.d.ts.map +1 -1
  15. package/lib/cjs/helpers.js +34 -6
  16. package/lib/cjs/helpers.js.map +1 -1
  17. package/lib/cjs/hierarchy.d.ts +3 -14
  18. package/lib/cjs/hierarchy.d.ts.map +1 -1
  19. package/lib/cjs/hierarchy.js +14 -108
  20. package/lib/cjs/hierarchy.js.map +1 -1
  21. package/lib/cjs/index.d.ts +1 -0
  22. package/lib/cjs/index.d.ts.map +1 -1
  23. package/lib/cjs/index.js +3 -1
  24. package/lib/cjs/index.js.map +1 -1
  25. package/lib/cjs/libs/messenger.d.ts.map +1 -1
  26. package/lib/cjs/libs/messenger.js +1 -0
  27. package/lib/cjs/libs/messenger.js.map +1 -1
  28. package/lib/cjs/pageActions/actions.d.ts +2 -2
  29. package/lib/cjs/pageActions/actions.d.ts.map +1 -1
  30. package/lib/cjs/pageActions/actions.js.map +1 -1
  31. package/lib/cjs/version.d.ts +1 -1
  32. package/lib/cjs/version.js +1 -1
  33. package/lib/cjs/version.js.map +1 -1
  34. package/lib/esm/autocapture-plugin.d.ts.map +1 -1
  35. package/lib/esm/autocapture-plugin.js +23 -5
  36. package/lib/esm/autocapture-plugin.js.map +1 -1
  37. package/lib/esm/constants.d.ts +3 -0
  38. package/lib/esm/constants.d.ts.map +1 -1
  39. package/lib/esm/constants.js +5 -0
  40. package/lib/esm/constants.js.map +1 -1
  41. package/lib/esm/data-extractor.d.ts +3 -2
  42. package/lib/esm/data-extractor.d.ts.map +1 -1
  43. package/lib/esm/data-extractor.js +95 -55
  44. package/lib/esm/data-extractor.js.map +1 -1
  45. package/lib/esm/helpers.d.ts +15 -1
  46. package/lib/esm/helpers.d.ts.map +1 -1
  47. package/lib/esm/helpers.js +31 -4
  48. package/lib/esm/helpers.js.map +1 -1
  49. package/lib/esm/hierarchy.d.ts +3 -14
  50. package/lib/esm/hierarchy.d.ts.map +1 -1
  51. package/lib/esm/hierarchy.js +14 -105
  52. package/lib/esm/hierarchy.js.map +1 -1
  53. package/lib/esm/index.d.ts +1 -0
  54. package/lib/esm/index.d.ts.map +1 -1
  55. package/lib/esm/index.js +1 -0
  56. package/lib/esm/index.js.map +1 -1
  57. package/lib/esm/libs/messenger.d.ts.map +1 -1
  58. package/lib/esm/libs/messenger.js +1 -0
  59. package/lib/esm/libs/messenger.js.map +1 -1
  60. package/lib/esm/pageActions/actions.d.ts +2 -2
  61. package/lib/esm/pageActions/actions.d.ts.map +1 -1
  62. package/lib/esm/pageActions/actions.js.map +1 -1
  63. package/lib/esm/version.d.ts +1 -1
  64. package/lib/esm/version.js +1 -1
  65. package/lib/esm/version.js.map +1 -1
  66. package/lib/scripts/amplitude-min.js +1 -1
  67. package/lib/scripts/amplitude-min.js.gz +0 -0
  68. package/lib/scripts/amplitude-min.js.map +1 -1
  69. package/lib/scripts/amplitude-min.umd.js +1 -1
  70. package/lib/scripts/amplitude-min.umd.js.gz +0 -0
  71. package/lib/scripts/autocapture-plugin.d.ts.map +1 -1
  72. package/lib/scripts/constants.d.ts +3 -0
  73. package/lib/scripts/constants.d.ts.map +1 -1
  74. package/lib/scripts/data-extractor.d.ts +3 -2
  75. package/lib/scripts/data-extractor.d.ts.map +1 -1
  76. package/lib/scripts/helpers.d.ts +15 -1
  77. package/lib/scripts/helpers.d.ts.map +1 -1
  78. package/lib/scripts/hierarchy.d.ts +3 -14
  79. package/lib/scripts/hierarchy.d.ts.map +1 -1
  80. package/lib/scripts/index.d.ts +1 -0
  81. package/lib/scripts/index.d.ts.map +1 -1
  82. package/lib/scripts/libs/messenger.d.ts.map +1 -1
  83. package/lib/scripts/pageActions/actions.d.ts +2 -2
  84. package/lib/scripts/pageActions/actions.d.ts.map +1 -1
  85. package/lib/scripts/version.d.ts +1 -1
  86. package/package.json +3 -3
@@ -1,3 +1,4 @@
1
+ import { __read } from "tslib";
1
2
  /* eslint-disable no-restricted-globals */
2
3
  import { isUrlMatchAllowlist } from '@amplitude/analytics-core';
3
4
  var SENSITIVE_TAGS = ['input', 'select', 'textarea'];
@@ -13,7 +14,7 @@ isAlwaysCaptureCursorPointer) {
13
14
  if (isAlwaysCaptureCursorPointer === void 0) { isAlwaysCaptureCursorPointer = false; }
14
15
  return function (actionType, element) {
15
16
  var _a, _b;
16
- var pageUrlAllowlist = autocaptureOptions.pageUrlAllowlist, shouldTrackEventResolver = autocaptureOptions.shouldTrackEventResolver;
17
+ var pageUrlAllowlist = autocaptureOptions.pageUrlAllowlist, pageUrlExcludelist = autocaptureOptions.pageUrlExcludelist, shouldTrackEventResolver = autocaptureOptions.shouldTrackEventResolver;
17
18
  /* istanbul ignore next */
18
19
  var tag = (_b = (_a = element === null || element === void 0 ? void 0 : element.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase) === null || _b === void 0 ? void 0 : _b.call(_a);
19
20
  // window, document, and Text nodes have no tag
@@ -23,9 +24,16 @@ isAlwaysCaptureCursorPointer) {
23
24
  if (shouldTrackEventResolver) {
24
25
  return shouldTrackEventResolver(actionType, element);
25
26
  }
27
+ // check if the URL is in the allow list
26
28
  if (!isUrlMatchAllowlist(window.location.href, pageUrlAllowlist)) {
27
29
  return false;
28
30
  }
31
+ // check if the URL is in the excludelist
32
+ if (pageUrlExcludelist &&
33
+ pageUrlExcludelist.length > 0 &&
34
+ isUrlMatchAllowlist(window.location.href, pageUrlExcludelist)) {
35
+ return false;
36
+ }
29
37
  /* istanbul ignore next */
30
38
  var elementType = String(element === null || element === void 0 ? void 0 : element.getAttribute('type')) || '';
31
39
  if (typeof elementType === 'string') {
@@ -73,11 +81,30 @@ export var isNonSensitiveElement = function (element) {
73
81
  var isContentEditable = element instanceof HTMLElement ? ((_c = element.getAttribute('contenteditable')) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'true' : false;
74
82
  return !SENSITIVE_TAGS.includes(tag) && !isContentEditable;
75
83
  };
76
- export var getAttributesWithPrefix = function (element, prefix) {
77
- return element.getAttributeNames().reduce(function (attributes, attributeName) {
84
+ /**
85
+ * Collects redacted attribute names from element and ancestor elements with data-amp-mask-attributes
86
+ * The 'id' and 'class' attributes cannot be redacted as they're critical for element identification
87
+ * @param element - The target element to check for redaction attributes
88
+ * @returns Set of attribute names that should be redacted
89
+ */
90
+ /**
91
+ * Parses a comma-separated string of attribute names and filters out protected attributes
92
+ * @param attributeString - Comma-separated string of attribute names
93
+ * @returns Array of valid attribute names, excluding 'id' and 'class'
94
+ */
95
+ export var parseAttributesToMask = function (attributeString) {
96
+ return attributeString
97
+ ? attributeString
98
+ .split(',')
99
+ .map(function (attr) { return attr.trim(); })
100
+ .filter(function (attr) { return attr.length > 0 && attr !== 'id' && attr !== 'class'; }) // Prevent 'id' and 'class' from being redacted as they're critical for element identification
101
+ : [];
102
+ };
103
+ export var extractPrefixedAttributes = function (attrs, prefix) {
104
+ return Object.entries(attrs).reduce(function (attributes, _a) {
105
+ var _b = __read(_a, 2), attributeName = _b[0], attributeValue = _b[1];
78
106
  if (attributeName.startsWith(prefix)) {
79
107
  var attributeKey = attributeName.replace(prefix, '');
80
- var attributeValue = element.getAttribute(attributeName);
81
108
  if (attributeKey) {
82
109
  attributes[attributeKey] = attributeValue || '';
83
110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AC;AAEF,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAG,IAAI,CAAC,GAAG,EAAE,cAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAC;AACpE,CAAC;AAED,MAAM,CAAC,IAAM,2BAA2B,GAAG,UAAC,KAAsD;IAChG,+CAA+C;IAC/C,sEAAsE;IACtE,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE;QAChE,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA8BF,iBAAiB;AACjB,MAAM,UAAU,mBAAmB,CAAI,KAA8B;IACnE,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC3D,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport { ElementInteractionsOptions, ActionType, isUrlMatchAllowlist } from '@amplitude/analytics-core';\n\nexport type JSONValue = string | number | boolean | null | { [x: string]: JSONValue } | Array<JSONValue>;\n\nconst SENSITIVE_TAGS = ['input', 'select', 'textarea'];\n\nexport type shouldTrackEvent = (actionType: ActionType, element: Element) => boolean;\n\nexport const isElementPointerCursor = (element: Element, actionType: ActionType): boolean => {\n /* istanbul ignore next */\n const computedStyle = window?.getComputedStyle?.(element);\n /* istanbul ignore next */\n return computedStyle?.getPropertyValue('cursor') === 'pointer' && actionType === 'click';\n};\n\nexport const createShouldTrackEvent = (\n autocaptureOptions: ElementInteractionsOptions,\n allowlist: string[], // this can be any type of css selector allow list\n isAlwaysCaptureCursorPointer = false,\n): shouldTrackEvent => {\n return (actionType: ActionType, element: Element) => {\n const { pageUrlAllowlist, shouldTrackEventResolver } = autocaptureOptions;\n\n /* istanbul ignore next */\n const tag = element?.tagName?.toLowerCase?.();\n // window, document, and Text nodes have no tag\n if (!tag) {\n return false;\n }\n\n if (shouldTrackEventResolver) {\n return shouldTrackEventResolver(actionType, element);\n }\n\n if (!isUrlMatchAllowlist(window.location.href, pageUrlAllowlist)) {\n return false;\n }\n\n /* istanbul ignore next */\n const elementType = String(element?.getAttribute('type')) || '';\n if (typeof elementType === 'string') {\n switch (elementType.toLowerCase()) {\n case 'hidden':\n return false;\n case 'password':\n return false;\n }\n }\n\n const isCursorPointer = isElementPointerCursor(element, actionType);\n\n if (isAlwaysCaptureCursorPointer && isCursorPointer) {\n return true;\n }\n\n /* istanbul ignore if */\n if (allowlist) {\n const hasMatchAnyAllowedSelector = allowlist.some((selector) => !!element?.matches?.(selector));\n if (!hasMatchAnyAllowedSelector) {\n return false;\n }\n }\n\n switch (tag) {\n case 'input':\n case 'select':\n case 'textarea':\n return actionType === 'change' || actionType === 'click';\n default: {\n /* istanbul ignore next */\n /* istanbul ignore next */\n if (isCursorPointer) {\n return true;\n }\n return actionType === 'click';\n }\n }\n };\n};\n\nexport const isTextNode = (node: Node) => {\n return !!node && node.nodeType === 3;\n};\n\nexport const isNonSensitiveElement = (element: Element) => {\n /* istanbul ignore next */\n const tag = element?.tagName?.toLowerCase?.();\n const isContentEditable =\n element instanceof HTMLElement ? element.getAttribute('contenteditable')?.toLowerCase() === 'true' : false;\n\n return !SENSITIVE_TAGS.includes(tag) && !isContentEditable;\n};\n\nexport const getAttributesWithPrefix = (element: Element, prefix: string): { [key: string]: string } => {\n return element.getAttributeNames().reduce((attributes: { [key: string]: string }, attributeName) => {\n if (attributeName.startsWith(prefix)) {\n const attributeKey = attributeName.replace(prefix, '');\n const attributeValue = element.getAttribute(attributeName);\n if (attributeKey) {\n attributes[attributeKey] = attributeValue || '';\n }\n }\n return attributes;\n }, {});\n};\n\nexport const isEmpty = (value: unknown) => {\n return (\n value === undefined ||\n value === null ||\n (typeof value === 'object' && Object.keys(value).length === 0) ||\n (typeof value === 'string' && value.trim().length === 0)\n );\n};\n\nexport const removeEmptyProperties = (properties: { [key: string]: unknown }): { [key: string]: unknown } => {\n return Object.keys(properties).reduce((filteredProperties: { [key: string]: unknown }, key) => {\n const value = properties[key];\n if (!isEmpty(value)) {\n filteredProperties[key] = value;\n }\n return filteredProperties;\n }, {});\n};\n\nexport const querySelectUniqueElements = (root: Element | Document, selectors: string[]): Element[] => {\n if (root && 'querySelectorAll' in root && typeof root.querySelectorAll === 'function') {\n const elementSet = selectors.reduce((elements: Set<Element>, selector) => {\n if (selector) {\n const selectedElements = Array.from(root.querySelectorAll(selector));\n selectedElements.forEach((element) => {\n elements.add(element);\n });\n }\n return elements;\n }, new Set<Element>());\n return Array.from(elementSet);\n }\n return [];\n};\n\n// Similar as element.closest, but works with multiple selectors\nexport const getClosestElement = (element: Element | null, selectors: string[]): Element | null => {\n if (!element) {\n return null;\n }\n /* istanbul ignore next */\n if (selectors.some((selector) => element?.matches?.(selector))) {\n return element;\n }\n /* istanbul ignore next */\n return getClosestElement(element?.parentElement, selectors);\n};\n\nexport const asyncLoadScript = (url: string) => {\n return new Promise((resolve, reject) => {\n try {\n const scriptElement = document.createElement('script');\n scriptElement.type = 'text/javascript';\n scriptElement.async = true;\n scriptElement.src = url;\n scriptElement.addEventListener(\n 'load',\n () => {\n resolve({ status: true });\n },\n { once: true },\n );\n scriptElement.addEventListener('error', () => {\n reject({\n status: false,\n message: `Failed to load the script ${url}`,\n });\n });\n /* istanbul ignore next */\n document.head?.appendChild(scriptElement);\n } catch (error) {\n /* istanbul ignore next */\n reject(error);\n }\n });\n};\n\nexport function generateUniqueId(): string {\n return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n}\n\nexport const filterOutNonTrackableEvents = (event: ElementBasedTimestampedEvent<ElementBasedEvent>): boolean => {\n // Filter out changeEvent events with no target\n // This could happen when change events are triggered programmatically\n if (event.event.target === null || !event.closestTrackedAncestor) {\n return false;\n }\n\n return true;\n};\n\nexport type AutoCaptureOptionsWithDefaults = Required<\n Pick<ElementInteractionsOptions, 'debounceTime' | 'cssSelectorAllowlist' | 'actionClickAllowlist'>\n> &\n ElementInteractionsOptions;\n\n// Base TimestampedEvent type\nexport type BaseTimestampedEvent<T> = {\n event: T;\n timestamp: number;\n type: 'rage' | 'click' | 'change' | 'error' | 'navigate' | 'mutation';\n};\n\n// Specific types for events with targetElementProperties\nexport type ElementBasedEvent = MouseEvent | Event;\nexport type ElementBasedTimestampedEvent<T> = BaseTimestampedEvent<T> & {\n event: MouseEvent | Event;\n type: 'click' | 'change';\n closestTrackedAncestor: Element;\n targetElementProperties: Record<string, any>;\n};\n\nexport type evaluateTriggersFn = (\n event: ElementBasedTimestampedEvent<ElementBasedEvent>,\n) => ElementBasedTimestampedEvent<ElementBasedEvent>;\n\n// Union type for all possible TimestampedEvents\nexport type TimestampedEvent<T> = BaseTimestampedEvent<T> | ElementBasedTimestampedEvent<T>;\n\n// Type predicate\nexport function isElementBasedEvent<T>(event: BaseTimestampedEvent<T>): event is ElementBasedTimestampedEvent<T> {\n return event.type === 'click' || event.type === 'change';\n}\n\nexport interface NavigateEvent extends Event {\n readonly navigationType: 'reload' | 'push' | 'replace' | 'traverse';\n readonly destination: {\n readonly url: string;\n readonly key: string | null;\n readonly id: string | null;\n readonly index: number;\n readonly sameDocument: boolean;\n\n getState(): any;\n };\n readonly canIntercept: boolean;\n readonly userInitiated: boolean;\n readonly hashChange: boolean;\n readonly signal: AbortSignal;\n readonly formData: FormData | null;\n readonly downloadRequest: string | null;\n readonly info: any;\n readonly hasUAVisualTransition: boolean;\n /** @see https://github.com/WICG/navigation-api/pull/264 */\n readonly sourceElement: Element | null;\n\n scroll(): void;\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,OAAO,EAA0C,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAIxG,IAAM,cAAc,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AAIvD,MAAM,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B,CAAC,EACD,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;YACF,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE;gBACtC,MAAM,CAAC;oBACL,MAAM,EAAE,KAAK;oBACb,OAAO,EAAE,oCAA6B,GAAG,CAAE;iBAC5C,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,0BAA0B;YAC1B,MAAA,QAAQ,CAAC,IAAI,0CAAE,WAAW,CAAC,aAAa,CAAC,CAAC;SAC3C;QAAC,OAAO,KAAK,EAAE;YACd,0BAA0B;YAC1B,MAAM,CAAC,KAAK,CAAC,CAAC;SACf;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAG,IAAI,CAAC,GAAG,EAAE,cAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,CAAC;AACpE,CAAC;AAED,MAAM,CAAC,IAAM,2BAA2B,GAAG,UAAC,KAAsD;IAChG,+CAA+C;IAC/C,sEAAsE;IACtE,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,sBAAsB,EAAE;QAChE,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA8BF,iBAAiB;AACjB,MAAM,UAAU,mBAAmB,CAAI,KAA8B;IACnE,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AAC3D,CAAC","sourcesContent":["/* eslint-disable no-restricted-globals */\nimport { ElementInteractionsOptions, ActionType, isUrlMatchAllowlist } from '@amplitude/analytics-core';\n\nexport type JSONValue = string | number | boolean | null | { [x: string]: JSONValue } | Array<JSONValue>;\n\nconst SENSITIVE_TAGS = ['input', 'select', 'textarea'];\n\nexport type shouldTrackEvent = (actionType: ActionType, element: Element) => boolean;\n\nexport const isElementPointerCursor = (element: Element, actionType: ActionType): boolean => {\n /* istanbul ignore next */\n const computedStyle = window?.getComputedStyle?.(element);\n /* istanbul ignore next */\n return computedStyle?.getPropertyValue('cursor') === 'pointer' && actionType === 'click';\n};\n\nexport const createShouldTrackEvent = (\n autocaptureOptions: ElementInteractionsOptions,\n allowlist: string[], // this can be any type of css selector allow list\n isAlwaysCaptureCursorPointer = false,\n): shouldTrackEvent => {\n return (actionType: ActionType, element: Element) => {\n const { pageUrlAllowlist, pageUrlExcludelist, shouldTrackEventResolver } = autocaptureOptions;\n\n /* istanbul ignore next */\n const tag = element?.tagName?.toLowerCase?.();\n // window, document, and Text nodes have no tag\n if (!tag) {\n return false;\n }\n\n if (shouldTrackEventResolver) {\n return shouldTrackEventResolver(actionType, element);\n }\n\n // check if the URL is in the allow list\n if (!isUrlMatchAllowlist(window.location.href, pageUrlAllowlist)) {\n return false;\n }\n\n // check if the URL is in the excludelist\n if (\n pageUrlExcludelist &&\n pageUrlExcludelist.length > 0 &&\n isUrlMatchAllowlist(window.location.href, pageUrlExcludelist as (string | RegExp)[])\n ) {\n return false;\n }\n\n /* istanbul ignore next */\n const elementType = String(element?.getAttribute('type')) || '';\n if (typeof elementType === 'string') {\n switch (elementType.toLowerCase()) {\n case 'hidden':\n return false;\n case 'password':\n return false;\n }\n }\n\n const isCursorPointer = isElementPointerCursor(element, actionType);\n\n if (isAlwaysCaptureCursorPointer && isCursorPointer) {\n return true;\n }\n\n /* istanbul ignore if */\n if (allowlist) {\n const hasMatchAnyAllowedSelector = allowlist.some((selector) => !!element?.matches?.(selector));\n if (!hasMatchAnyAllowedSelector) {\n return false;\n }\n }\n\n switch (tag) {\n case 'input':\n case 'select':\n case 'textarea':\n return actionType === 'change' || actionType === 'click';\n default: {\n /* istanbul ignore next */\n /* istanbul ignore next */\n if (isCursorPointer) {\n return true;\n }\n return actionType === 'click';\n }\n }\n };\n};\n\nexport const isTextNode = (node: Node) => {\n return !!node && node.nodeType === 3;\n};\n\nexport const isNonSensitiveElement = (element: Element) => {\n /* istanbul ignore next */\n const tag = element?.tagName?.toLowerCase?.();\n const isContentEditable =\n element instanceof HTMLElement ? element.getAttribute('contenteditable')?.toLowerCase() === 'true' : false;\n\n return !SENSITIVE_TAGS.includes(tag) && !isContentEditable;\n};\n\n/**\n * Collects redacted attribute names from element and ancestor elements with data-amp-mask-attributes\n * The 'id' and 'class' attributes cannot be redacted as they're critical for element identification\n * @param element - The target element to check for redaction attributes\n * @returns Set of attribute names that should be redacted\n */\n/**\n * Parses a comma-separated string of attribute names and filters out protected attributes\n * @param attributeString - Comma-separated string of attribute names\n * @returns Array of valid attribute names, excluding 'id' and 'class'\n */\nexport const parseAttributesToMask = (attributeString: string | null): string[] => {\n return attributeString\n ? attributeString\n .split(',')\n .map((attr) => attr.trim())\n .filter((attr) => attr.length > 0 && attr !== 'id' && attr !== 'class') // Prevent 'id' and 'class' from being redacted as they're critical for element identification\n : [];\n};\n\nexport const extractPrefixedAttributes = (\n attrs: { [key: string]: string },\n prefix: string,\n): { [key: string]: string } => {\n return Object.entries(attrs).reduce((attributes: { [key: string]: string }, [attributeName, attributeValue]) => {\n if (attributeName.startsWith(prefix)) {\n const attributeKey = attributeName.replace(prefix, '');\n\n if (attributeKey) {\n attributes[attributeKey] = attributeValue || '';\n }\n }\n return attributes;\n }, {});\n};\n\nexport const isEmpty = (value: unknown) => {\n return (\n value === undefined ||\n value === null ||\n (typeof value === 'object' && Object.keys(value).length === 0) ||\n (typeof value === 'string' && value.trim().length === 0)\n );\n};\n\nexport const removeEmptyProperties = (properties: { [key: string]: unknown }): { [key: string]: unknown } => {\n return Object.keys(properties).reduce((filteredProperties: { [key: string]: unknown }, key) => {\n const value = properties[key];\n if (!isEmpty(value)) {\n filteredProperties[key] = value;\n }\n return filteredProperties;\n }, {});\n};\n\nexport const querySelectUniqueElements = (root: Element | Document, selectors: string[]): Element[] => {\n if (root && 'querySelectorAll' in root && typeof root.querySelectorAll === 'function') {\n const elementSet = selectors.reduce((elements: Set<Element>, selector) => {\n if (selector) {\n const selectedElements = Array.from(root.querySelectorAll(selector));\n selectedElements.forEach((element) => {\n elements.add(element);\n });\n }\n return elements;\n }, new Set<Element>());\n return Array.from(elementSet);\n }\n return [];\n};\n\n// Similar as element.closest, but works with multiple selectors\nexport const getClosestElement = (element: Element | null, selectors: string[]): Element | null => {\n if (!element) {\n return null;\n }\n /* istanbul ignore next */\n if (selectors.some((selector) => element?.matches?.(selector))) {\n return element;\n }\n /* istanbul ignore next */\n return getClosestElement(element?.parentElement, selectors);\n};\n\nexport const asyncLoadScript = (url: string) => {\n return new Promise((resolve, reject) => {\n try {\n const scriptElement = document.createElement('script');\n scriptElement.type = 'text/javascript';\n scriptElement.async = true;\n scriptElement.src = url;\n scriptElement.addEventListener(\n 'load',\n () => {\n resolve({ status: true });\n },\n { once: true },\n );\n scriptElement.addEventListener('error', () => {\n reject({\n status: false,\n message: `Failed to load the script ${url}`,\n });\n });\n /* istanbul ignore next */\n document.head?.appendChild(scriptElement);\n } catch (error) {\n /* istanbul ignore next */\n reject(error);\n }\n });\n};\n\nexport function generateUniqueId(): string {\n return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n}\n\nexport const filterOutNonTrackableEvents = (event: ElementBasedTimestampedEvent<ElementBasedEvent>): boolean => {\n // Filter out changeEvent events with no target\n // This could happen when change events are triggered programmatically\n if (event.event.target === null || !event.closestTrackedAncestor) {\n return false;\n }\n\n return true;\n};\n\nexport type AutoCaptureOptionsWithDefaults = Required<\n Pick<ElementInteractionsOptions, 'debounceTime' | 'cssSelectorAllowlist' | 'actionClickAllowlist'>\n> &\n ElementInteractionsOptions;\n\n// Base TimestampedEvent type\nexport type BaseTimestampedEvent<T> = {\n event: T;\n timestamp: number;\n type: 'rage' | 'click' | 'change' | 'error' | 'navigate' | 'mutation';\n};\n\n// Specific types for events with targetElementProperties\nexport type ElementBasedEvent = MouseEvent | Event;\nexport type ElementBasedTimestampedEvent<T> = BaseTimestampedEvent<T> & {\n event: MouseEvent | Event;\n type: 'click' | 'change';\n closestTrackedAncestor: Element;\n targetElementProperties: Record<string, any>;\n};\n\nexport type evaluateTriggersFn = (\n event: ElementBasedTimestampedEvent<ElementBasedEvent>,\n) => ElementBasedTimestampedEvent<ElementBasedEvent>;\n\n// Union type for all possible TimestampedEvents\nexport type TimestampedEvent<T> = BaseTimestampedEvent<T> | ElementBasedTimestampedEvent<T>;\n\n// Type predicate\nexport function isElementBasedEvent<T>(event: BaseTimestampedEvent<T>): event is ElementBasedTimestampedEvent<T> {\n return event.type === 'click' || event.type === 'change';\n}\n\nexport interface NavigateEvent extends Event {\n readonly navigationType: 'reload' | 'push' | 'replace' | 'traverse';\n readonly destination: {\n readonly url: string;\n readonly key: string | null;\n readonly id: string | null;\n readonly index: number;\n readonly sameDocument: boolean;\n\n getState(): any;\n };\n readonly canIntercept: boolean;\n readonly userInitiated: boolean;\n readonly hashChange: boolean;\n readonly signal: AbortSignal;\n readonly formData: FormData | null;\n readonly downloadRequest: string | null;\n readonly info: any;\n readonly hasUAVisualTransition: boolean;\n /** @see https://github.com/WICG/navigation-api/pull/264 */\n readonly sourceElement: Element | null;\n\n scroll(): void;\n}\n"]}
@@ -1,16 +1,5 @@
1
- import { type JSONValue } from './helpers';
2
- import type { Hierarchy, HierarchyNode } from './typings/autocapture';
3
- export declare function getElementProperties(element: Element | null): HierarchyNode | null;
1
+ import type { HierarchyNode } from './typings/autocapture';
2
+ export declare const MAX_HIERARCHY_LENGTH = 1024;
3
+ export declare function getElementProperties(element: Element | null, userMaskedAttributeNames: Set<string>): HierarchyNode | null;
4
4
  export declare function getAncestors(targetEl: Element | null): Element[];
5
- export declare const getHierarchy: (element: Element | null) => Hierarchy;
6
- export declare function ensureListUnderLimit(list: Hierarchy | JSONValue[], bytesLimit: number): Hierarchy | JSONValue[];
7
- /**
8
- * Converts a JSON-compatible value to a Python-compatible string representation.
9
- * This function handles various data types and ensures proper escaping and formatting.
10
- *
11
- * @param value - The value to be converted (can be any JSON-compatible type)
12
- * @param nested - Indicates if the value is nested within another structure (default: false)
13
- * @returns A string representation of the value compatible with Python, or null if conversion fails
14
- */
15
- export declare function ensureUnicodePythonCompatible(value: HierarchyNode | JSONValue | null, nested?: boolean): string | null;
16
5
  //# sourceMappingURL=hierarchy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hierarchy.d.ts","sourceRoot":"","sources":["../../src/hierarchy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAoCtE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,aAAa,GAAG,IAAI,CAsDlF;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,EAAE,CAehE;AAGD,eAAO,MAAM,YAAY,YAAa,OAAO,GAAG,IAAI,cAcnD,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,CAkB/G;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,EAAE,MAAM,UAAQ,GAAG,MAAM,GAAG,IAAI,CAoDpH"}
1
+ {"version":3,"file":"hierarchy.d.ts","sourceRoot":"","sources":["../../src/hierarchy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAsC3D,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,GAAG,IAAI,EACvB,wBAAwB,EAAE,GAAG,CAAC,MAAM,CAAC,GACpC,aAAa,GAAG,IAAI,CA2DtB;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,EAAE,CAehE"}
@@ -1,6 +1,7 @@
1
- import { __read, __values } from "tslib";
1
+ import { __values } from "tslib";
2
2
  import { isNonSensitiveElement } from './helpers';
3
- var BLOCKED_ATTRIBUTES = [
3
+ import { DATA_AMP_MASK_ATTRIBUTES, MASKED_TEXT_VALUE, TEXT_MASK_ATTRIBUTE } from './constants';
4
+ var BLOCKED_ATTRIBUTES = new Set([
4
5
  // Already captured elsewhere in the hierarchy object
5
6
  'id',
6
7
  'class',
@@ -22,13 +23,16 @@ var BLOCKED_ATTRIBUTES = [
22
23
  'data-reactid',
23
24
  'data-react-checksum',
24
25
  'data-reactroot',
25
- ];
26
+ // Amplitude specific - used for redaction but should not be included in getElementProperties
27
+ DATA_AMP_MASK_ATTRIBUTES,
28
+ TEXT_MASK_ATTRIBUTE,
29
+ ]);
26
30
  var SENSITIVE_ELEMENT_ATTRIBUTE_ALLOWLIST = ['type'];
27
31
  var SVG_TAGS = ['svg', 'path', 'g'];
28
32
  var HIGHLY_SENSITIVE_INPUT_TYPES = ['password', 'hidden'];
29
33
  var MAX_ATTRIBUTE_LENGTH = 128;
30
- var MAX_HIERARCHY_LENGTH = 1024;
31
- export function getElementProperties(element) {
34
+ export var MAX_HIERARCHY_LENGTH = 1024;
35
+ export function getElementProperties(element, userMaskedAttributeNames) {
32
36
  var e_1, _a;
33
37
  var _b, _c, _d, _e;
34
38
  if (element === null) {
@@ -57,7 +61,7 @@ export function getElementProperties(element) {
57
61
  }
58
62
  var attributes = {};
59
63
  var attributesArray = Array.from(element.attributes);
60
- var filteredAttributes = attributesArray.filter(function (attr) { return !BLOCKED_ATTRIBUTES.includes(attr.name); });
64
+ var filteredAttributes = attributesArray.filter(function (attr) { return !BLOCKED_ATTRIBUTES.has(attr.name); });
61
65
  var isSensitiveElement = !isNonSensitiveElement(element);
62
66
  // if input is hidden or password or for SVGs, skip attribute collection entirely
63
67
  if (!HIGHLY_SENSITIVE_INPUT_TYPES.includes(String(element.getAttribute('type'))) && !SVG_TAGS.includes(tagName)) {
@@ -68,6 +72,10 @@ export function getElementProperties(element) {
68
72
  if (isSensitiveElement && !SENSITIVE_ELEMENT_ATTRIBUTE_ALLOWLIST.includes(attr.name)) {
69
73
  continue;
70
74
  }
75
+ if (userMaskedAttributeNames.has(attr.name)) {
76
+ attributes[attr.name] = MASKED_TEXT_VALUE;
77
+ continue;
78
+ }
71
79
  // Finally cast attribute value to string and limit attribute value length
72
80
  attributes[attr.name] = String(attr.value).substring(0, MAX_ATTRIBUTE_LENGTH);
73
81
  }
@@ -99,103 +107,4 @@ export function getAncestors(targetEl) {
99
107
  }
100
108
  return ancestors;
101
109
  }
102
- // Get the DOM hierarchy of the element, starting from the target element to the root element.
103
- export var getHierarchy = function (element) {
104
- var hierarchy = [];
105
- if (!element) {
106
- return [];
107
- }
108
- // Get list of ancestors including itself and get properties at each level in the hierarchy
109
- var ancestors = getAncestors(element);
110
- hierarchy = ensureListUnderLimit(ancestors.map(function (el) { return getElementProperties(el); }), MAX_HIERARCHY_LENGTH);
111
- return hierarchy;
112
- };
113
- export function ensureListUnderLimit(list, bytesLimit) {
114
- var numChars = 0;
115
- for (var i = 0; i < list.length; i++) {
116
- var node = list[i];
117
- if (node === null) {
118
- // simulate 'None' in python
119
- numChars += 4;
120
- }
121
- else {
122
- var value = ensureUnicodePythonCompatible(node);
123
- // Using Array.from(string).length instead of string.length
124
- // to correctly count Unicode characters (including emojis)
125
- numChars += value ? Array.from(value).length : 4;
126
- }
127
- if (numChars > bytesLimit) {
128
- return list.slice(0, i);
129
- }
130
- }
131
- return list;
132
- }
133
- /**
134
- * Converts a JSON-compatible value to a Python-compatible string representation.
135
- * This function handles various data types and ensures proper escaping and formatting.
136
- *
137
- * @param value - The value to be converted (can be any JSON-compatible type)
138
- * @param nested - Indicates if the value is nested within another structure (default: false)
139
- * @returns A string representation of the value compatible with Python, or null if conversion fails
140
- */
141
- export function ensureUnicodePythonCompatible(value, nested) {
142
- if (nested === void 0) { nested = false; }
143
- try {
144
- if (value == null) {
145
- // Handle null values
146
- if (nested) {
147
- return 'None'; // Represent null as 'None' in Python when nested
148
- }
149
- return null; // Return null for top-level null values
150
- }
151
- else if (typeof value === 'string') {
152
- if (nested) {
153
- // Escape special characters in nested strings
154
- value = value.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/\t/g, '\\t').replace(/\r/g, '\\r');
155
- // Handle quotes in the string
156
- if (value.includes('"')) {
157
- return "'".concat(value, "'"); // Wrap in single quotes if it contains double quotes
158
- }
159
- if (value.includes("'")) {
160
- return "\"".concat(value.replace(/'/g, "\\'"), "\""); // Wrap in double quotes and escape single quotes
161
- }
162
- return "'".concat(value, "'"); // Default to wrapping in single quotes
163
- }
164
- return value; // Return non-nested strings as-is
165
- }
166
- else if (typeof value === 'boolean') {
167
- // Convert boolean to Python-style capitalized string
168
- return value ? 'True' : 'False';
169
- }
170
- else if (Array.isArray(value)) {
171
- // Handle arrays by recursively converting each element
172
- var elements = value.map(function (o) { return ensureUnicodePythonCompatible(o, true); });
173
- return "[".concat(elements.join(', '), "]");
174
- }
175
- else if (typeof value === 'object') {
176
- // Handle objects (dictionaries in Python)
177
- var entries = Object.entries(value)
178
- .filter(function (_a) {
179
- var _b = __read(_a, 1), key = _b[0];
180
- return key != null;
181
- }) // Filter out null keys
182
- .map(function (_a) {
183
- var _b = __read(_a, 2), key = _b[0], val = _b[1];
184
- return "".concat(String(ensureUnicodePythonCompatible(key, true)), ": ").concat(String(ensureUnicodePythonCompatible(val, true)));
185
- });
186
- var result = "{".concat(entries.join(', '), "}");
187
- // Handle single quotes in the resulting string
188
- if (result.includes("\\'")) {
189
- result = result.replace(/'/g, "'").replace(/'/g, "\\'");
190
- }
191
- return result;
192
- }
193
- // For any other types, return their string representation;
194
- return value.toString();
195
- }
196
- catch (e) {
197
- // Return null if any error occurs during the conversion
198
- return null;
199
- }
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AAC,EAAU;oBAAV,KAAA,aAAU,EAAT,GAAG,QAAA,EAAE,GAAG,QAAA;gBACR,OAAA,UAAG,MAAM,CAAC,6BAA6B,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,eAAK,MAAM,CAAC,6BAA6B,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAE;YAA1G,CAA0G,CAC7G,CAAC;YACJ,IAAI,MAAM,GAAG,WAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAG,CAAC;YAEvC,+CAA+C;YAC/C,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC1B,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aACzD;YACD,OAAO,MAAM,CAAC;SACf;QACD,2DAA2D;QAC3D,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;IAAC,OAAO,CAAC,EAAE;QACV,wDAAwD;QACxD,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["import { isNonSensitiveElement, type JSONValue } from './helpers';\nimport type { Hierarchy, HierarchyNode } from './typings/autocapture';\n\nconst BLOCKED_ATTRIBUTES = [\n // Already captured elsewhere in the hierarchy object\n 'id',\n 'class',\n\n // non-useful and potentially large attribute\n 'style',\n\n // sensitive as prefilled form data may populate this attribute\n 'value',\n\n // DOM events\n 'onclick',\n 'onchange',\n 'oninput',\n 'onblur',\n 'onsubmit',\n 'onfocus',\n 'onkeydown',\n 'onkeyup',\n 'onkeypress',\n\n // React specific\n 'data-reactid',\n 'data-react-checksum',\n 'data-reactroot',\n];\nconst SENSITIVE_ELEMENT_ATTRIBUTE_ALLOWLIST = ['type'];\n\nconst SVG_TAGS = ['svg', 'path', 'g'];\nconst HIGHLY_SENSITIVE_INPUT_TYPES = ['password', 'hidden'];\nconst MAX_ATTRIBUTE_LENGTH = 128;\nconst MAX_HIERARCHY_LENGTH = 1024;\n\nexport function getElementProperties(element: Element | null): HierarchyNode | null {\n if (element === null) {\n return null;\n }\n\n const tagName = String(element.tagName).toLowerCase();\n const properties: HierarchyNode = {\n tag: tagName,\n };\n\n const siblings = Array.from(element.parentElement?.children ?? []);\n if (siblings.length) {\n properties.index = siblings.indexOf(element);\n properties.indexOfType = siblings.filter((el) => el.tagName === element.tagName).indexOf(element);\n }\n\n const prevSiblingTag = element.previousElementSibling?.tagName?.toLowerCase();\n if (prevSiblingTag) {\n properties.prevSib = String(prevSiblingTag);\n }\n\n const id = element.getAttribute('id');\n if (id) {\n properties.id = String(id);\n }\n\n const classes = Array.from(element.classList);\n if (classes.length) {\n properties.classes = classes;\n }\n\n const attributes: Record<string, string> = {};\n const attributesArray = Array.from(element.attributes);\n const filteredAttributes = attributesArray.filter((attr) => !BLOCKED_ATTRIBUTES.includes(attr.name));\n const isSensitiveElement = !isNonSensitiveElement(element);\n\n // if input is hidden or password or for SVGs, skip attribute collection entirely\n if (!HIGHLY_SENSITIVE_INPUT_TYPES.includes(String(element.getAttribute('type'))) && !SVG_TAGS.includes(tagName)) {\n for (const attr of filteredAttributes) {\n // If sensitive element, only allow certain attributes\n if (isSensitiveElement && !SENSITIVE_ELEMENT_ATTRIBUTE_ALLOWLIST.includes(attr.name)) {\n continue;\n }\n\n // Finally cast attribute value to string and limit attribute value length\n attributes[attr.name] = String(attr.value).substring(0, MAX_ATTRIBUTE_LENGTH);\n }\n }\n\n if (Object.keys(attributes).length) {\n properties.attrs = attributes;\n }\n\n return properties;\n}\n\nexport function getAncestors(targetEl: Element | null): Element[] {\n const ancestors: Element[] = [];\n\n if (!targetEl) {\n return ancestors;\n }\n\n // Add self to the list of ancestors\n ancestors.push(targetEl);\n let current = targetEl.parentElement;\n while (current && current.tagName !== 'HTML') {\n ancestors.push(current);\n current = current.parentElement;\n }\n return ancestors;\n}\n\n// Get the DOM hierarchy of the element, starting from the target element to the root element.\nexport const getHierarchy = (element: Element | null): Hierarchy => {\n let hierarchy: Hierarchy = [];\n if (!element) {\n return [];\n }\n\n // Get list of ancestors including itself and get properties at each level in the hierarchy\n const ancestors = getAncestors(element);\n hierarchy = ensureListUnderLimit(\n ancestors.map((el) => getElementProperties(el)),\n MAX_HIERARCHY_LENGTH,\n ) as Hierarchy;\n\n return hierarchy;\n};\n\nexport function ensureListUnderLimit(list: Hierarchy | JSONValue[], bytesLimit: number): Hierarchy | JSONValue[] {\n let numChars = 0;\n for (let i = 0; i < list.length; i++) {\n const node = list[i];\n if (node === null) {\n // simulate 'None' in python\n numChars += 4;\n } else {\n const value = ensureUnicodePythonCompatible(node);\n // Using Array.from(string).length instead of string.length\n // to correctly count Unicode characters (including emojis)\n numChars += value ? Array.from(value).length : 4;\n }\n if (numChars > bytesLimit) {\n return list.slice(0, i);\n }\n }\n return list;\n}\n\n/**\n * Converts a JSON-compatible value to a Python-compatible string representation.\n * This function handles various data types and ensures proper escaping and formatting.\n *\n * @param value - The value to be converted (can be any JSON-compatible type)\n * @param nested - Indicates if the value is nested within another structure (default: false)\n * @returns A string representation of the value compatible with Python, or null if conversion fails\n */\nexport function ensureUnicodePythonCompatible(value: HierarchyNode | JSONValue | null, nested = false): string | null {\n try {\n if (value == null) {\n // Handle null values\n if (nested) {\n return 'None'; // Represent null as 'None' in Python when nested\n }\n return null; // Return null for top-level null values\n } else if (typeof value === 'string') {\n if (nested) {\n // Escape special characters in nested strings\n value = value.replace(/\\\\/g, '\\\\\\\\').replace(/\\n/g, '\\\\n').replace(/\\t/g, '\\\\t').replace(/\\r/g, '\\\\r');\n\n // Handle quotes in the string\n if (value.includes('\"')) {\n return `'${value}'`; // Wrap in single quotes if it contains double quotes\n }\n if (value.includes(\"'\")) {\n return `\"${value.replace(/'/g, \"\\\\'\")}\"`; // Wrap in double quotes and escape single quotes\n }\n return `'${value}'`; // Default to wrapping in single quotes\n }\n return value; // Return non-nested strings as-is\n } else if (typeof value === 'boolean') {\n // Convert boolean to Python-style capitalized string\n return value ? 'True' : 'False';\n } else if (Array.isArray(value)) {\n // Handle arrays by recursively converting each element\n const elements = value.map((o) => ensureUnicodePythonCompatible(o, true));\n return `[${elements.join(', ')}]`;\n } else if (typeof value === 'object') {\n // Handle objects (dictionaries in Python)\n const entries = Object.entries(value)\n .filter(([key]) => key != null) // Filter out null keys\n .map(\n ([key, val]) =>\n `${String(ensureUnicodePythonCompatible(key, true))}: ${String(ensureUnicodePythonCompatible(val, true))}`,\n );\n let result = `{${entries.join(', ')}}`;\n\n // Handle single quotes in the resulting string\n if (result.includes(\"\\\\'\")) {\n result = result.replace(/'/g, \"'\").replace(/'/g, \"\\\\'\");\n }\n return result;\n }\n // For any other types, return their string representation;\n return value.toString();\n } catch (e) {\n // Return null if any error occurs during the conversion\n return null;\n }\n}\n"]}
1
+ {"version":3,"file":"hierarchy.js","sourceRoot":"","sources":["../../src/hierarchy.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG/F,IAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,qDAAqD;IACrD,IAAI;IACJ,OAAO;IAEP,6CAA6C;IAC7C,OAAO;IAEP,+DAA+D;IAC/D,OAAO;IAEP,aAAa;IACb,SAAS;IACT,UAAU;IACV,SAAS;IACT,QAAQ;IACR,UAAU;IACV,SAAS;IACT,WAAW;IACX,SAAS;IACT,YAAY;IAEZ,iBAAiB;IACjB,cAAc;IACd,qBAAqB;IACrB,gBAAgB;IAEhB,6FAA6F;IAC7F,wBAAwB;IACxB,mBAAmB;CACpB,CAAC,CAAC;AACH,IAAM,qCAAqC,GAAG,CAAC,MAAM,CAAC,CAAC;AAEvD,IAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACtC,IAAM,4BAA4B,GAAG,CAAC,UAAU,EAAE,QAAQ,C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ED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,QAAwB;IACnD,IAAM,SAAS,GAAc,EAAE,CAAC;IAEhC,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,SAAS,CAAC;KAClB;IAED,oCAAoC;IACpC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,IAAI,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;IACrC,OAAO,OAAO,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,EAAE;QAC5C,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;KACjC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { isNonSensitiveElement } from './helpers';\nimport { DATA_AMP_MASK_ATTRIBUTES, MASKED_TEXT_VALUE, TEXT_MASK_ATTRIBUTE } from './constants';\nimport type { HierarchyNode } from './typings/autocapture';\n\nconst BLOCKED_ATTRIBUTES = new Set([\n // Already captured elsewhere in the hierarchy object\n 'id',\n 'class',\n\n // non-useful and potentially large attribute\n 'style',\n\n // sensitive as prefilled form data may populate this attribute\n 'value',\n\n // DOM events\n 'onclick',\n 'onchange',\n 'oninput',\n 'onblur',\n 'onsubmit',\n 'onfocus',\n 'onkeydown',\n 'onkeyup',\n 'onkeypress',\n\n // React specific\n 'data-reactid',\n 'data-react-checksum',\n 'data-reactroot',\n\n // Amplitude specific - used for redaction but should not be included in getElementProperties\n DATA_AMP_MASK_ATTRIBUTES,\n TEXT_MASK_ATTRIBUTE,\n]);\nconst SENSITIVE_ELEMENT_ATTRIBUTE_ALLOWLIST = ['type'];\n\nconst SVG_TAGS = ['svg', 'path', 'g'];\nconst HIGHLY_SENSITIVE_INPUT_TYPES = ['password', 'hidden'];\nconst MAX_ATTRIBUTE_LENGTH = 128;\nexport const MAX_HIERARCHY_LENGTH = 1024;\n\nexport function getElementProperties(\n element: Element | null,\n userMaskedAttributeNames: Set<string>,\n): HierarchyNode | null {\n if (element === null) {\n return null;\n }\n\n const tagName = String(element.tagName).toLowerCase();\n const properties: HierarchyNode = {\n tag: tagName,\n };\n\n const siblings = Array.from(element.parentElement?.children ?? []);\n if (siblings.length) {\n properties.index = siblings.indexOf(element);\n properties.indexOfType = siblings.filter((el) => el.tagName === element.tagName).indexOf(element);\n }\n\n const prevSiblingTag = element.previousElementSibling?.tagName?.toLowerCase();\n if (prevSiblingTag) {\n properties.prevSib = String(prevSiblingTag);\n }\n\n const id = element.getAttribute('id');\n if (id) {\n properties.id = String(id);\n }\n\n const classes = Array.from(element.classList);\n if (classes.length) {\n properties.classes = classes;\n }\n\n const attributes: Record<string, string> = {};\n const attributesArray = Array.from(element.attributes);\n const filteredAttributes = attributesArray.filter((attr) => !BLOCKED_ATTRIBUTES.has(attr.name));\n const isSensitiveElement = !isNonSensitiveElement(element);\n\n // if input is hidden or password or for SVGs, skip attribute collection entirely\n if (!HIGHLY_SENSITIVE_INPUT_TYPES.includes(String(element.getAttribute('type'))) && !SVG_TAGS.includes(tagName)) {\n for (const attr of filteredAttributes) {\n // If sensitive element, only allow certain attributes\n if (isSensitiveElement && !SENSITIVE_ELEMENT_ATTRIBUTE_ALLOWLIST.includes(attr.name)) {\n continue;\n }\n\n if (userMaskedAttributeNames.has(attr.name)) {\n attributes[attr.name] = MASKED_TEXT_VALUE;\n continue;\n }\n\n // Finally cast attribute value to string and limit attribute value length\n attributes[attr.name] = String(attr.value).substring(0, MAX_ATTRIBUTE_LENGTH);\n }\n }\n\n if (Object.keys(attributes).length) {\n properties.attrs = attributes;\n }\n\n return properties;\n}\n\nexport function getAncestors(targetEl: Element | null): Element[] {\n const ancestors: Element[] = [];\n\n if (!targetEl) {\n return ancestors;\n }\n\n // Add self to the list of ancestors\n ancestors.push(targetEl);\n let current = targetEl.parentElement;\n while (current && current.tagName !== 'HTML') {\n ancestors.push(current);\n current = current.parentElement;\n }\n return ancestors;\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export { autocapturePlugin as plugin, autocapturePlugin } from './autocapture-plugin';
2
2
  export { frustrationPlugin } from './frustration-plugin';
3
3
  export { Action, ActionData, Message, WindowMessenger } from './libs/messenger';
4
+ export { DataExtractor } from './data-extractor';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,MAAM,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,MAAM,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
package/lib/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { autocapturePlugin as plugin, autocapturePlugin } from './autocapture-plugin';
2
2
  export { frustrationPlugin } from './frustration-plugin';
3
3
  export { WindowMessenger } from './libs/messenger';
4
+ export { DataExtractor } from './data-extractor';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,MAAM,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAA+B,eAAe,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { autocapturePlugin as plugin, autocapturePlugin } from './autocapture-plugin';\nexport { frustrationPlugin } from './frustration-plugin';\nexport { Action, ActionData, Message, WindowMessenger } from './libs/messenger';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,MAAM,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAA+B,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { autocapturePlugin as plugin, autocapturePlugin } from './autocapture-plugin';\nexport { frustrationPlugin } from './frustration-plugin';\nexport { Action, ActionData, Message, WindowMessenger } from './libs/messenger';\nexport { DataExtractor } from './data-extractor';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"messenger.d.ts","sourceRoot":"","sources":["../../../src/libs/messenger.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,MAAM,GACd,MAAM,GACN,MAAM,GACN,aAAa,GACb,iBAAiB,GACjB,oCAAoC,GACpC,+BAA+B,GAC/B,kBAAkB,GAClB,6BAA6B,GAC7B,sBAAsB,CAAC;AAE3B,UAAU,mCAAmC;IAC3C,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,UAAU,mBAAmB;IAC3B,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,sBAAsB,CAAC,EAAE,MAA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,GAAG,CAAC,EAAE,OAAO;;KAAsB,GAAG,OAAO,CAAC,GAAG,CAAC;IA6B1G,OAAO,CAAC,cAAc;IAUtB,KAAK,CACH,EACE,MAAM,EACN,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,GACd,GAAE;QACD,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,mCAAmC,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;QAC/G,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;QAChC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;QAChC,aAAa,EAAE,aAAa,CAAC;KACa;IA8E9C,OAAO,CAAC,QAAQ,CAEd;IAEF,OAAO,CAAC,OAAO,CAMb;CACH"}
@@ -119,6 +119,7 @@ var WindowMessenger = /** @class */ (function () {
119
119
  cssSelectorAllowlist: cssSelectorAllowlist,
120
120
  actionClickAllowlist: actionClickAllowlist,
121
121
  extractDataFromDataSource: dataExtractor.extractDataFromDataSource,
122
+ dataExtractor: dataExtractor,
122
123
  diagnostics: {
123
124
  autocapture: {
124
125
  version: VERSION,
@@ -1 +1 @@
1
- {"version":3,"file":"messenger.js","sourceRoot":"","sources":["../../../src/libs/messenger.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,0CAA0C;AAC1C,OAAO,EACL,gBAAgB,EAChB,4CAA4C,EAC5C,wCAAwC,GACzC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAgElD,yDAAyD;AACzD;IAUE,yBAAY,EAAuD;YAAvD,qBAAqD,EAAE,KAAA,EAArD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BAAC;AAAD,CAAC,AAlKD,IAkKC","sourcesContent":["/* istanbul ignore file */\n/* eslint-disable no-restricted-globals */\nimport {\n AMPLITUDE_ORIGIN,\n AMPLITUDE_VISUAL_TAGGING_SELECTOR_SCRIPT_URL,\n AMPLITUDE_VISUAL_TAGGING_HIGHLIGHT_CLASS,\n} from '../constants';\nimport { asyncLoadScript, generateUniqueId } from '../helpers';\nimport { ILogger, Messenger, ActionType } from '@amplitude/analytics-core';\nimport { VERSION } from '../version';\nimport { DataExtractor } from '../data-extractor';\n\nexport type Action =\n | 'ping'\n | 'pong'\n | 'page-loaded'\n | 'selector-loaded'\n | 'initialize-visual-tagging-selector'\n | 'close-visual-tagging-selector'\n | 'element-selected'\n | 'track-selector-mode-changed'\n | 'track-selector-moved';\n\ninterface InitializeVisualTaggingSelectorData {\n actionType: ActionType;\n}\n\ninterface ElementSelectedData {\n '[Amplitude] Element Hierarchy'?: string;\n '[Amplitude] Element Tag'?: string;\n '[Amplitude] Element Text'?: string;\n '[Amplitude] Page URL'?: string;\n elementScreenshot?: Blob;\n}\n\ninterface TrackSelectorModeChangedData {\n newMode: string;\n pageUrl?: string;\n}\n\ninterface TrackSelectorMovedData {\n newEditorLocation: string;\n pageUrl?: string;\n}\n\nexport type ActionData = {\n ping: null | undefined;\n pong: null | undefined;\n 'page-loaded': null | undefined;\n 'selector-loaded': null | undefined;\n 'initialize-visual-tagging-selector': InitializeVisualTaggingSelectorData | null | undefined;\n 'close-visual-tagging-selector': null | undefined;\n 'element-selected': ElementSelectedData;\n 'track-selector-mode-changed': TrackSelectorModeChangedData;\n 'track-selector-moved': TrackSelectorMovedData;\n};\n\nexport interface Message<A extends Action> {\n action: A;\n data?: ActionData[A];\n}\n\ntype MessageRequest = {\n id: string;\n action: string;\n args: Record<string, any>;\n};\n\ntype MessageResponse = {\n id: string;\n action: string;\n responseData: any;\n};\n\n// TODO: use MessageChannel instead of window.postMessage\nexport class WindowMessenger implements Messenger {\n endpoint = AMPLITUDE_ORIGIN;\n logger?: ILogger;\n requestCallbacks: {\n [id: string]: {\n resolve: (data: any) => void;\n reject: (data: any) => void;\n };\n } = {};\n\n constructor({ origin = AMPLITUDE_ORIGIN }: { origin?: string } = {}) {\n this.endpoint = origin;\n }\n\n private notify(message: Message<Action> | MessageRequest) {\n this.logger?.debug?.('Message sent: ', JSON.stringify(message));\n (window.opener as WindowProxy)?.postMessage?.(message, this.endpoint);\n }\n\n // Send an async request to the parent window\n public sendRequest(action: string, args: Record<string, any>, options = { timeout: 15_000 }): Promise<any> {\n // Create Request ID\n const id = generateUniqueId();\n const request = {\n id,\n action,\n args,\n };\n\n // Create a Promise that will be resolved when the response is received\n const promise = new Promise((resolve, reject) => {\n this.requestCallbacks[id] = { resolve, reject };\n\n // Send the request\n this.notify(request);\n\n // Handle request timeouts\n if (options?.timeout > 0) {\n setTimeout(() => {\n reject(new Error(`${action} timed out (id: ${id})`));\n delete this.requestCallbacks[id];\n }, options.timeout);\n }\n });\n\n return promise;\n }\n\n // Handle messages from the parent window\n private handleResponse(response: MessageResponse) {\n if (!this.requestCallbacks[response.id]) {\n this.logger?.warn(`No callback found for request id: ${response.id}`);\n return;\n }\n\n this.requestCallbacks[response.id].resolve(response.responseData);\n delete this.requestCallbacks[response.id];\n }\n\n setup(\n {\n logger,\n endpoint,\n isElementSelectable,\n cssSelectorAllowlist,\n actionClickAllowlist,\n dataExtractor,\n }: {\n logger?: ILogger;\n endpoint?: string;\n isElementSelectable?: (action: InitializeVisualTaggingSelectorData['actionType'], element: Element) => boolean;\n cssSelectorAllowlist?: string[];\n actionClickAllowlist?: string[];\n dataExtractor: DataExtractor;\n } = { dataExtractor: new DataExtractor({}) },\n ) {\n this.logger = logger;\n // If endpoint is customized, don't override it.\n if (endpoint && this.endpoint === AMPLITUDE_ORIGIN) {\n this.endpoint = endpoint;\n }\n let amplitudeVisualTaggingSelectorInstance: any = null;\n\n // Attach Event Listener to listen for messages from the parent window\n window.addEventListener('message', (event) => {\n this.logger?.debug?.('Message received: ', JSON.stringify(event));\n\n // Only accept messages from the specified origin\n if (this.endpoint !== event.origin) {\n return;\n }\n\n const eventData = event?.data as Message<Action> | MessageResponse;\n const action = eventData?.action;\n\n // Ignore messages without action\n if (!action) {\n return;\n }\n\n // If id exists, handle responses to previous requests\n if ('id' in eventData) {\n this.logger?.debug?.('Received Response to previous request: ', JSON.stringify(event));\n this.handleResponse(eventData);\n\n // If action exists, handle the action using existing handlers\n } else {\n if (action === 'ping') {\n this.notify({ action: 'pong' });\n } else if (action === 'initialize-visual-tagging-selector') {\n const actionData = eventData?.data as InitializeVisualTaggingSelectorData;\n asyncLoadScript(AMPLITUDE_VISUAL_TAGGING_SELECTOR_SCRIPT_URL)\n .then(() => {\n // eslint-disable-next-line\n amplitudeVisualTaggingSelectorInstance = (window as any)?.amplitudeVisualTaggingSelector?.({\n getEventTagProps: dataExtractor.getEventTagProps,\n isElementSelectable: (element: Element) => {\n if (isElementSelectable) {\n return isElementSelectable(actionData?.actionType || 'click', element);\n }\n return true;\n },\n onTrack: this.onTrack,\n onSelect: this.onSelect,\n visualHighlightClass: AMPLITUDE_VISUAL_TAGGING_HIGHLIGHT_CLASS,\n messenger: this,\n cssSelectorAllowlist,\n actionClickAllowlist,\n extractDataFromDataSource: dataExtractor.extractDataFromDataSource,\n diagnostics: {\n autocapture: {\n version: VERSION,\n },\n },\n });\n this.notify({ action: 'selector-loaded' });\n })\n .catch(() => {\n this.logger?.warn('Failed to initialize visual tagging selector');\n });\n } else if (action === 'close-visual-tagging-selector') {\n // eslint-disable-next-line\n amplitudeVisualTaggingSelectorInstance?.close?.();\n }\n }\n });\n\n // Notify the parent window that the page has loaded\n this.notify({ action: 'page-loaded' });\n }\n\n private onSelect = (data: ElementSelectedData) => {\n this.notify({ action: 'element-selected', data });\n };\n\n private onTrack = (type: string, properties: { [key: string]: string | null }) => {\n if (type === 'selector-mode-changed') {\n this.notify({ action: 'track-selector-mode-changed', data: properties });\n } else if (type === 'selector-moved') {\n this.notify({ action: 'track-selector-moved', data: properties });\n }\n };\n}\n"]}
1
+ {"version":3,"file":"messenger.js","sourceRoot":"","sources":["../../../src/libs/messenger.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,0CAA0C;AAC1C,OAAO,EACL,gBAAgB,EAChB,4CAA4C,EAC5C,wCAAwC,GACzC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAgElD,yDAAyD;AACzD;IAUE,yBAAY,EAAuD;YAAvD,qBAAqD,EAAE,KAAA,EAArD,cAAyB,EAAzB,MAAM,mBAAG,gBAAgB,KAAA;QAAvC,iBAEC;QAXD,aAAQ,GAAG,gBAAgB,CAAC;QAE5B,qBAAgB,GAKZ,EAAE,CAAC;QAgJC,aAAQ,GAAG,UAAC,IAAyB;YAC3C,KAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;QACpD,CAAC,CAAC;QAEM,YAAO,GAAG,UAAC,IAAY,EAAE,UAA4C;YAC3E,IAAI,IAAI,KAAK,uBAAuB,EAAE;gBACpC,KAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,6BAA6B,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;aAC1E;iBAAM,IAAI,IAAI,KAAK,gBAAgB,EAAE;gBACpC,KAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;aACnE;QACH,CAAC,CAAC;QAvJA,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;IACzB,CAAC;IAEO,gCAAM,GAAd,UAAe,OAAyC;;QACtD,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,mDAAG,gBA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,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;oBAC7C,CAAC,CAAC;yBACD,KAAK,CAAC;;wBACL,MAAA,KAAI,CAAC,MAAM,0CAAE,IAAI,CAAC,8CAA8C,CAAC,CAAC;oBACpE,CAAC,CAAC,CAAC;iBACN;qBAAM,IAAI,MAAM,KAAK,+BAA+B,EAAE;oBACrD,2BAA2B;oBAC3B,MAAA,sCAAsC,aAAtC,sCAAsC,uBAAtC,sCAAsC,CAAE,KAAK,sFAAI,CAAC;iBACnD;aACF;QACH,CAAC,CAAC,CAAC;QAEH,oDAAoD;QACpD,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;IACzC,CAAC;IAaH,sBAAC;AAAD,CAAC,AAnKD,IAmKC","sourcesContent":["/* istanbul ignore file */\n/* eslint-disable no-restricted-globals */\nimport {\n AMPLITUDE_ORIGIN,\n AMPLITUDE_VISUAL_TAGGING_SELECTOR_SCRIPT_URL,\n AMPLITUDE_VISUAL_TAGGING_HIGHLIGHT_CLASS,\n} from '../constants';\nimport { asyncLoadScript, generateUniqueId } from '../helpers';\nimport { ILogger, Messenger, ActionType } from '@amplitude/analytics-core';\nimport { VERSION } from '../version';\nimport { DataExtractor } from '../data-extractor';\n\nexport type Action =\n | 'ping'\n | 'pong'\n | 'page-loaded'\n | 'selector-loaded'\n | 'initialize-visual-tagging-selector'\n | 'close-visual-tagging-selector'\n | 'element-selected'\n | 'track-selector-mode-changed'\n | 'track-selector-moved';\n\ninterface InitializeVisualTaggingSelectorData {\n actionType: ActionType;\n}\n\ninterface ElementSelectedData {\n '[Amplitude] Element Hierarchy'?: string;\n '[Amplitude] Element Tag'?: string;\n '[Amplitude] Element Text'?: string;\n '[Amplitude] Page URL'?: string;\n elementScreenshot?: Blob;\n}\n\ninterface TrackSelectorModeChangedData {\n newMode: string;\n pageUrl?: string;\n}\n\ninterface TrackSelectorMovedData {\n newEditorLocation: string;\n pageUrl?: string;\n}\n\nexport type ActionData = {\n ping: null | undefined;\n pong: null | undefined;\n 'page-loaded': null | undefined;\n 'selector-loaded': null | undefined;\n 'initialize-visual-tagging-selector': InitializeVisualTaggingSelectorData | null | undefined;\n 'close-visual-tagging-selector': null | undefined;\n 'element-selected': ElementSelectedData;\n 'track-selector-mode-changed': TrackSelectorModeChangedData;\n 'track-selector-moved': TrackSelectorMovedData;\n};\n\nexport interface Message<A extends Action> {\n action: A;\n data?: ActionData[A];\n}\n\ntype MessageRequest = {\n id: string;\n action: string;\n args: Record<string, any>;\n};\n\ntype MessageResponse = {\n id: string;\n action: string;\n responseData: any;\n};\n\n// TODO: use MessageChannel instead of window.postMessage\nexport class WindowMessenger implements Messenger {\n endpoint = AMPLITUDE_ORIGIN;\n logger?: ILogger;\n requestCallbacks: {\n [id: string]: {\n resolve: (data: any) => void;\n reject: (data: any) => void;\n };\n } = {};\n\n constructor({ origin = AMPLITUDE_ORIGIN }: { origin?: string } = {}) {\n this.endpoint = origin;\n }\n\n private notify(message: Message<Action> | MessageRequest) {\n this.logger?.debug?.('Message sent: ', JSON.stringify(message));\n (window.opener as WindowProxy)?.postMessage?.(message, this.endpoint);\n }\n\n // Send an async request to the parent window\n public sendRequest(action: string, args: Record<string, any>, options = { timeout: 15_000 }): Promise<any> {\n // Create Request ID\n const id = generateUniqueId();\n const request = {\n id,\n action,\n args,\n };\n\n // Create a Promise that will be resolved when the response is received\n const promise = new Promise((resolve, reject) => {\n this.requestCallbacks[id] = { resolve, reject };\n\n // Send the request\n this.notify(request);\n\n // Handle request timeouts\n if (options?.timeout > 0) {\n setTimeout(() => {\n reject(new Error(`${action} timed out (id: ${id})`));\n delete this.requestCallbacks[id];\n }, options.timeout);\n }\n });\n\n return promise;\n }\n\n // Handle messages from the parent window\n private handleResponse(response: MessageResponse) {\n if (!this.requestCallbacks[response.id]) {\n this.logger?.warn(`No callback found for request id: ${response.id}`);\n return;\n }\n\n this.requestCallbacks[response.id].resolve(response.responseData);\n delete this.requestCallbacks[response.id];\n }\n\n setup(\n {\n logger,\n endpoint,\n isElementSelectable,\n cssSelectorAllowlist,\n actionClickAllowlist,\n dataExtractor,\n }: {\n logger?: ILogger;\n endpoint?: string;\n isElementSelectable?: (action: InitializeVisualTaggingSelectorData['actionType'], element: Element) => boolean;\n cssSelectorAllowlist?: string[];\n actionClickAllowlist?: string[];\n dataExtractor: DataExtractor;\n } = { dataExtractor: new DataExtractor({}) },\n ) {\n this.logger = logger;\n // If endpoint is customized, don't override it.\n if (endpoint && this.endpoint === AMPLITUDE_ORIGIN) {\n this.endpoint = endpoint;\n }\n let amplitudeVisualTaggingSelectorInstance: any = null;\n\n // Attach Event Listener to listen for messages from the parent window\n window.addEventListener('message', (event) => {\n this.logger?.debug?.('Message received: ', JSON.stringify(event));\n\n // Only accept messages from the specified origin\n if (this.endpoint !== event.origin) {\n return;\n }\n\n const eventData = event?.data as Message<Action> | MessageResponse;\n const action = eventData?.action;\n\n // Ignore messages without action\n if (!action) {\n return;\n }\n\n // If id exists, handle responses to previous requests\n if ('id' in eventData) {\n this.logger?.debug?.('Received Response to previous request: ', JSON.stringify(event));\n this.handleResponse(eventData);\n\n // If action exists, handle the action using existing handlers\n } else {\n if (action === 'ping') {\n this.notify({ action: 'pong' });\n } else if (action === 'initialize-visual-tagging-selector') {\n const actionData = eventData?.data as InitializeVisualTaggingSelectorData;\n asyncLoadScript(AMPLITUDE_VISUAL_TAGGING_SELECTOR_SCRIPT_URL)\n .then(() => {\n // eslint-disable-next-line\n amplitudeVisualTaggingSelectorInstance = (window as any)?.amplitudeVisualTaggingSelector?.({\n getEventTagProps: dataExtractor.getEventTagProps,\n isElementSelectable: (element: Element) => {\n if (isElementSelectable) {\n return isElementSelectable(actionData?.actionType || 'click', element);\n }\n return true;\n },\n onTrack: this.onTrack,\n onSelect: this.onSelect,\n visualHighlightClass: AMPLITUDE_VISUAL_TAGGING_HIGHLIGHT_CLASS,\n messenger: this,\n cssSelectorAllowlist,\n actionClickAllowlist,\n extractDataFromDataSource: dataExtractor.extractDataFromDataSource,\n dataExtractor,\n diagnostics: {\n autocapture: {\n version: VERSION,\n },\n },\n });\n this.notify({ action: 'selector-loaded' });\n })\n .catch(() => {\n this.logger?.warn('Failed to initialize visual tagging selector');\n });\n } else if (action === 'close-visual-tagging-selector') {\n // eslint-disable-next-line\n amplitudeVisualTaggingSelectorInstance?.close?.();\n }\n }\n });\n\n // Notify the parent window that the page has loaded\n this.notify({ action: 'page-loaded' });\n }\n\n private onSelect = (data: ElementSelectedData) => {\n this.notify({ action: 'element-selected', data });\n };\n\n private onTrack = (type: string, properties: { [key: string]: string | null }) => {\n if (type === 'selector-mode-changed') {\n this.notify({ action: 'track-selector-mode-changed', data: properties });\n } else if (type === 'selector-moved') {\n this.notify({ action: 'track-selector-moved', data: properties });\n }\n };\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { DataSource, PageAction } from '@amplitude/analytics-core/lib/esm/types/element-interactions';
2
- import type { DataExtractor } from 'src/data-extractor';
3
- import type { ElementBasedTimestampedEvent, ElementBasedEvent } from 'src/helpers';
2
+ import type { DataExtractor } from '../data-extractor';
3
+ import type { ElementBasedTimestampedEvent, ElementBasedEvent } from '../helpers';
4
4
  /**
5
5
  * Gets the DOM element specified by the data source configuration
6
6
  * @param dataSource - Configuration for finding the target element
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/pageActions/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,8DAA8D,CAAC;AAC3G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGnF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,eAAgB,UAAU,kBAAkB,WAAW,+BAwBhF,CAAC;AAGF,eAAO,MAAM,cAAc,YAChB,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,MAC5B,6BAA6B,iBAAiB,CAAC,iBACpC,aAAa,SAe7B,CAAC"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/pageActions/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,8DAA8D,CAAC;AAC3G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,4BAA4B,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGlF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,eAAgB,UAAU,kBAAkB,WAAW,+BAwBhF,CAAC;AAGF,eAAO,MAAM,cAAc,YAChB,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,MAC5B,6BAA6B,iBAAiB,CAAC,iBACpC,aAAa,SAe7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/pageActions/actions.ts"],"names":[],"mappings":"AAIA,iBAAiB;AACjB;;;;;GAKG;AACH,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,UAAsB,EAAE,cAA2B;IAC/E,6CAA6C;IAC7C,IAAI;QACF,IAAI,UAAU,CAAC,UAAU,KAAK,aAAa,EAAE;YAC3C,4HAA4H;YAC5H,IAAI,cAAc,GAAuB,QAAQ,CAAC,eAAe,CAAC;YAClE,IAAI,UAAU,CAAC,KAAK,IAAI,cAAc,EAAE;gBACtC,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAC3D;YAED,kEAAkE;YAClE,IAAI,cAAc,IAAI,UAAU,CAAC,QAAQ,EAAE;gBACzC,OAAO,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;aAC1D;YAED,qDAAqD;YACrD,OAAO,cAAc,CAAC;SACvB;KACF;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,SAAS,CAAC;KAClB;IAED,oDAAoD;IACpD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,qFAAqF;AACrF,MAAM,CAAC,IAAM,cAAc,GAAG,UAC5B,OAAgC,EAChC,EAAmD,EACnD,aAA4B;IAE5B,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;QACrB,4DAA4D;QAC5D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,OAAO;SACR;QAED,IAAI,MAAM,CAAC,UAAU,KAAK,uBAAuB,EAAE;YACjD,IAAM,IAAI,GAAG,aAAa,CAAC,yBAAyB,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,sBAAqC,CAAC,CAAC;YAElH,uBAAuB;YACvB,EAAE,CAAC,uBAAuB,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;SAC1D;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { DataSource, PageAction } from '@amplitude/analytics-core/lib/esm/types/element-interactions';\nimport type { DataExtractor } from 'src/data-extractor';\nimport type { ElementBasedTimestampedEvent, ElementBasedEvent } from 'src/helpers';\n\n// Get DataSource\n/**\n * Gets the DOM element specified by the data source configuration\n * @param dataSource - Configuration for finding the target element\n * @param contextElement - The element to start searching from\n * @returns The matching DOM element or undefined if not found\n */\nexport const getDataSource = (dataSource: DataSource, contextElement: HTMLElement) => {\n // Only process DOM_ELEMENT type data sources\n try {\n if (dataSource.sourceType === 'DOM_ELEMENT') {\n // If scope is specified, find the closest ancestor matching the scope rather than using documentElement (html) as the scope\n let scopingElement: HTMLElement | null = document.documentElement;\n if (dataSource.scope && contextElement) {\n scopingElement = contextElement.closest(dataSource.scope);\n }\n\n // If we have both a scope and selector, find the matching element\n if (scopingElement && dataSource.selector) {\n return scopingElement.querySelector(dataSource.selector);\n }\n\n // Return scopingElement if no selector was specified\n return scopingElement;\n }\n } catch (error) {\n return undefined;\n }\n\n // Return undefined for non-DOM_ELEMENT data sources\n return undefined;\n};\n\n// Execute actions for a condition and attach event properties to the event if needed\nexport const executeActions = (\n actions: (string | PageAction)[],\n ev: ElementBasedTimestampedEvent<ElementBasedEvent>,\n dataExtractor: DataExtractor,\n) => {\n actions.forEach((action) => {\n // Skip if actions is string until action set is implemented\n if (typeof action === 'string') {\n return;\n }\n\n if (action.actionType === 'ATTACH_EVENT_PROPERTY') {\n const data = dataExtractor.extractDataFromDataSource(action.dataSource, ev.closestTrackedAncestor as HTMLElement);\n\n // Attach data to event\n ev.targetElementProperties[action.destinationKey] = data;\n }\n });\n};\n"]}
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/pageActions/actions.ts"],"names":[],"mappings":"AAIA,iBAAiB;AACjB;;;;;GAKG;AACH,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,UAAsB,EAAE,cAA2B;IAC/E,6CAA6C;IAC7C,IAAI;QACF,IAAI,UAAU,CAAC,UAAU,KAAK,aAAa,EAAE;YAC3C,4HAA4H;YAC5H,IAAI,cAAc,GAAuB,QAAQ,CAAC,eAAe,CAAC;YAClE,IAAI,UAAU,CAAC,KAAK,IAAI,cAAc,EAAE;gBACtC,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAC3D;YAED,kEAAkE;YAClE,IAAI,cAAc,IAAI,UAAU,CAAC,QAAQ,EAAE;gBACzC,OAAO,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;aAC1D;YAED,qDAAqD;YACrD,OAAO,cAAc,CAAC;SACvB;KACF;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,SAAS,CAAC;KAClB;IAED,oDAAoD;IACpD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,qFAAqF;AACrF,MAAM,CAAC,IAAM,cAAc,GAAG,UAC5B,OAAgC,EAChC,EAAmD,EACnD,aAA4B;IAE5B,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;QACrB,4DAA4D;QAC5D,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,OAAO;SACR;QAED,IAAI,MAAM,CAAC,UAAU,KAAK,uBAAuB,EAAE;YACjD,IAAM,IAAI,GAAG,aAAa,CAAC,yBAAyB,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,sBAAqC,CAAC,CAAC;YAElH,uBAAuB;YACvB,EAAE,CAAC,uBAAuB,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;SAC1D;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { DataSource, PageAction } from '@amplitude/analytics-core/lib/esm/types/element-interactions';\nimport type { DataExtractor } from '../data-extractor';\nimport type { ElementBasedTimestampedEvent, ElementBasedEvent } from '../helpers';\n\n// Get DataSource\n/**\n * Gets the DOM element specified by the data source configuration\n * @param dataSource - Configuration for finding the target element\n * @param contextElement - The element to start searching from\n * @returns The matching DOM element or undefined if not found\n */\nexport const getDataSource = (dataSource: DataSource, contextElement: HTMLElement) => {\n // Only process DOM_ELEMENT type data sources\n try {\n if (dataSource.sourceType === 'DOM_ELEMENT') {\n // If scope is specified, find the closest ancestor matching the scope rather than using documentElement (html) as the scope\n let scopingElement: HTMLElement | null = document.documentElement;\n if (dataSource.scope && contextElement) {\n scopingElement = contextElement.closest(dataSource.scope);\n }\n\n // If we have both a scope and selector, find the matching element\n if (scopingElement && dataSource.selector) {\n return scopingElement.querySelector(dataSource.selector);\n }\n\n // Return scopingElement if no selector was specified\n return scopingElement;\n }\n } catch (error) {\n return undefined;\n }\n\n // Return undefined for non-DOM_ELEMENT data sources\n return undefined;\n};\n\n// Execute actions for a condition and attach event properties to the event if needed\nexport const executeActions = (\n actions: (string | PageAction)[],\n ev: ElementBasedTimestampedEvent<ElementBasedEvent>,\n dataExtractor: DataExtractor,\n) => {\n actions.forEach((action) => {\n // Skip if actions is string until action set is implemented\n if (typeof action === 'string') {\n return;\n }\n\n if (action.actionType === 'ATTACH_EVENT_PROPERTY') {\n const data = dataExtractor.extractDataFromDataSource(action.dataSource, ev.closestTrackedAncestor as HTMLElement);\n\n // Attach data to event\n ev.targetElementProperties[action.destinationKey] = data;\n }\n });\n};\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.11.1";
1
+ export declare const VERSION = "1.12.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,2 +1,2 @@
1
- export var VERSION = '1.11.1';
1
+ export var VERSION = '1.12.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.11.1';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["export const VERSION = '1.12.0';\n"]}