@posthog/browser-common 0.9.12 → 0.10.1

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.
@@ -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
  }
@@ -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
@@ -27,7 +27,7 @@ var __webpack_require__ = {};
27
27
  })();
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
- const packageVersion = "0.9.12";
30
+ const packageVersion = "0.10.1";
31
31
  const Config = {
32
32
  DEBUG: false,
33
33
  LIB_VERSION: packageVersion,
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const packageVersion = "0.9.12";
1
+ const packageVersion = "0.10.1";
2
2
  const Config = {
3
3
  DEBUG: false,
4
4
  LIB_VERSION: packageVersion,
@@ -140,7 +140,16 @@ const weakRandomValues = (buffer)=>{
140
140
  return buffer;
141
141
  };
142
142
  let getRandomValues;
143
- const selectRandomValues = ()=>"u" > typeof window && !(0, core_namespaceObject.isUndefined)(window.crypto) && crypto.getRandomValues ? (buffer)=>crypto.getRandomValues(buffer) : weakRandomValues;
143
+ const selectRandomValues = ()=>{
144
+ if ("u" > typeof window && !(0, core_namespaceObject.isUndefined)(window.crypto) && crypto.getRandomValues) return (buffer)=>{
145
+ try {
146
+ return crypto.getRandomValues(buffer);
147
+ } catch {
148
+ return weakRandomValues(buffer);
149
+ }
150
+ };
151
+ return weakRandomValues;
152
+ };
144
153
  class DefaultRandom {
145
154
  nextUint32() {
146
155
  if (this._cursor >= this._buffer.length) {
@@ -106,7 +106,16 @@ const weakRandomValues = (buffer)=>{
106
106
  return buffer;
107
107
  };
108
108
  let getRandomValues;
109
- const selectRandomValues = ()=>"u" > typeof window && !isUndefined(window.crypto) && crypto.getRandomValues ? (buffer)=>crypto.getRandomValues(buffer) : weakRandomValues;
109
+ const selectRandomValues = ()=>{
110
+ if ("u" > typeof window && !isUndefined(window.crypto) && crypto.getRandomValues) return (buffer)=>{
111
+ try {
112
+ return crypto.getRandomValues(buffer);
113
+ } catch {
114
+ return weakRandomValues(buffer);
115
+ }
116
+ };
117
+ return weakRandomValues;
118
+ };
110
119
  class DefaultRandom {
111
120
  nextUint32() {
112
121
  if (this._cursor >= this._buffer.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/browser-common",
3
- "version": "0.9.12",
3
+ "version": "0.10.1",
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.60.1",
244
- "@posthog/types": "^1.416.1"
243
+ "@posthog/types": "^1.418.0",
244
+ "@posthog/core": "^1.61.1"
245
245
  },
246
246
  "devDependencies": {
247
247
  "@rsbuild/plugin-react": "^2.1.0",