@posthog/browser-common 0.8.0 → 0.8.2

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/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.8.0";
30
+ const packageVersion = "0.8.2";
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.8.0";
1
+ const packageVersion = "0.8.2";
2
2
  const Config = {
3
3
  DEBUG: false,
4
4
  LIB_VERSION: packageVersion,
@@ -7,7 +7,9 @@ export declare function makeSafeText(s: string | null | undefined): string | nul
7
7
  export declare function getSafeText(el: Element): string;
8
8
  export declare function getEventTarget(e: Event): Element | null;
9
9
  export declare const autocaptureCompatibleElements: string[];
10
+ export declare function elementMatchesCSSSelector(el: Element, selector: string): boolean;
10
11
  export declare function getParentElement(curEl: Element): Element | false;
12
+ export declare const DEFAULT_AUTOCAPTURE_IGNORE_LIST: string[];
11
13
  export declare const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS: string[];
12
14
  export declare function shouldCaptureDeadClick(el: Element | null, _config: PostHogConfig['capture_dead_clicks']): boolean;
13
15
  export declare function isTextSelectionTarget(el: Element | null): boolean;
@@ -28,9 +28,11 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
+ DEFAULT_AUTOCAPTURE_IGNORE_LIST: ()=>DEFAULT_AUTOCAPTURE_IGNORE_LIST,
31
32
  DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS: ()=>DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS,
32
33
  MAX_DOM_ANCESTOR_DEPTH: ()=>MAX_DOM_ANCESTOR_DEPTH,
33
34
  autocaptureCompatibleElements: ()=>autocaptureCompatibleElements,
35
+ elementMatchesCSSSelector: ()=>elementMatchesCSSSelector,
34
36
  getClassNames: ()=>getClassNames,
35
37
  getDirectAndNestedSpanText: ()=>getDirectAndNestedSpanText,
36
38
  getElementsChainString: ()=>getElementsChainString,
@@ -488,9 +490,11 @@ function extractAttrClass(el) {
488
490
  if ((0, core_namespaceObject.isArray)(attr_class)) return attr_class;
489
491
  return splitClassString(attr_class);
490
492
  }
493
+ exports.DEFAULT_AUTOCAPTURE_IGNORE_LIST = __webpack_exports__.DEFAULT_AUTOCAPTURE_IGNORE_LIST;
491
494
  exports.DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = __webpack_exports__.DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS;
492
495
  exports.MAX_DOM_ANCESTOR_DEPTH = __webpack_exports__.MAX_DOM_ANCESTOR_DEPTH;
493
496
  exports.autocaptureCompatibleElements = __webpack_exports__.autocaptureCompatibleElements;
497
+ exports.elementMatchesCSSSelector = __webpack_exports__.elementMatchesCSSSelector;
494
498
  exports.getClassNames = __webpack_exports__.getClassNames;
495
499
  exports.getDirectAndNestedSpanText = __webpack_exports__.getDirectAndNestedSpanText;
496
500
  exports.getElementsChainString = __webpack_exports__.getElementsChainString;
@@ -510,9 +514,11 @@ exports.shouldCaptureValue = __webpack_exports__.shouldCaptureValue;
510
514
  exports.shouldSkipDeadClick = __webpack_exports__.shouldSkipDeadClick;
511
515
  exports.splitClassString = __webpack_exports__.splitClassString;
512
516
  for(var __rspack_i in __webpack_exports__)if (-1 === [
517
+ "DEFAULT_AUTOCAPTURE_IGNORE_LIST",
513
518
  "DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS",
514
519
  "MAX_DOM_ANCESTOR_DEPTH",
515
520
  "autocaptureCompatibleElements",
521
+ "elementMatchesCSSSelector",
516
522
  "getClassNames",
517
523
  "getDirectAndNestedSpanText",
518
524
  "getElementsChainString",
@@ -436,4 +436,4 @@ function extractAttrClass(el) {
436
436
  if (isArray(attr_class)) return attr_class;
437
437
  return splitClassString(attr_class);
438
438
  }
439
- export { DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS, MAX_DOM_ANCESTOR_DEPTH, autocaptureCompatibleElements, getClassNames, getDirectAndNestedSpanText, getElementsChainString, getEventTarget, getNestedSpanText, getParentElement, getSafeText, isAngularStyleAttr, isSensitiveElement, isTextSelectionTarget, makeSafeText, shouldCaptureDeadClick, shouldCaptureDomEvent, shouldCaptureElement, shouldCaptureRageclick, shouldCaptureValue, shouldSkipDeadClick, splitClassString };
439
+ export { DEFAULT_AUTOCAPTURE_IGNORE_LIST, DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS, MAX_DOM_ANCESTOR_DEPTH, autocaptureCompatibleElements, elementMatchesCSSSelector, getClassNames, getDirectAndNestedSpanText, getElementsChainString, getEventTarget, getNestedSpanText, getParentElement, getSafeText, isAngularStyleAttr, isSensitiveElement, isTextSelectionTarget, makeSafeText, shouldCaptureDeadClick, shouldCaptureDomEvent, shouldCaptureElement, shouldCaptureRageclick, shouldCaptureValue, shouldSkipDeadClick, splitClassString };
@@ -12,6 +12,10 @@ export declare const trySafe: <T>(fn: () => T) => T | undefined;
12
12
  export declare const safewrap: <F extends (...args: any[]) => any = (...args: any[]) => any>(f: F) => F;
13
13
  export declare const safewrapClass: (klass: Function, functions: string[]) => void;
14
14
  export declare const stripEmptyProperties: (p: Properties) => Properties;
15
+ export declare function errorToProperties(error: Error & {
16
+ cause?: unknown;
17
+ errors?: unknown;
18
+ }): Record<string, unknown>;
15
19
  export declare function _copyAndTruncateStrings<T extends Record<string, any> = Record<string, any>>(object: T, maxStringLength: number): T;
16
20
  export declare function isCrossDomainCookie(documentLocation: Location | undefined): boolean;
17
21
  export declare function addEventListener(element: Window | Document | Element | undefined, event: string, callback: EventListener, options?: AddEventListenerOptions): void;
@@ -33,6 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
33
33
  each: ()=>each,
34
34
  eachArray: ()=>eachArray,
35
35
  entries: ()=>entries,
36
+ errorToProperties: ()=>errorToProperties,
36
37
  extend: ()=>extend,
37
38
  find: ()=>find,
38
39
  isCrossDomainCookie: ()=>isCrossDomainCookie,
@@ -98,6 +99,21 @@ const stripEmptyProperties = function(p) {
98
99
  });
99
100
  return ret;
100
101
  };
102
+ function errorToProperties(error) {
103
+ const copy = {
104
+ ...error
105
+ };
106
+ for (const detail of [
107
+ 'name',
108
+ 'message',
109
+ 'stack',
110
+ 'cause',
111
+ 'errors'
112
+ ])try {
113
+ if (detail in error) copy[detail] = error[detail];
114
+ } catch {}
115
+ return copy;
116
+ }
101
117
  function deepCircularCopy(value, customizer) {
102
118
  const COPY_IN_PROGRESS_SET = new Set();
103
119
  function internalDeepCircularCopy(value, key) {
@@ -112,7 +128,7 @@ function deepCircularCopy(value, customizer) {
112
128
  });
113
129
  } else {
114
130
  const copy = {};
115
- each(value, (val, key)=>{
131
+ each((0, core_namespaceObject.isError)(value) ? errorToProperties(value) : value, (val, key)=>{
116
132
  if (!COPY_IN_PROGRESS_SET.has(val)) copy[key] = internalDeepCircularCopy(val, key);
117
133
  });
118
134
  result = copy;
@@ -165,6 +181,7 @@ exports.addEventListener = __webpack_exports__.addEventListener;
165
181
  exports.each = __webpack_exports__.each;
166
182
  exports.eachArray = __webpack_exports__.eachArray;
167
183
  exports.entries = __webpack_exports__.entries;
184
+ exports.errorToProperties = __webpack_exports__.errorToProperties;
168
185
  exports.extend = __webpack_exports__.extend;
169
186
  exports.find = __webpack_exports__.find;
170
187
  exports.isCrossDomainCookie = __webpack_exports__.isCrossDomainCookie;
@@ -180,6 +197,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
180
197
  "each",
181
198
  "eachArray",
182
199
  "entries",
200
+ "errorToProperties",
183
201
  "extend",
184
202
  "find",
185
203
  "isCrossDomainCookie",
@@ -1,4 +1,4 @@
1
- import { hasOwnProperty as core_hasOwnProperty, isArray, isFormData, isNullish, isNumber, isString } from "@posthog/core";
1
+ import { hasOwnProperty as core_hasOwnProperty, isArray, isError, isFormData, isNullish, isNumber, isString } from "@posthog/core";
2
2
  import { logger } from "./logger.mjs";
3
3
  function find(value, predicate) {
4
4
  for(let i = 0; i < value.length; i++)if (predicate(value[i])) return value[i];
@@ -53,6 +53,21 @@ const stripEmptyProperties = function(p) {
53
53
  });
54
54
  return ret;
55
55
  };
56
+ function errorToProperties(error) {
57
+ const copy = {
58
+ ...error
59
+ };
60
+ for (const detail of [
61
+ 'name',
62
+ 'message',
63
+ 'stack',
64
+ 'cause',
65
+ 'errors'
66
+ ])try {
67
+ if (detail in error) copy[detail] = error[detail];
68
+ } catch {}
69
+ return copy;
70
+ }
56
71
  function deepCircularCopy(value, customizer) {
57
72
  const COPY_IN_PROGRESS_SET = new Set();
58
73
  function internalDeepCircularCopy(value, key) {
@@ -67,7 +82,7 @@ function deepCircularCopy(value, customizer) {
67
82
  });
68
83
  } else {
69
84
  const copy = {};
70
- each(value, (val, key)=>{
85
+ each(isError(value) ? errorToProperties(value) : value, (val, key)=>{
71
86
  if (!COPY_IN_PROGRESS_SET.has(val)) copy[key] = internalDeepCircularCopy(val, key);
72
87
  });
73
88
  result = copy;
@@ -115,4 +130,4 @@ const TOOLBAR_INTERNAL_INSTANCE_NAME = 'ph_toolbar_internal';
115
130
  function isToolbarInstance(config) {
116
131
  return config.name === TOOLBAR_INTERNAL_INSTANCE_NAME;
117
132
  }
118
- export { _copyAndTruncateStrings, addEventListener, each, eachArray, entries, extend, find, isCrossDomainCookie, isToolbarInstance, migrateConfigField, safewrap, safewrapClass, stripEmptyProperties, trySafe };
133
+ export { _copyAndTruncateStrings, addEventListener, each, eachArray, entries, errorToProperties, extend, find, isCrossDomainCookie, isToolbarInstance, migrateConfigField, safewrap, safewrapClass, stripEmptyProperties, trySafe };
@@ -48,7 +48,15 @@ const localDomains = [
48
48
  ];
49
49
  const jsonStringify = (data, space)=>{
50
50
  try {
51
- return JSON.stringify(data, (_, value)=>'bigint' == typeof value ? value.toString() : value, space);
51
+ let errors;
52
+ return JSON.stringify(data, (_, value)=>{
53
+ if ((0, core_namespaceObject.isError)(value)) {
54
+ errors ??= new WeakMap();
55
+ if (!errors.has(value)) errors.set(value, (0, external_general_utils_js_namespaceObject.errorToProperties)(value));
56
+ return errors.get(value);
57
+ }
58
+ return 'bigint' == typeof value ? value.toString() : value;
59
+ }, space);
52
60
  } catch {
53
61
  return (0, core_namespaceObject.safeJsonStringify)(data);
54
62
  }
@@ -1,5 +1,5 @@
1
- import { isArray, isFile, isUndefined, safeJsonStringify } from "@posthog/core";
2
- import { each } from "./general-utils.mjs";
1
+ import { isArray, isError, isFile, isUndefined, safeJsonStringify } from "@posthog/core";
2
+ import { each, errorToProperties } from "./general-utils.mjs";
3
3
  import { document as external_globals_mjs_document, isBrowserOnline, location as external_globals_mjs_location } from "./globals.mjs";
4
4
  import { logger } from "./logger.mjs";
5
5
  const localDomains = [
@@ -8,7 +8,15 @@ const localDomains = [
8
8
  ];
9
9
  const jsonStringify = (data, space)=>{
10
10
  try {
11
- return JSON.stringify(data, (_, value)=>'bigint' == typeof value ? value.toString() : value, space);
11
+ let errors;
12
+ return JSON.stringify(data, (_, value)=>{
13
+ if (isError(value)) {
14
+ errors ??= new WeakMap();
15
+ if (!errors.has(value)) errors.set(value, errorToProperties(value));
16
+ return errors.get(value);
17
+ }
18
+ return 'bigint' == typeof value ? value.toString() : value;
19
+ }, space);
12
20
  } catch {
13
21
  return safeJsonStringify(data);
14
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/browser-common",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
5
5
  "license": "MIT",
6
6
  "repository": {