@posthog/browser-common 0.0.0 → 0.2.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/README.md +114 -28
- package/dist/client.d.ts +136 -0
- package/dist/client.js +18 -0
- package/dist/client.mjs +0 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +43 -0
- package/dist/config.mjs +9 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +44 -0
- package/dist/constants.mjs +4 -0
- package/dist/disposable.d.ts +13 -0
- package/dist/disposable.js +18 -0
- package/dist/disposable.mjs +0 -0
- package/dist/extension.d.ts +45 -0
- package/dist/extension.js +18 -0
- package/dist/extension.mjs +0 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +36 -0
- package/dist/index.mjs +2 -0
- package/dist/persistence.d.ts +24 -0
- package/dist/persistence.js +18 -0
- package/dist/persistence.mjs +0 -0
- package/dist/pubsub.d.ts +28 -0
- package/dist/pubsub.js +67 -0
- package/dist/pubsub.mjs +33 -0
- package/dist/token.d.ts +21 -0
- package/dist/token.js +18 -0
- package/dist/token.mjs +0 -0
- package/dist/utils/array-at-polyfill.d.ts +1 -0
- package/dist/utils/array-at-polyfill.js +16 -0
- package/dist/utils/array-at-polyfill.mjs +11 -0
- package/dist/utils/autocapture-utils.d.ts +23 -0
- package/dist/utils/autocapture-utils.js +479 -0
- package/dist/utils/autocapture-utils.mjs +385 -0
- package/dist/utils/blocked-uas.d.ts +17 -0
- package/dist/utils/blocked-uas.js +54 -0
- package/dist/utils/blocked-uas.mjs +14 -0
- package/dist/utils/cookie-utils.d.ts +1 -0
- package/dist/utils/cookie-utils.js +49 -0
- package/dist/utils/cookie-utils.mjs +15 -0
- package/dist/utils/device-model-utils.d.ts +8 -0
- package/dist/utils/device-model-utils.js +52 -0
- package/dist/utils/device-model-utils.mjs +18 -0
- package/dist/utils/element-utils.d.ts +5 -0
- package/dist/utils/element-utils.js +67 -0
- package/dist/utils/element-utils.mjs +21 -0
- package/dist/utils/elements-chain-utils.d.ts +4 -0
- package/dist/utils/elements-chain-utils.js +79 -0
- package/dist/utils/elements-chain-utils.mjs +36 -0
- package/dist/utils/encode-utils.d.ts +8 -0
- package/dist/utils/encode-utils.js +39 -0
- package/dist/utils/encode-utils.mjs +5 -0
- package/dist/utils/event-utils.d.ts +24 -0
- package/dist/utils/event-utils.js +344 -0
- package/dist/utils/event-utils.mjs +246 -0
- package/dist/utils/general-utils.d.ts +30 -0
- package/dist/utils/general-utils.js +191 -0
- package/dist/utils/general-utils.mjs +118 -0
- package/dist/utils/globals.d.ts +25 -0
- package/dist/utils/globals.js +75 -0
- package/dist/utils/globals.mjs +14 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +83 -0
- package/dist/utils/logger.mjs +36 -0
- package/dist/utils/matcher-utils.d.ts +3 -0
- package/dist/utils/matcher-utils.js +63 -0
- package/dist/utils/matcher-utils.mjs +26 -0
- package/dist/utils/property-utils.d.ts +23 -0
- package/dist/utils/property-utils.js +108 -0
- package/dist/utils/property-utils.mjs +65 -0
- package/dist/utils/prototype-utils.d.ts +7 -0
- package/dist/utils/prototype-utils.js +64 -0
- package/dist/utils/prototype-utils.mjs +27 -0
- package/dist/utils/regex-utils.d.ts +2 -0
- package/dist/utils/regex-utils.js +54 -0
- package/dist/utils/regex-utils.mjs +17 -0
- package/dist/utils/request-utils.d.ts +15 -0
- package/dist/utils/request-utils.js +153 -0
- package/dist/utils/request-utils.mjs +95 -0
- package/dist/utils/simple-event-emitter.d.ts +5 -0
- package/dist/utils/simple-event-emitter.js +51 -0
- package/dist/utils/simple-event-emitter.mjs +17 -0
- package/dist/utils/stylesheet-loader.d.ts +7 -0
- package/dist/utils/stylesheet-loader.js +53 -0
- package/dist/utils/stylesheet-loader.mjs +19 -0
- package/dist/utils/type-utils.d.ts +2 -0
- package/dist/utils/type-utils.js +41 -0
- package/dist/utils/type-utils.mjs +4 -0
- package/dist/utils/url-targeting-utils.d.ts +28 -0
- package/dist/utils/url-targeting-utils.js +56 -0
- package/dist/utils/url-targeting-utils.mjs +19 -0
- package/dist/utils/uuidv7.d.ts +43 -0
- package/dist/utils/uuidv7.js +172 -0
- package/dist/utils/uuidv7.js.LICENSE.txt +9 -0
- package/dist/utils/uuidv7.mjs +132 -0
- package/dist/utils/uuidv7.mjs.LICENSE.txt +9 -0
- package/package.json +79 -8
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
isTextSelectionTarget: ()=>isTextSelectionTarget,
|
|
28
|
+
shouldCaptureRageclick: ()=>shouldCaptureRageclick,
|
|
29
|
+
shouldCaptureValue: ()=>shouldCaptureValue,
|
|
30
|
+
splitClassString: ()=>splitClassString,
|
|
31
|
+
shouldCaptureDomEvent: ()=>shouldCaptureDomEvent,
|
|
32
|
+
getEventTarget: ()=>getEventTarget,
|
|
33
|
+
getNestedSpanText: ()=>getNestedSpanText,
|
|
34
|
+
isAngularStyleAttr: ()=>isAngularStyleAttr,
|
|
35
|
+
getSafeText: ()=>getSafeText,
|
|
36
|
+
isSensitiveElement: ()=>isSensitiveElement,
|
|
37
|
+
shouldSkipDeadClick: ()=>shouldSkipDeadClick,
|
|
38
|
+
autocaptureCompatibleElements: ()=>autocaptureCompatibleElements,
|
|
39
|
+
makeSafeText: ()=>makeSafeText,
|
|
40
|
+
shouldCaptureDeadClick: ()=>shouldCaptureDeadClick,
|
|
41
|
+
getClassNames: ()=>getClassNames,
|
|
42
|
+
getDirectAndNestedSpanText: ()=>getDirectAndNestedSpanText,
|
|
43
|
+
getParentElement: ()=>getParentElement,
|
|
44
|
+
shouldCaptureElement: ()=>shouldCaptureElement,
|
|
45
|
+
MAX_DOM_ANCESTOR_DEPTH: ()=>MAX_DOM_ANCESTOR_DEPTH,
|
|
46
|
+
DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS: ()=>DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS,
|
|
47
|
+
getElementsChainString: ()=>getElementsChainString
|
|
48
|
+
});
|
|
49
|
+
const external_general_utils_js_namespaceObject = require("./general-utils.js");
|
|
50
|
+
const core_namespaceObject = require("@posthog/core");
|
|
51
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
52
|
+
const external_globals_js_namespaceObject = require("./globals.js");
|
|
53
|
+
const external_url_targeting_utils_js_namespaceObject = require("./url-targeting-utils.js");
|
|
54
|
+
const external_element_utils_js_namespaceObject = require("./element-utils.js");
|
|
55
|
+
const MAX_DOM_ANCESTOR_DEPTH = 1000;
|
|
56
|
+
function splitClassString(s) {
|
|
57
|
+
return s ? (0, core_namespaceObject.trim)(s).split(/\s+/) : [];
|
|
58
|
+
}
|
|
59
|
+
function checkForURLMatches(urlsList, instance) {
|
|
60
|
+
const url = (0, external_url_targeting_utils_js_namespaceObject.getTargetingUrl)(instance);
|
|
61
|
+
return !!(url && urlsList && urlsList.some((regex)=>url.match(regex)));
|
|
62
|
+
}
|
|
63
|
+
function getClassNames(el) {
|
|
64
|
+
let className = '';
|
|
65
|
+
switch(typeof el.className){
|
|
66
|
+
case 'string':
|
|
67
|
+
className = el.className;
|
|
68
|
+
break;
|
|
69
|
+
case 'object':
|
|
70
|
+
className = (el.className && 'baseVal' in el.className ? el.className.baseVal : null) || el.getAttribute('class') || '';
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
className = '';
|
|
74
|
+
}
|
|
75
|
+
return splitClassString(className);
|
|
76
|
+
}
|
|
77
|
+
function makeSafeText(s) {
|
|
78
|
+
if ((0, core_namespaceObject.isNullish)(s)) return null;
|
|
79
|
+
return (0, core_namespaceObject.trim)(s).split(/(\s+)/).filter((s)=>shouldCaptureValue(s)).join('').replace(/[\r\n]/g, ' ').replace(/[ ]+/g, ' ').substring(0, 255);
|
|
80
|
+
}
|
|
81
|
+
function getSafeText(el) {
|
|
82
|
+
let elText = '';
|
|
83
|
+
if (shouldCaptureElement(el) && !isSensitiveElement(el) && el.childNodes && el.childNodes.length) (0, external_general_utils_js_namespaceObject.each)(el.childNodes, function(child) {
|
|
84
|
+
if ((0, external_element_utils_js_namespaceObject.isTextNode)(child) && child.textContent) elText += makeSafeText(child.textContent) ?? '';
|
|
85
|
+
});
|
|
86
|
+
return (0, core_namespaceObject.trim)(elText);
|
|
87
|
+
}
|
|
88
|
+
function getEventTarget(e) {
|
|
89
|
+
if ((0, core_namespaceObject.isUndefined)(e.target)) return e.srcElement || null;
|
|
90
|
+
if (e.target?.shadowRoot) return e.composedPath()[0] || null;
|
|
91
|
+
return e.target || null;
|
|
92
|
+
}
|
|
93
|
+
const autocaptureCompatibleElements = [
|
|
94
|
+
'a',
|
|
95
|
+
'button',
|
|
96
|
+
'form',
|
|
97
|
+
'input',
|
|
98
|
+
'select',
|
|
99
|
+
'textarea',
|
|
100
|
+
'label'
|
|
101
|
+
];
|
|
102
|
+
function checkIfElementTreePassesElementAllowList(elements, autocaptureConfig) {
|
|
103
|
+
const allowlist = autocaptureConfig?.element_allowlist;
|
|
104
|
+
if ((0, core_namespaceObject.isUndefined)(allowlist)) return true;
|
|
105
|
+
for (const el of elements)if (allowlist.some((elementType)=>el.tagName.toLowerCase() === elementType)) return true;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
function elementMatchesCSSSelector(el, selector) {
|
|
109
|
+
const matches = el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector;
|
|
110
|
+
try {
|
|
111
|
+
return matches ? matches.call(el, selector) : false;
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function checkIfElementsMatchCSSSelector(elements, selectorList) {
|
|
117
|
+
if ((0, core_namespaceObject.isUndefined)(selectorList)) return true;
|
|
118
|
+
for (const el of elements)if (selectorList.some((selector)=>elementMatchesCSSSelector(el, selector))) return true;
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
function getParentElement(curEl) {
|
|
122
|
+
const parentNode = curEl.parentNode;
|
|
123
|
+
if (!parentNode || !(0, external_element_utils_js_namespaceObject.isElementNode)(parentNode)) return false;
|
|
124
|
+
return parentNode;
|
|
125
|
+
}
|
|
126
|
+
const DEFAULT_AUTOCAPTURE_IGNORE_LIST = [
|
|
127
|
+
'.ph-no-autocapture',
|
|
128
|
+
'[data-ph-no-autocapture]'
|
|
129
|
+
];
|
|
130
|
+
const DEFAULT_CONTENT_IGNORELIST = [
|
|
131
|
+
'next',
|
|
132
|
+
'previous',
|
|
133
|
+
'prev',
|
|
134
|
+
'>',
|
|
135
|
+
'<'
|
|
136
|
+
];
|
|
137
|
+
const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = [
|
|
138
|
+
...DEFAULT_CONTENT_IGNORELIST,
|
|
139
|
+
'+',
|
|
140
|
+
'-',
|
|
141
|
+
"\u2212",
|
|
142
|
+
"\u2013"
|
|
143
|
+
];
|
|
144
|
+
const MAX_CONTENT_IGNORELIST_ENTRIES = 10;
|
|
145
|
+
const matchesContentKeyword = (text, keyword)=>/[a-z0-9]/i.test(keyword) ? text.includes(keyword) : text === keyword;
|
|
146
|
+
function shouldIgnoreByContent(contentIgnorelist, elementsWithText) {
|
|
147
|
+
if (false === contentIgnorelist || (0, core_namespaceObject.isUndefined)(contentIgnorelist)) return false;
|
|
148
|
+
let keywords;
|
|
149
|
+
if (true === contentIgnorelist) keywords = DEFAULT_CONTENT_IGNORELIST;
|
|
150
|
+
else {
|
|
151
|
+
if (!(0, core_namespaceObject.isArray)(contentIgnorelist)) return false;
|
|
152
|
+
if (contentIgnorelist.length > MAX_CONTENT_IGNORELIST_ENTRIES) {
|
|
153
|
+
external_logger_js_namespaceObject.logger.error(`[PostHog] content_ignorelist array cannot exceed ${MAX_CONTENT_IGNORELIST_ENTRIES} items. Use css_selector_ignorelist for more complex matching.`);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
keywords = contentIgnorelist.map((k)=>k.toLowerCase());
|
|
157
|
+
}
|
|
158
|
+
return elementsWithText.some(({ safeText, ariaLabel })=>keywords.some((keyword)=>matchesContentKeyword(safeText, keyword) || matchesContentKeyword(ariaLabel, keyword)));
|
|
159
|
+
}
|
|
160
|
+
const DEFAULT_DEAD_CLICK_IGNORE_LIST = [
|
|
161
|
+
'.ph-no-deadclick',
|
|
162
|
+
'.ph-no-capture'
|
|
163
|
+
];
|
|
164
|
+
function shouldCaptureDeadClick(el, _config) {
|
|
165
|
+
if (!external_globals_js_namespaceObject.window || cannotCheckForAutocapture(el)) return false;
|
|
166
|
+
const selectorIgnoreList = (0, core_namespaceObject.isBoolean)(_config) ? DEFAULT_DEAD_CLICK_IGNORE_LIST : _config?.css_selector_ignorelist ?? DEFAULT_DEAD_CLICK_IGNORE_LIST;
|
|
167
|
+
const { targetElementList } = getElementAndParentsForElement(el, false);
|
|
168
|
+
return !checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList);
|
|
169
|
+
}
|
|
170
|
+
const DEFAULT_RAGE_CLICK_IGNORE_LIST = [
|
|
171
|
+
'.ph-no-rageclick',
|
|
172
|
+
'.ph-no-capture'
|
|
173
|
+
];
|
|
174
|
+
const TEXT_SELECTION_INPUT_TYPES = [
|
|
175
|
+
'',
|
|
176
|
+
'text',
|
|
177
|
+
'search',
|
|
178
|
+
'email',
|
|
179
|
+
'password',
|
|
180
|
+
'url',
|
|
181
|
+
'tel',
|
|
182
|
+
'number'
|
|
183
|
+
];
|
|
184
|
+
function isContentEditableTarget(el) {
|
|
185
|
+
if (el.isContentEditable) return true;
|
|
186
|
+
const contentEditable = el.getAttribute?.('contenteditable');
|
|
187
|
+
return 'true' === contentEditable || '' === contentEditable;
|
|
188
|
+
}
|
|
189
|
+
function isTextSelectionTarget(el) {
|
|
190
|
+
if (!el || !(0, external_element_utils_js_namespaceObject.isElementNode)(el)) return false;
|
|
191
|
+
if ((0, external_element_utils_js_namespaceObject.isTag)(el, 'textarea')) return true;
|
|
192
|
+
if ((0, external_element_utils_js_namespaceObject.isTag)(el, 'input')) return (0, core_namespaceObject.includes)(TEXT_SELECTION_INPUT_TYPES, (el.getAttribute('type') || '').toLowerCase());
|
|
193
|
+
return isContentEditableTarget(el);
|
|
194
|
+
}
|
|
195
|
+
function shouldCaptureRageclick(el, _config) {
|
|
196
|
+
if (!external_globals_js_namespaceObject.window || cannotCheckForAutocapture(el)) return false;
|
|
197
|
+
let selectorIgnoreList;
|
|
198
|
+
let contentIgnorelist;
|
|
199
|
+
let ignoreTextSelection;
|
|
200
|
+
if ((0, core_namespaceObject.isBoolean)(_config)) {
|
|
201
|
+
selectorIgnoreList = _config ? DEFAULT_RAGE_CLICK_IGNORE_LIST : false;
|
|
202
|
+
contentIgnorelist = void 0;
|
|
203
|
+
ignoreTextSelection = false;
|
|
204
|
+
} else {
|
|
205
|
+
selectorIgnoreList = _config?.css_selector_ignorelist ?? DEFAULT_RAGE_CLICK_IGNORE_LIST;
|
|
206
|
+
contentIgnorelist = _config?.content_ignorelist;
|
|
207
|
+
ignoreTextSelection = _config?.ignore_text_selection ?? false;
|
|
208
|
+
}
|
|
209
|
+
if (false === selectorIgnoreList) return false;
|
|
210
|
+
if (ignoreTextSelection && isTextSelectionTarget(el)) return false;
|
|
211
|
+
const { targetElementList } = getElementAndParentsForElement(el, false);
|
|
212
|
+
const elementsWithText = targetElementList.map((element)=>({
|
|
213
|
+
safeText: getSafeText(element).toLowerCase(),
|
|
214
|
+
ariaLabel: element.getAttribute('aria-label')?.toLowerCase().trim() || ''
|
|
215
|
+
}));
|
|
216
|
+
if (shouldIgnoreByContent(contentIgnorelist, elementsWithText)) return false;
|
|
217
|
+
return !checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList);
|
|
218
|
+
}
|
|
219
|
+
const cannotCheckForAutocapture = (el)=>!el || (0, external_element_utils_js_namespaceObject.isTag)(el, 'html') || !(0, external_element_utils_js_namespaceObject.isElementNode)(el);
|
|
220
|
+
const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
|
|
221
|
+
if (!external_globals_js_namespaceObject.window || cannotCheckForAutocapture(el)) return {
|
|
222
|
+
parentIsUsefulElement: false,
|
|
223
|
+
targetElementList: []
|
|
224
|
+
};
|
|
225
|
+
let parentIsUsefulElement = false;
|
|
226
|
+
const targetElementList = [
|
|
227
|
+
el
|
|
228
|
+
];
|
|
229
|
+
let curEl = el;
|
|
230
|
+
while(curEl.parentNode && !(0, external_element_utils_js_namespaceObject.isTag)(curEl, 'body')){
|
|
231
|
+
if ((0, external_element_utils_js_namespaceObject.isShadowRoot)(curEl.parentNode)) {
|
|
232
|
+
targetElementList.push(curEl.parentNode.host);
|
|
233
|
+
curEl = curEl.parentNode.host;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const parentNode = getParentElement(curEl);
|
|
237
|
+
if (!parentNode) break;
|
|
238
|
+
if (captureOnAnyElement || autocaptureCompatibleElements.indexOf(parentNode.tagName.toLowerCase()) > -1) parentIsUsefulElement = true;
|
|
239
|
+
else try {
|
|
240
|
+
const compStyles = external_globals_js_namespaceObject.window.getComputedStyle(parentNode);
|
|
241
|
+
if (compStyles && 'pointer' === compStyles.getPropertyValue('cursor')) parentIsUsefulElement = true;
|
|
242
|
+
} catch {}
|
|
243
|
+
targetElementList.push(parentNode);
|
|
244
|
+
curEl = parentNode;
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
parentIsUsefulElement,
|
|
248
|
+
targetElementList
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
function shouldSkipDeadClick(el) {
|
|
252
|
+
if (!external_globals_js_namespaceObject.window || cannotCheckForAutocapture(el)) return false;
|
|
253
|
+
const { targetElementList } = getElementAndParentsForElement(el, false);
|
|
254
|
+
return targetElementList.some((node)=>(0, external_element_utils_js_namespaceObject.isTag)(node, 'a'));
|
|
255
|
+
}
|
|
256
|
+
function shouldCaptureDomEvent(el, event, autocaptureConfig, captureOnAnyElement, allowedEventTypes, instance) {
|
|
257
|
+
if (!external_globals_js_namespaceObject.window || cannotCheckForAutocapture(el)) return false;
|
|
258
|
+
if (autocaptureConfig?.url_allowlist) {
|
|
259
|
+
if (!checkForURLMatches(autocaptureConfig.url_allowlist, instance)) return false;
|
|
260
|
+
}
|
|
261
|
+
if (autocaptureConfig?.url_ignorelist) {
|
|
262
|
+
if (checkForURLMatches(autocaptureConfig.url_ignorelist, instance)) return false;
|
|
263
|
+
}
|
|
264
|
+
if (autocaptureConfig?.dom_event_allowlist) {
|
|
265
|
+
const allowlist = autocaptureConfig.dom_event_allowlist;
|
|
266
|
+
if (allowlist && !allowlist.some((eventType)=>event.type === eventType)) return false;
|
|
267
|
+
}
|
|
268
|
+
const { parentIsUsefulElement, targetElementList } = getElementAndParentsForElement(el, captureOnAnyElement);
|
|
269
|
+
if (!checkIfElementTreePassesElementAllowList(targetElementList, autocaptureConfig)) return false;
|
|
270
|
+
if (!checkIfElementsMatchCSSSelector(targetElementList, autocaptureConfig?.css_selector_allowlist)) return false;
|
|
271
|
+
const selectorIgnoreList = autocaptureConfig?.css_selector_ignorelist ?? DEFAULT_AUTOCAPTURE_IGNORE_LIST;
|
|
272
|
+
if (checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList)) return false;
|
|
273
|
+
try {
|
|
274
|
+
const compStyles = external_globals_js_namespaceObject.window.getComputedStyle(el);
|
|
275
|
+
if (compStyles && 'pointer' === compStyles.getPropertyValue('cursor') && 'click' === event.type) return true;
|
|
276
|
+
} catch {}
|
|
277
|
+
const tag = el.tagName.toLowerCase();
|
|
278
|
+
switch(tag){
|
|
279
|
+
case 'html':
|
|
280
|
+
return false;
|
|
281
|
+
case 'form':
|
|
282
|
+
return (allowedEventTypes || [
|
|
283
|
+
'submit'
|
|
284
|
+
]).indexOf(event.type) >= 0;
|
|
285
|
+
case 'input':
|
|
286
|
+
case 'select':
|
|
287
|
+
case 'textarea':
|
|
288
|
+
return (allowedEventTypes || [
|
|
289
|
+
'change',
|
|
290
|
+
'click'
|
|
291
|
+
]).indexOf(event.type) >= 0;
|
|
292
|
+
default:
|
|
293
|
+
if (parentIsUsefulElement) return (allowedEventTypes || [
|
|
294
|
+
'click'
|
|
295
|
+
]).indexOf(event.type) >= 0;
|
|
296
|
+
return (allowedEventTypes || [
|
|
297
|
+
'click'
|
|
298
|
+
]).indexOf(event.type) >= 0 && (autocaptureCompatibleElements.indexOf(tag) > -1 || 'true' === el.getAttribute('contenteditable'));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function shouldCaptureElement(el) {
|
|
302
|
+
const seen = new Set();
|
|
303
|
+
let depth = 0;
|
|
304
|
+
for(let curEl = el; curEl.parentNode && !(0, external_element_utils_js_namespaceObject.isTag)(curEl, 'body'); curEl = curEl.parentNode){
|
|
305
|
+
if (depth++ >= MAX_DOM_ANCESTOR_DEPTH || seen.has(curEl)) return false;
|
|
306
|
+
seen.add(curEl);
|
|
307
|
+
const classes = getClassNames(curEl);
|
|
308
|
+
if ((0, core_namespaceObject.includes)(classes, 'ph-sensitive') || (0, core_namespaceObject.includes)(classes, 'ph-no-capture')) return false;
|
|
309
|
+
}
|
|
310
|
+
if ((0, core_namespaceObject.includes)(getClassNames(el), 'ph-include')) return true;
|
|
311
|
+
const type = el.type || '';
|
|
312
|
+
if ((0, core_namespaceObject.isString)(type)) switch(type.toLowerCase()){
|
|
313
|
+
case 'hidden':
|
|
314
|
+
return false;
|
|
315
|
+
case 'password':
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
const name = el.name || el.id || '';
|
|
319
|
+
if ((0, core_namespaceObject.isString)(name)) {
|
|
320
|
+
const sensitiveNameRegex = /^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i;
|
|
321
|
+
if (sensitiveNameRegex.test(name.replace(/[^a-zA-Z0-9]/g, ''))) return false;
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
function isSensitiveElement(el) {
|
|
326
|
+
const allowedInputTypes = [
|
|
327
|
+
'button',
|
|
328
|
+
'checkbox',
|
|
329
|
+
'submit',
|
|
330
|
+
'reset'
|
|
331
|
+
];
|
|
332
|
+
if ((0, external_element_utils_js_namespaceObject.isTag)(el, 'input') && !allowedInputTypes.includes(el.type) || (0, external_element_utils_js_namespaceObject.isTag)(el, 'select') || (0, external_element_utils_js_namespaceObject.isTag)(el, 'textarea') || 'true' === el.getAttribute('contenteditable')) return true;
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const coreCCPattern = "(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})";
|
|
336
|
+
const anchoredCCRegex = new RegExp(`^(?:${coreCCPattern})$`);
|
|
337
|
+
const unanchoredCCRegex = new RegExp(coreCCPattern);
|
|
338
|
+
const coreSSNPattern = "\\d{3}-?\\d{2}-?\\d{4}";
|
|
339
|
+
const anchoredSSNRegex = new RegExp(`^(${coreSSNPattern})$`);
|
|
340
|
+
const unanchoredSSNRegex = new RegExp(`(${coreSSNPattern})`);
|
|
341
|
+
function shouldCaptureValue(value, anchorRegexes = true) {
|
|
342
|
+
if ((0, core_namespaceObject.isNullish)(value)) return false;
|
|
343
|
+
if ((0, core_namespaceObject.isString)(value)) {
|
|
344
|
+
value = (0, core_namespaceObject.trim)(value);
|
|
345
|
+
const ccRegex = anchorRegexes ? anchoredCCRegex : unanchoredCCRegex;
|
|
346
|
+
if (ccRegex.test((value || '').replace(/[- ]/g, ''))) return false;
|
|
347
|
+
const ssnRegex = anchorRegexes ? anchoredSSNRegex : unanchoredSSNRegex;
|
|
348
|
+
if (ssnRegex.test(value)) return false;
|
|
349
|
+
}
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
function isAngularStyleAttr(attributeName) {
|
|
353
|
+
if ((0, core_namespaceObject.isString)(attributeName)) return '_ngcontent' === attributeName.substring(0, 10) || '_nghost' === attributeName.substring(0, 7);
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
function getDirectAndNestedSpanText(target) {
|
|
357
|
+
let text = getSafeText(target);
|
|
358
|
+
text = `${text} ${getNestedSpanText(target)}`.trim();
|
|
359
|
+
return shouldCaptureValue(text) ? text : '';
|
|
360
|
+
}
|
|
361
|
+
function getNestedSpanText(target) {
|
|
362
|
+
let text = '';
|
|
363
|
+
if (target && target.childNodes && target.childNodes.length) (0, external_general_utils_js_namespaceObject.each)(target.childNodes, function(child) {
|
|
364
|
+
if (child && child.tagName?.toLowerCase() === 'span') try {
|
|
365
|
+
const spanText = getSafeText(child);
|
|
366
|
+
text = `${text} ${spanText}`.trim();
|
|
367
|
+
if (child.childNodes && child.childNodes.length) text = `${text} ${getNestedSpanText(child)}`.trim();
|
|
368
|
+
} catch (e) {
|
|
369
|
+
external_logger_js_namespaceObject.logger.error('[AutoCapture]', e);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
return text;
|
|
373
|
+
}
|
|
374
|
+
function getElementsChainString(elements) {
|
|
375
|
+
return elementsToString(extractElements(elements));
|
|
376
|
+
}
|
|
377
|
+
function escapeQuotes(input) {
|
|
378
|
+
return input.replace(/"|\\"/g, '\\"');
|
|
379
|
+
}
|
|
380
|
+
function elementsToString(elements) {
|
|
381
|
+
const ret = elements.map((element)=>{
|
|
382
|
+
let el_string = '';
|
|
383
|
+
if (element.tag_name) el_string += element.tag_name;
|
|
384
|
+
if (element.attr_class) {
|
|
385
|
+
element.attr_class.sort();
|
|
386
|
+
for (const single_class of element.attr_class)el_string += `.${single_class.replace(/"/g, '')}`;
|
|
387
|
+
}
|
|
388
|
+
const attributes = {
|
|
389
|
+
...element.text ? {
|
|
390
|
+
text: element.text
|
|
391
|
+
} : {},
|
|
392
|
+
'nth-child': element.nth_child ?? 0,
|
|
393
|
+
'nth-of-type': element.nth_of_type ?? 0,
|
|
394
|
+
...element.href ? {
|
|
395
|
+
href: element.href
|
|
396
|
+
} : {},
|
|
397
|
+
...element.attr_id ? {
|
|
398
|
+
attr_id: element.attr_id
|
|
399
|
+
} : {},
|
|
400
|
+
...element.attributes
|
|
401
|
+
};
|
|
402
|
+
const sortedAttributes = {};
|
|
403
|
+
(0, external_general_utils_js_namespaceObject.entries)(attributes).sort(([a], [b])=>a.localeCompare(b)).forEach(([key, value])=>sortedAttributes[escapeQuotes(key.toString())] = escapeQuotes(value.toString()));
|
|
404
|
+
el_string += ':';
|
|
405
|
+
el_string += (0, external_general_utils_js_namespaceObject.entries)(sortedAttributes).map(([key, value])=>`${key}="${value}"`).join('');
|
|
406
|
+
return el_string;
|
|
407
|
+
});
|
|
408
|
+
return ret.join(';');
|
|
409
|
+
}
|
|
410
|
+
function extractElements(elements) {
|
|
411
|
+
return elements.map((el)=>{
|
|
412
|
+
const attributes = {};
|
|
413
|
+
const response = {
|
|
414
|
+
text: el['$el_text']?.slice(0, 400),
|
|
415
|
+
tag_name: el['tag_name'],
|
|
416
|
+
href: el['attr__href']?.slice(0, 2048),
|
|
417
|
+
attr_class: extractAttrClass(el),
|
|
418
|
+
attr_id: el['attr__id'],
|
|
419
|
+
nth_child: el['nth_child'],
|
|
420
|
+
nth_of_type: el['nth_of_type'],
|
|
421
|
+
attributes
|
|
422
|
+
};
|
|
423
|
+
(0, external_general_utils_js_namespaceObject.entries)(el).filter(([key])=>0 === key.indexOf('attr__')).forEach(([key, value])=>response.attributes[key] = value);
|
|
424
|
+
return response;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
function extractAttrClass(el) {
|
|
428
|
+
const attr_class = el['attr__class'];
|
|
429
|
+
if (!attr_class) return;
|
|
430
|
+
if ((0, core_namespaceObject.isArray)(attr_class)) return attr_class;
|
|
431
|
+
return splitClassString(attr_class);
|
|
432
|
+
}
|
|
433
|
+
exports.DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = __webpack_exports__.DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS;
|
|
434
|
+
exports.MAX_DOM_ANCESTOR_DEPTH = __webpack_exports__.MAX_DOM_ANCESTOR_DEPTH;
|
|
435
|
+
exports.autocaptureCompatibleElements = __webpack_exports__.autocaptureCompatibleElements;
|
|
436
|
+
exports.getClassNames = __webpack_exports__.getClassNames;
|
|
437
|
+
exports.getDirectAndNestedSpanText = __webpack_exports__.getDirectAndNestedSpanText;
|
|
438
|
+
exports.getElementsChainString = __webpack_exports__.getElementsChainString;
|
|
439
|
+
exports.getEventTarget = __webpack_exports__.getEventTarget;
|
|
440
|
+
exports.getNestedSpanText = __webpack_exports__.getNestedSpanText;
|
|
441
|
+
exports.getParentElement = __webpack_exports__.getParentElement;
|
|
442
|
+
exports.getSafeText = __webpack_exports__.getSafeText;
|
|
443
|
+
exports.isAngularStyleAttr = __webpack_exports__.isAngularStyleAttr;
|
|
444
|
+
exports.isSensitiveElement = __webpack_exports__.isSensitiveElement;
|
|
445
|
+
exports.isTextSelectionTarget = __webpack_exports__.isTextSelectionTarget;
|
|
446
|
+
exports.makeSafeText = __webpack_exports__.makeSafeText;
|
|
447
|
+
exports.shouldCaptureDeadClick = __webpack_exports__.shouldCaptureDeadClick;
|
|
448
|
+
exports.shouldCaptureDomEvent = __webpack_exports__.shouldCaptureDomEvent;
|
|
449
|
+
exports.shouldCaptureElement = __webpack_exports__.shouldCaptureElement;
|
|
450
|
+
exports.shouldCaptureRageclick = __webpack_exports__.shouldCaptureRageclick;
|
|
451
|
+
exports.shouldCaptureValue = __webpack_exports__.shouldCaptureValue;
|
|
452
|
+
exports.shouldSkipDeadClick = __webpack_exports__.shouldSkipDeadClick;
|
|
453
|
+
exports.splitClassString = __webpack_exports__.splitClassString;
|
|
454
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
455
|
+
"DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS",
|
|
456
|
+
"MAX_DOM_ANCESTOR_DEPTH",
|
|
457
|
+
"autocaptureCompatibleElements",
|
|
458
|
+
"getClassNames",
|
|
459
|
+
"getDirectAndNestedSpanText",
|
|
460
|
+
"getElementsChainString",
|
|
461
|
+
"getEventTarget",
|
|
462
|
+
"getNestedSpanText",
|
|
463
|
+
"getParentElement",
|
|
464
|
+
"getSafeText",
|
|
465
|
+
"isAngularStyleAttr",
|
|
466
|
+
"isSensitiveElement",
|
|
467
|
+
"isTextSelectionTarget",
|
|
468
|
+
"makeSafeText",
|
|
469
|
+
"shouldCaptureDeadClick",
|
|
470
|
+
"shouldCaptureDomEvent",
|
|
471
|
+
"shouldCaptureElement",
|
|
472
|
+
"shouldCaptureRageclick",
|
|
473
|
+
"shouldCaptureValue",
|
|
474
|
+
"shouldSkipDeadClick",
|
|
475
|
+
"splitClassString"
|
|
476
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
477
|
+
Object.defineProperty(exports, '__esModule', {
|
|
478
|
+
value: true
|
|
479
|
+
});
|