@posthog/browser-common 0.9.12 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autocapture.js +43 -0
- package/dist/autocapture.mjs +44 -1
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/package.json +3 -3
package/dist/autocapture.js
CHANGED
|
@@ -57,6 +57,39 @@ const element_utils_js_namespaceObject = require("./utils/element-utils.js");
|
|
|
57
57
|
const getWindow = ()=>"u" < typeof window ? void 0 : window;
|
|
58
58
|
const getDocument = ()=>"u" < typeof document ? void 0 : document;
|
|
59
59
|
const COPY_AUTOCAPTURE_EVENT = '$copy_autocapture';
|
|
60
|
+
const EXCLUDED_INPUT_TYPES = [
|
|
61
|
+
'password',
|
|
62
|
+
'hidden',
|
|
63
|
+
'file',
|
|
64
|
+
'checkbox',
|
|
65
|
+
'button',
|
|
66
|
+
'submit',
|
|
67
|
+
'reset',
|
|
68
|
+
'image'
|
|
69
|
+
];
|
|
70
|
+
function isValueInputElement(element) {
|
|
71
|
+
if ((0, element_utils_js_namespaceObject.isTag)(element, 'input')) return !(0, core_namespaceObject.includes)(EXCLUDED_INPUT_TYPES, element.type);
|
|
72
|
+
return (0, element_utils_js_namespaceObject.isTag)(element, 'textarea') || (0, element_utils_js_namespaceObject.isTag)(element, 'select') && !element.multiple;
|
|
73
|
+
}
|
|
74
|
+
function isInputValueEligible(target, config) {
|
|
75
|
+
if (!(0, autocapture_utils_js_namespaceObject.shouldCaptureElement)(target)) return false;
|
|
76
|
+
const ignorelist = config.css_selector_ignorelist ?? autocapture_utils_js_namespaceObject.DEFAULT_AUTOCAPTURE_IGNORE_LIST;
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
let element = target;
|
|
79
|
+
if ((0, element_utils_js_namespaceObject.isTag)(target, 'select')) {
|
|
80
|
+
const select = target;
|
|
81
|
+
element = select.options[select.selectedIndex] || target;
|
|
82
|
+
}
|
|
83
|
+
while(element){
|
|
84
|
+
const current = element;
|
|
85
|
+
const classes = (0, autocapture_utils_js_namespaceObject.getClassNames)(current);
|
|
86
|
+
if (seen.size >= autocapture_utils_js_namespaceObject.MAX_DOM_ANCESTOR_DEPTH || seen.has(element) || (0, core_namespaceObject.includes)(classes, 'ph-sensitive') || (0, core_namespaceObject.includes)(classes, 'ph-no-capture') || ignorelist.some((selector)=>(0, autocapture_utils_js_namespaceObject.elementMatchesCSSSelector)(current, selector))) return false;
|
|
87
|
+
seen.add(element);
|
|
88
|
+
const parent = element.assignedSlot || element.parentNode;
|
|
89
|
+
element = (0, element_utils_js_namespaceObject.isShadowRoot)(parent) ? parent.host : parent && (0, element_utils_js_namespaceObject.isElementNode)(parent) ? parent : null;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
60
93
|
const logger = (0, logger_js_namespaceObject.createLogger)('[AutoCapture]');
|
|
61
94
|
function limitText(length, text) {
|
|
62
95
|
if (text.length > length) return text.slice(0, length) + '...';
|
|
@@ -504,6 +537,16 @@ class Autocapture {
|
|
|
504
537
|
}
|
|
505
538
|
props['$copy_type'] = clipType;
|
|
506
539
|
}
|
|
540
|
+
if ('$autocapture' === eventName && 'change' === e.type && config.capture_value_css_selector_allowlist && !config.maskAllText && isValueInputElement(target) && isInputValueEligible(target, config) && !target.querySelector('.ph-no-capture, .ph-sensitive')) {
|
|
541
|
+
const allowlist = config.capture_value_css_selector_allowlist;
|
|
542
|
+
let captureValue = false;
|
|
543
|
+
try {
|
|
544
|
+
captureValue = (0, core_namespaceObject.isFunction)(allowlist) ? !!allowlist(target) : (0, core_namespaceObject.isArray)(allowlist) && allowlist.some((selector)=>(0, autocapture_utils_js_namespaceObject.elementMatchesCSSSelector)(target, selector));
|
|
545
|
+
} catch (error) {
|
|
546
|
+
logger.error('capture_value_css_selector_allowlist threw', error);
|
|
547
|
+
}
|
|
548
|
+
if (captureValue) props['$input_value'] = target.value;
|
|
549
|
+
}
|
|
507
550
|
this._client?.capture(eventName, props);
|
|
508
551
|
return true;
|
|
509
552
|
}
|
package/dist/autocapture.mjs
CHANGED
|
@@ -2,13 +2,46 @@ import { addEventListener, each, extend } from "./utils/general-utils.mjs";
|
|
|
2
2
|
import { DEFAULT_AUTOCAPTURE_IGNORE_LIST, MAX_DOM_ANCESTOR_DEPTH, autocaptureCompatibleElements, elementMatchesCSSSelector, getClassNames, getDirectAndNestedSpanText, getElementsChainString, getEventTarget, getSafeText, isAngularStyleAttr, isSensitiveElement, makeSafeText, shouldCaptureDomEvent, shouldCaptureElement, shouldCaptureRageclick, shouldCaptureValue, splitClassString } from "./utils/autocapture-utils.mjs";
|
|
3
3
|
import rageclick from "./rageclick.mjs";
|
|
4
4
|
import { AUTOCAPTURE_DISABLED_SERVER_SIDE } from "./constants.mjs";
|
|
5
|
-
import { includes, isBoolean, isFunction, isNull, stripUrlHash } from "@posthog/core";
|
|
5
|
+
import { includes, isArray, isBoolean, isFunction, isNull, stripUrlHash } from "@posthog/core";
|
|
6
6
|
import { createLogger } from "./utils/logger.mjs";
|
|
7
7
|
import { convertToURL } from "./utils/convert-to-url.mjs";
|
|
8
8
|
import { isElementNode, isShadowRoot, isTag, isTextNode } from "./utils/element-utils.mjs";
|
|
9
9
|
const getWindow = ()=>"u" < typeof window ? void 0 : window;
|
|
10
10
|
const getDocument = ()=>"u" < typeof document ? void 0 : document;
|
|
11
11
|
const COPY_AUTOCAPTURE_EVENT = '$copy_autocapture';
|
|
12
|
+
const EXCLUDED_INPUT_TYPES = [
|
|
13
|
+
'password',
|
|
14
|
+
'hidden',
|
|
15
|
+
'file',
|
|
16
|
+
'checkbox',
|
|
17
|
+
'button',
|
|
18
|
+
'submit',
|
|
19
|
+
'reset',
|
|
20
|
+
'image'
|
|
21
|
+
];
|
|
22
|
+
function isValueInputElement(element) {
|
|
23
|
+
if (isTag(element, 'input')) return !includes(EXCLUDED_INPUT_TYPES, element.type);
|
|
24
|
+
return isTag(element, 'textarea') || isTag(element, 'select') && !element.multiple;
|
|
25
|
+
}
|
|
26
|
+
function isInputValueEligible(target, config) {
|
|
27
|
+
if (!shouldCaptureElement(target)) return false;
|
|
28
|
+
const ignorelist = config.css_selector_ignorelist ?? DEFAULT_AUTOCAPTURE_IGNORE_LIST;
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
let element = target;
|
|
31
|
+
if (isTag(target, 'select')) {
|
|
32
|
+
const select = target;
|
|
33
|
+
element = select.options[select.selectedIndex] || target;
|
|
34
|
+
}
|
|
35
|
+
while(element){
|
|
36
|
+
const current = element;
|
|
37
|
+
const classes = getClassNames(current);
|
|
38
|
+
if (seen.size >= MAX_DOM_ANCESTOR_DEPTH || seen.has(element) || includes(classes, 'ph-sensitive') || includes(classes, 'ph-no-capture') || ignorelist.some((selector)=>elementMatchesCSSSelector(current, selector))) return false;
|
|
39
|
+
seen.add(element);
|
|
40
|
+
const parent = element.assignedSlot || element.parentNode;
|
|
41
|
+
element = isShadowRoot(parent) ? parent.host : parent && isElementNode(parent) ? parent : null;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
12
45
|
const logger = createLogger('[AutoCapture]');
|
|
13
46
|
function limitText(length, text) {
|
|
14
47
|
if (text.length > length) return text.slice(0, length) + '...';
|
|
@@ -456,6 +489,16 @@ class Autocapture {
|
|
|
456
489
|
}
|
|
457
490
|
props['$copy_type'] = clipType;
|
|
458
491
|
}
|
|
492
|
+
if ('$autocapture' === eventName && 'change' === e.type && config.capture_value_css_selector_allowlist && !config.maskAllText && isValueInputElement(target) && isInputValueEligible(target, config) && !target.querySelector('.ph-no-capture, .ph-sensitive')) {
|
|
493
|
+
const allowlist = config.capture_value_css_selector_allowlist;
|
|
494
|
+
let captureValue = false;
|
|
495
|
+
try {
|
|
496
|
+
captureValue = isFunction(allowlist) ? !!allowlist(target) : isArray(allowlist) && allowlist.some((selector)=>elementMatchesCSSSelector(target, selector));
|
|
497
|
+
} catch (error) {
|
|
498
|
+
logger.error('capture_value_css_selector_allowlist threw', error);
|
|
499
|
+
}
|
|
500
|
+
if (captureValue) props['$input_value'] = target.value;
|
|
501
|
+
}
|
|
459
502
|
this._client?.capture(eventName, props);
|
|
460
503
|
return true;
|
|
461
504
|
}
|
package/dist/config.js
CHANGED
package/dist/config.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/browser-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -240,8 +240,8 @@
|
|
|
240
240
|
},
|
|
241
241
|
"dependencies": {
|
|
242
242
|
"preact": "^10.29.3",
|
|
243
|
-
"@posthog/core": "^1.
|
|
244
|
-
"@posthog/types": "^1.
|
|
243
|
+
"@posthog/core": "^1.61.1",
|
|
244
|
+
"@posthog/types": "^1.418.0"
|
|
245
245
|
},
|
|
246
246
|
"devDependencies": {
|
|
247
247
|
"@rsbuild/plugin-react": "^2.1.0",
|