@posthog/browser-common 0.9.1 → 0.9.3
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 +1 -1
- package/dist/config.mjs +1 -1
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +64 -0
- package/dist/constants.mjs +17 -1
- package/dist/feature-flags-config.d.ts +23 -0
- package/dist/feature-flags-config.js +18 -0
- package/dist/feature-flags-config.mjs +1 -0
- package/dist/feature-flags.d.ts +329 -0
- package/dist/feature-flags.js +1222 -0
- package/dist/feature-flags.mjs +1172 -0
- package/dist/types/feature-flags.d.ts +18 -0
- package/dist/types/feature-flags.js +18 -0
- package/dist/types/feature-flags.mjs +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.mjs +1 -0
- package/dist/utils/autocapture-utils.js +67 -11
- package/dist/utils/autocapture-utils.mjs +67 -11
- package/dist/utils/event-utils.d.ts +1 -1
- package/dist/utils/event-utils.js +3 -9
- package/dist/utils/event-utils.mjs +1 -7
- package/dist/utils/logger.js +8 -3
- package/dist/utils/logger.mjs +8 -3
- package/dist/utils/request-reachability.d.ts +2 -0
- package/dist/utils/request-reachability.js +61 -0
- package/dist/utils/request-reachability.mjs +20 -0
- package/dist/utils/request-utils.d.ts +1 -2
- package/dist/utils/request-utils.js +3 -14
- package/dist/utils/request-utils.mjs +3 -14
- package/dist/utils/timezone.d.ts +1 -0
- package/dist/utils/timezone.js +46 -0
- package/dist/utils/timezone.mjs +8 -0
- package/package.json +19 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FeatureFlagDetail, JsonType } from '@posthog/types';
|
|
2
|
+
import type { RemoteConfig } from './remote-config';
|
|
3
|
+
/**
|
|
4
|
+
* Flags returns feature flags and their payloads
|
|
5
|
+
*/
|
|
6
|
+
export interface FlagsResponse extends RemoteConfig {
|
|
7
|
+
featureFlags: Record<string, string | boolean>;
|
|
8
|
+
featureFlagPayloads: Record<string, JsonType>;
|
|
9
|
+
errorsWhileComputingFlags: boolean;
|
|
10
|
+
requestId?: string;
|
|
11
|
+
flags: Record<string, FeatureFlagDetail>;
|
|
12
|
+
evaluatedAt?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Server-controlled gate for minimal `$feature_flag_called` events. `true` only when the
|
|
15
|
+
* project opted in; omitted otherwise. Absence always means full events.
|
|
16
|
+
*/
|
|
17
|
+
minimalFlagCalledEvents?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -3,6 +3,9 @@ var __webpack_modules__ = {
|
|
|
3
3
|
"./compression" (module) {
|
|
4
4
|
module.exports = require("./compression.js");
|
|
5
5
|
},
|
|
6
|
+
"./feature-flags" (module) {
|
|
7
|
+
module.exports = require("./feature-flags.js");
|
|
8
|
+
},
|
|
6
9
|
"./network-recording" (module) {
|
|
7
10
|
module.exports = require("./network-recording.js");
|
|
8
11
|
},
|
|
@@ -76,6 +79,10 @@ var __webpack_exports__ = {};
|
|
|
76
79
|
var __rspack_reexport = {};
|
|
77
80
|
for(const __rspack_import_key in _surveys__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_surveys__rspack_import_3[__rspack_import_key];
|
|
78
81
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
82
|
+
var _feature_flags__rspack_import_4 = __webpack_require__("./feature-flags");
|
|
83
|
+
var __rspack_reexport = {};
|
|
84
|
+
for(const __rspack_import_key in _feature_flags__rspack_import_4)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_feature_flags__rspack_import_4[__rspack_import_key];
|
|
85
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
79
86
|
})();
|
|
80
87
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
81
88
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/types/index.mjs
CHANGED
|
@@ -138,7 +138,17 @@ const DEFAULT_CONTENT_IGNORELIST = [
|
|
|
138
138
|
'previous',
|
|
139
139
|
'prev',
|
|
140
140
|
'>',
|
|
141
|
-
'<'
|
|
141
|
+
'<',
|
|
142
|
+
'→',
|
|
143
|
+
'←',
|
|
144
|
+
'›',
|
|
145
|
+
'‹',
|
|
146
|
+
'»',
|
|
147
|
+
'«',
|
|
148
|
+
'▶',
|
|
149
|
+
'◀',
|
|
150
|
+
'❯',
|
|
151
|
+
'❮'
|
|
142
152
|
];
|
|
143
153
|
const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = [
|
|
144
154
|
...DEFAULT_CONTENT_IGNORELIST,
|
|
@@ -147,10 +157,27 @@ const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = [
|
|
|
147
157
|
'−',
|
|
148
158
|
'–'
|
|
149
159
|
];
|
|
150
|
-
const MAX_CONTENT_IGNORELIST_ENTRIES = 10;
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
160
|
+
const MAX_CONTENT_IGNORELIST_ENTRIES = DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS.length + 10;
|
|
161
|
+
const INTERACTIVE_TAGS = [
|
|
162
|
+
'button',
|
|
163
|
+
'a',
|
|
164
|
+
'input',
|
|
165
|
+
'select',
|
|
166
|
+
'textarea',
|
|
167
|
+
'label'
|
|
168
|
+
];
|
|
169
|
+
const INTERACTIVE_ROLES = [
|
|
170
|
+
'button',
|
|
171
|
+
'link',
|
|
172
|
+
'tab',
|
|
173
|
+
'menuitem',
|
|
174
|
+
'option'
|
|
175
|
+
];
|
|
176
|
+
const matchesContentKeyword = (text, keyword)=>{
|
|
177
|
+
if (!/[a-z0-9]/i.test(keyword)) return text === keyword;
|
|
178
|
+
return (0, core_namespaceObject.includes)(DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS, keyword) ? new RegExp(`\\b${keyword}\\b`).test(text) : text.includes(keyword);
|
|
179
|
+
};
|
|
180
|
+
function shouldIgnoreByContent(contentIgnorelist, { safeText, ariaLabel }) {
|
|
154
181
|
let keywords;
|
|
155
182
|
if (true === contentIgnorelist) keywords = DEFAULT_CONTENT_IGNORELIST;
|
|
156
183
|
else {
|
|
@@ -161,7 +188,40 @@ function shouldIgnoreByContent(contentIgnorelist, elementsWithText) {
|
|
|
161
188
|
}
|
|
162
189
|
keywords = contentIgnorelist.map((k)=>k.toLowerCase());
|
|
163
190
|
}
|
|
164
|
-
return
|
|
191
|
+
return keywords.some((keyword)=>matchesContentKeyword(safeText, keyword) || matchesContentKeyword(ariaLabel, keyword));
|
|
192
|
+
}
|
|
193
|
+
const isInteractiveElement = (el)=>(0, core_namespaceObject.includes)(INTERACTIVE_TAGS, el.tagName.toLowerCase()) || (0, core_namespaceObject.includes)(INTERACTIVE_ROLES, (el.getAttribute('role') || '').toLowerCase());
|
|
194
|
+
function clickedControlText(el, targetElementList) {
|
|
195
|
+
for (const candidate of targetElementList)if (isInteractiveElement(candidate)) return controlLabelText(candidate);
|
|
196
|
+
for (const candidate of targetElementList){
|
|
197
|
+
try {
|
|
198
|
+
if (external_globals_js_namespaceObject.window?.getComputedStyle(candidate).getPropertyValue('cursor') !== 'pointer') break;
|
|
199
|
+
} catch {
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
const label = controlLabelText(candidate);
|
|
203
|
+
if (label.safeText || label.ariaLabel) return label;
|
|
204
|
+
}
|
|
205
|
+
return controlLabelText(el);
|
|
206
|
+
}
|
|
207
|
+
function controlLabelText(control) {
|
|
208
|
+
let text = '';
|
|
209
|
+
let firstAriaLabel = '';
|
|
210
|
+
const collect = (node)=>{
|
|
211
|
+
if ((0, external_element_utils_js_namespaceObject.isElementNode)(node) && shouldCaptureElement(node) && !isSensitiveElement(node)) {
|
|
212
|
+
text += ` ${getSafeText(node)}`;
|
|
213
|
+
firstAriaLabel = firstAriaLabel || node.getAttribute('aria-label') || '';
|
|
214
|
+
(0, external_general_utils_js_namespaceObject.each)(node.childNodes, collect);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
collect(control);
|
|
218
|
+
text = (0, core_namespaceObject.trim)(text.replace(/\s+/g, ' '));
|
|
219
|
+
const safeText = (shouldCaptureValue(text) ? text : '').toLowerCase();
|
|
220
|
+
const ariaLabel = control.getAttribute('aria-label') || (safeText ? '' : firstAriaLabel);
|
|
221
|
+
return {
|
|
222
|
+
safeText,
|
|
223
|
+
ariaLabel: (0, core_namespaceObject.trim)(ariaLabel).toLowerCase()
|
|
224
|
+
};
|
|
165
225
|
}
|
|
166
226
|
const DEFAULT_DEAD_CLICK_IGNORE_LIST = [
|
|
167
227
|
'.ph-no-deadclick',
|
|
@@ -215,11 +275,7 @@ function shouldCaptureRageclick(el, _config) {
|
|
|
215
275
|
if (false === selectorIgnoreList) return false;
|
|
216
276
|
if (ignoreTextSelection && isTextSelectionTarget(el)) return false;
|
|
217
277
|
const { targetElementList } = getElementAndParentsForElement(el, false);
|
|
218
|
-
|
|
219
|
-
safeText: getSafeText(element).toLowerCase(),
|
|
220
|
-
ariaLabel: element.getAttribute('aria-label')?.toLowerCase().trim() || ''
|
|
221
|
-
}));
|
|
222
|
-
if (shouldIgnoreByContent(contentIgnorelist, elementsWithText)) return false;
|
|
278
|
+
if (contentIgnorelist && shouldIgnoreByContent(contentIgnorelist, clickedControlText(el, targetElementList))) return false;
|
|
223
279
|
return !checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList);
|
|
224
280
|
}
|
|
225
281
|
const cannotCheckForAutocapture = (el)=>!el || (0, external_element_utils_js_namespaceObject.isTag)(el, 'html') || !(0, external_element_utils_js_namespaceObject.isElementNode)(el);
|
|
@@ -84,7 +84,17 @@ const DEFAULT_CONTENT_IGNORELIST = [
|
|
|
84
84
|
'previous',
|
|
85
85
|
'prev',
|
|
86
86
|
'>',
|
|
87
|
-
'<'
|
|
87
|
+
'<',
|
|
88
|
+
'→',
|
|
89
|
+
'←',
|
|
90
|
+
'›',
|
|
91
|
+
'‹',
|
|
92
|
+
'»',
|
|
93
|
+
'«',
|
|
94
|
+
'▶',
|
|
95
|
+
'◀',
|
|
96
|
+
'❯',
|
|
97
|
+
'❮'
|
|
88
98
|
];
|
|
89
99
|
const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = [
|
|
90
100
|
...DEFAULT_CONTENT_IGNORELIST,
|
|
@@ -93,10 +103,27 @@ const DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS = [
|
|
|
93
103
|
'−',
|
|
94
104
|
'–'
|
|
95
105
|
];
|
|
96
|
-
const MAX_CONTENT_IGNORELIST_ENTRIES = 10;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
106
|
+
const MAX_CONTENT_IGNORELIST_ENTRIES = DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS.length + 10;
|
|
107
|
+
const INTERACTIVE_TAGS = [
|
|
108
|
+
'button',
|
|
109
|
+
'a',
|
|
110
|
+
'input',
|
|
111
|
+
'select',
|
|
112
|
+
'textarea',
|
|
113
|
+
'label'
|
|
114
|
+
];
|
|
115
|
+
const INTERACTIVE_ROLES = [
|
|
116
|
+
'button',
|
|
117
|
+
'link',
|
|
118
|
+
'tab',
|
|
119
|
+
'menuitem',
|
|
120
|
+
'option'
|
|
121
|
+
];
|
|
122
|
+
const matchesContentKeyword = (text, keyword)=>{
|
|
123
|
+
if (!/[a-z0-9]/i.test(keyword)) return text === keyword;
|
|
124
|
+
return includes(DEFAULT_CONTENT_IGNORELIST_WITH_STEPPERS, keyword) ? new RegExp(`\\b${keyword}\\b`).test(text) : text.includes(keyword);
|
|
125
|
+
};
|
|
126
|
+
function shouldIgnoreByContent(contentIgnorelist, { safeText, ariaLabel }) {
|
|
100
127
|
let keywords;
|
|
101
128
|
if (true === contentIgnorelist) keywords = DEFAULT_CONTENT_IGNORELIST;
|
|
102
129
|
else {
|
|
@@ -107,7 +134,40 @@ function shouldIgnoreByContent(contentIgnorelist, elementsWithText) {
|
|
|
107
134
|
}
|
|
108
135
|
keywords = contentIgnorelist.map((k)=>k.toLowerCase());
|
|
109
136
|
}
|
|
110
|
-
return
|
|
137
|
+
return keywords.some((keyword)=>matchesContentKeyword(safeText, keyword) || matchesContentKeyword(ariaLabel, keyword));
|
|
138
|
+
}
|
|
139
|
+
const isInteractiveElement = (el)=>includes(INTERACTIVE_TAGS, el.tagName.toLowerCase()) || includes(INTERACTIVE_ROLES, (el.getAttribute('role') || '').toLowerCase());
|
|
140
|
+
function clickedControlText(el, targetElementList) {
|
|
141
|
+
for (const candidate of targetElementList)if (isInteractiveElement(candidate)) return controlLabelText(candidate);
|
|
142
|
+
for (const candidate of targetElementList){
|
|
143
|
+
try {
|
|
144
|
+
if (external_globals_mjs_window?.getComputedStyle(candidate).getPropertyValue('cursor') !== 'pointer') break;
|
|
145
|
+
} catch {
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
const label = controlLabelText(candidate);
|
|
149
|
+
if (label.safeText || label.ariaLabel) return label;
|
|
150
|
+
}
|
|
151
|
+
return controlLabelText(el);
|
|
152
|
+
}
|
|
153
|
+
function controlLabelText(control) {
|
|
154
|
+
let text = '';
|
|
155
|
+
let firstAriaLabel = '';
|
|
156
|
+
const collect = (node)=>{
|
|
157
|
+
if (isElementNode(node) && shouldCaptureElement(node) && !isSensitiveElement(node)) {
|
|
158
|
+
text += ` ${getSafeText(node)}`;
|
|
159
|
+
firstAriaLabel = firstAriaLabel || node.getAttribute('aria-label') || '';
|
|
160
|
+
each(node.childNodes, collect);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
collect(control);
|
|
164
|
+
text = trim(text.replace(/\s+/g, ' '));
|
|
165
|
+
const safeText = (shouldCaptureValue(text) ? text : '').toLowerCase();
|
|
166
|
+
const ariaLabel = control.getAttribute('aria-label') || (safeText ? '' : firstAriaLabel);
|
|
167
|
+
return {
|
|
168
|
+
safeText,
|
|
169
|
+
ariaLabel: trim(ariaLabel).toLowerCase()
|
|
170
|
+
};
|
|
111
171
|
}
|
|
112
172
|
const DEFAULT_DEAD_CLICK_IGNORE_LIST = [
|
|
113
173
|
'.ph-no-deadclick',
|
|
@@ -161,11 +221,7 @@ function shouldCaptureRageclick(el, _config) {
|
|
|
161
221
|
if (false === selectorIgnoreList) return false;
|
|
162
222
|
if (ignoreTextSelection && isTextSelectionTarget(el)) return false;
|
|
163
223
|
const { targetElementList } = getElementAndParentsForElement(el, false);
|
|
164
|
-
|
|
165
|
-
safeText: getSafeText(element).toLowerCase(),
|
|
166
|
-
ariaLabel: element.getAttribute('aria-label')?.toLowerCase().trim() || ''
|
|
167
|
-
}));
|
|
168
|
-
if (shouldIgnoreByContent(contentIgnorelist, elementsWithText)) return false;
|
|
224
|
+
if (contentIgnorelist && shouldIgnoreByContent(contentIgnorelist, clickedControlText(el, targetElementList))) return false;
|
|
169
225
|
return !checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList);
|
|
170
226
|
}
|
|
171
227
|
const cannotCheckForAutocapture = (el)=>!el || isTag(el, 'html') || !isElementNode(el);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { getTimezone } from './timezone';
|
|
1
2
|
import type { Properties } from '@posthog/types';
|
|
2
3
|
import type { BrowserDetectionHints } from '@posthog/core';
|
|
3
4
|
export declare const PERSONAL_DATA_CAMPAIGN_PARAMS: string[];
|
|
@@ -18,7 +19,6 @@ export declare function getPersonInfo(maskPersonalDataProperties?: boolean, cust
|
|
|
18
19
|
};
|
|
19
20
|
export declare function getPersonPropsFromInfo(info: Record<string, any>, disableCaptureUrlHashes?: boolean): Record<string, any>;
|
|
20
21
|
export declare function getInitialPersonPropsFromInfo(info: Record<string, any>, disableCaptureUrlHashes?: boolean): Record<string, any>;
|
|
21
|
-
export declare function getTimezone(): string | undefined;
|
|
22
22
|
export declare function getTimezoneOffset(): number | undefined;
|
|
23
23
|
export declare function getBrowserDetectionHints(): BrowserDetectionHints;
|
|
24
24
|
export declare function getEventProperties(maskPersonalDataProperties?: boolean, customPersonalDataProperties?: string[], detectGoogleSearchApp?: boolean, disableCaptureUrlHashes?: boolean): Properties;
|
|
@@ -54,9 +54,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
54
54
|
getReferrerInfo: ()=>getReferrerInfo,
|
|
55
55
|
getReferringDomain: ()=>getReferringDomain,
|
|
56
56
|
getSearchInfo: ()=>getSearchInfo,
|
|
57
|
-
getTimezone: ()=>getTimezone,
|
|
57
|
+
getTimezone: ()=>external_timezone_js_namespaceObject.getTimezone,
|
|
58
58
|
getTimezoneOffset: ()=>getTimezoneOffset
|
|
59
59
|
});
|
|
60
|
+
const external_timezone_js_namespaceObject = require("./timezone.js");
|
|
60
61
|
const external_request_utils_js_namespaceObject = require("./request-utils.js");
|
|
61
62
|
const core_namespaceObject = require("@posthog/core");
|
|
62
63
|
const external_config_js_namespaceObject = require("../config.js");
|
|
@@ -235,13 +236,6 @@ function getInitialPersonPropsFromInfo(info, disableCaptureUrlHashes = false) {
|
|
|
235
236
|
});
|
|
236
237
|
return props;
|
|
237
238
|
}
|
|
238
|
-
function getTimezone() {
|
|
239
|
-
try {
|
|
240
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
241
|
-
} catch {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
239
|
function getTimezoneOffset() {
|
|
246
240
|
try {
|
|
247
241
|
return new Date().getTimezoneOffset();
|
|
@@ -285,7 +279,7 @@ function getEventProperties(maskPersonalDataProperties, customPersonalDataProper
|
|
|
285
279
|
$webview_app_version: webviewAppVersion,
|
|
286
280
|
$device: (0, core_namespaceObject.detectDevice)(external_globals_js_namespaceObject.userAgent),
|
|
287
281
|
$device_type: (0, core_namespaceObject.detectDeviceType)(external_globals_js_namespaceObject.userAgent, deviceOptions),
|
|
288
|
-
$timezone: getTimezone(),
|
|
282
|
+
$timezone: (0, external_timezone_js_namespaceObject.getTimezone)(),
|
|
289
283
|
$timezone_offset: getTimezoneOffset()
|
|
290
284
|
}), {
|
|
291
285
|
$current_url: (0, external_request_utils_js_namespaceObject.maskQueryParams)(disableCaptureUrlHashes ? (0, core_namespaceObject.stripUrlHash)(external_globals_js_namespaceObject.location?.href) : external_globals_js_namespaceObject.location?.href, paramsToMask, MASKED),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getTimezone } from "./timezone.mjs";
|
|
1
2
|
import { convertToURL, getQueryParam, maskQueryParams } from "./request-utils.mjs";
|
|
2
3
|
import { detectBrowser, detectBrowserVersion, detectDevice, detectDeviceType, detectOS, detectWebviewApp, isNull, isUndefined, stripLeadingDollar, stripUrlHash } from "@posthog/core";
|
|
3
4
|
import config from "../config.mjs";
|
|
@@ -175,13 +176,6 @@ function getInitialPersonPropsFromInfo(info, disableCaptureUrlHashes = false) {
|
|
|
175
176
|
});
|
|
176
177
|
return props;
|
|
177
178
|
}
|
|
178
|
-
function getTimezone() {
|
|
179
|
-
try {
|
|
180
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
181
|
-
} catch {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
179
|
function getTimezoneOffset() {
|
|
186
180
|
try {
|
|
187
181
|
return new Date().getTimezoneOffset();
|
package/dist/utils/logger.js
CHANGED
|
@@ -43,12 +43,17 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
43
43
|
const external_config_js_namespaceObject = require("../config.js");
|
|
44
44
|
var external_config_js_default = /*#__PURE__*/ __webpack_require__.n(external_config_js_namespaceObject);
|
|
45
45
|
const core_namespaceObject = require("@posthog/core");
|
|
46
|
-
const external_globals_js_namespaceObject = require("./globals.js");
|
|
47
46
|
const _createLogger = (prefix, { debugEnabled } = {})=>{
|
|
48
47
|
const logger = {
|
|
49
48
|
_log: (level, ...args)=>{
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
let browserWindow;
|
|
50
|
+
try {
|
|
51
|
+
browserWindow = "u" < typeof window ? void 0 : window;
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (browserWindow && (external_config_js_default().DEBUG || browserWindow.POSTHOG_DEBUG || debugEnabled) && !(0, core_namespaceObject.isUndefined)(browserWindow.console) && browserWindow.console) {
|
|
56
|
+
const consoleLog = '__rrweb_original__' in browserWindow.console[level] ? browserWindow.console[level]['__rrweb_original__'] : browserWindow.console[level];
|
|
52
57
|
consoleLog(prefix, ...args);
|
|
53
58
|
}
|
|
54
59
|
},
|
package/dist/utils/logger.mjs
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import config from "../config.mjs";
|
|
2
2
|
import { isUndefined } from "@posthog/core";
|
|
3
|
-
import { window as external_globals_mjs_window } from "./globals.mjs";
|
|
4
3
|
const _createLogger = (prefix, { debugEnabled } = {})=>{
|
|
5
4
|
const logger = {
|
|
6
5
|
_log: (level, ...args)=>{
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
let browserWindow;
|
|
7
|
+
try {
|
|
8
|
+
browserWindow = "u" < typeof window ? void 0 : window;
|
|
9
|
+
} catch {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (browserWindow && (config.DEBUG || browserWindow.POSTHOG_DEBUG || debugEnabled) && !isUndefined(browserWindow.console) && browserWindow.console) {
|
|
13
|
+
const consoleLog = '__rrweb_original__' in browserWindow.console[level] ? browserWindow.console[level]['__rrweb_original__'] : browserWindow.console[level];
|
|
9
14
|
consoleLog(prefix, ...args);
|
|
10
15
|
}
|
|
11
16
|
},
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const isStatusZeroFailureCircuitBreakerTripped: (consecutiveStatusZeroFailures: number, maxConsecutiveStatusZeroFailures: number) => boolean;
|
|
2
|
+
export declare const updateStatusZeroFailureCount: (statusCode: number, consecutiveStatusZeroFailures: number, maxConsecutiveStatusZeroFailures: number, onCircuitBreakerTripped: () => void) => number;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
const isBrowserOnline = ()=>{
|
|
31
|
+
try {
|
|
32
|
+
return "u" > typeof window && false !== window.navigator.onLine;
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const isStatusZeroFailureCircuitBreakerTripped = (consecutiveStatusZeroFailures, maxConsecutiveStatusZeroFailures)=>consecutiveStatusZeroFailures >= maxConsecutiveStatusZeroFailures && isBrowserOnline();
|
|
38
|
+
const updateStatusZeroFailureCount = (statusCode, consecutiveStatusZeroFailures, maxConsecutiveStatusZeroFailures, onCircuitBreakerTripped)=>{
|
|
39
|
+
if (0 === statusCode) {
|
|
40
|
+
if (isBrowserOnline()) {
|
|
41
|
+
const updatedConsecutiveStatusZeroFailures = consecutiveStatusZeroFailures + 1;
|
|
42
|
+
if (updatedConsecutiveStatusZeroFailures === maxConsecutiveStatusZeroFailures) onCircuitBreakerTripped();
|
|
43
|
+
return updatedConsecutiveStatusZeroFailures;
|
|
44
|
+
}
|
|
45
|
+
return consecutiveStatusZeroFailures;
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
};
|
|
49
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
50
|
+
isStatusZeroFailureCircuitBreakerTripped: isStatusZeroFailureCircuitBreakerTripped,
|
|
51
|
+
updateStatusZeroFailureCount: updateStatusZeroFailureCount
|
|
52
|
+
});
|
|
53
|
+
exports.isStatusZeroFailureCircuitBreakerTripped = __webpack_exports__.isStatusZeroFailureCircuitBreakerTripped;
|
|
54
|
+
exports.updateStatusZeroFailureCount = __webpack_exports__.updateStatusZeroFailureCount;
|
|
55
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
56
|
+
"isStatusZeroFailureCircuitBreakerTripped",
|
|
57
|
+
"updateStatusZeroFailureCount"
|
|
58
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
|
+
Object.defineProperty(exports, '__esModule', {
|
|
60
|
+
value: true
|
|
61
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const isBrowserOnline = ()=>{
|
|
2
|
+
try {
|
|
3
|
+
return "u" > typeof window && false !== window.navigator.onLine;
|
|
4
|
+
} catch {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
const isStatusZeroFailureCircuitBreakerTripped = (consecutiveStatusZeroFailures, maxConsecutiveStatusZeroFailures)=>consecutiveStatusZeroFailures >= maxConsecutiveStatusZeroFailures && isBrowserOnline();
|
|
9
|
+
const updateStatusZeroFailureCount = (statusCode, consecutiveStatusZeroFailures, maxConsecutiveStatusZeroFailures, onCircuitBreakerTripped)=>{
|
|
10
|
+
if (0 === statusCode) {
|
|
11
|
+
if (isBrowserOnline()) {
|
|
12
|
+
const updatedConsecutiveStatusZeroFailures = consecutiveStatusZeroFailures + 1;
|
|
13
|
+
if (updatedConsecutiveStatusZeroFailures === maxConsecutiveStatusZeroFailures) onCircuitBreakerTripped();
|
|
14
|
+
return updatedConsecutiveStatusZeroFailures;
|
|
15
|
+
}
|
|
16
|
+
return consecutiveStatusZeroFailures;
|
|
17
|
+
}
|
|
18
|
+
return 0;
|
|
19
|
+
};
|
|
20
|
+
export { isStatusZeroFailureCircuitBreakerTripped, updateStatusZeroFailureCount };
|
|
@@ -11,5 +11,4 @@ export declare const getQueryParam: (url: string, param: string) => string;
|
|
|
11
11
|
export declare const maskQueryParams: <T extends string | undefined>(url: T, maskedParams: string[] | undefined, mask: string) => T extends string ? string : undefined;
|
|
12
12
|
export declare const _getHashParam: (hash: string, param: string) => string | null;
|
|
13
13
|
export declare const isLocalhost: () => boolean;
|
|
14
|
-
export
|
|
15
|
-
export declare const updateStatusZeroFailureCount: (statusCode: number, consecutiveStatusZeroFailures: number, maxConsecutiveStatusZeroFailures: number, onCircuitBreakerTripped: () => void) => number;
|
|
14
|
+
export { isStatusZeroFailureCircuitBreakerTripped, updateStatusZeroFailureCount } from './request-reachability';
|
|
@@ -33,15 +33,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
formDataToQuery: ()=>formDataToQuery,
|
|
34
34
|
getQueryParam: ()=>getQueryParam,
|
|
35
35
|
isLocalhost: ()=>isLocalhost,
|
|
36
|
-
isStatusZeroFailureCircuitBreakerTripped: ()=>isStatusZeroFailureCircuitBreakerTripped,
|
|
36
|
+
isStatusZeroFailureCircuitBreakerTripped: ()=>external_request_reachability_js_namespaceObject.isStatusZeroFailureCircuitBreakerTripped,
|
|
37
37
|
jsonStringify: ()=>jsonStringify,
|
|
38
38
|
maskQueryParams: ()=>maskQueryParams,
|
|
39
|
-
updateStatusZeroFailureCount: ()=>updateStatusZeroFailureCount
|
|
39
|
+
updateStatusZeroFailureCount: ()=>external_request_reachability_js_namespaceObject.updateStatusZeroFailureCount
|
|
40
40
|
});
|
|
41
41
|
const core_namespaceObject = require("@posthog/core");
|
|
42
42
|
const external_general_utils_js_namespaceObject = require("./general-utils.js");
|
|
43
43
|
const external_globals_js_namespaceObject = require("./globals.js");
|
|
44
44
|
const external_logger_js_namespaceObject = require("./logger.js");
|
|
45
|
+
const external_request_reachability_js_namespaceObject = require("./request-reachability.js");
|
|
45
46
|
const localDomains = [
|
|
46
47
|
'localhost',
|
|
47
48
|
'127.0.0.1'
|
|
@@ -128,18 +129,6 @@ const _getHashParam = function(hash, param) {
|
|
|
128
129
|
return matches ? matches[1] : null;
|
|
129
130
|
};
|
|
130
131
|
const isLocalhost = ()=>localDomains.includes(external_globals_js_namespaceObject.location.hostname);
|
|
131
|
-
const isStatusZeroFailureCircuitBreakerTripped = (consecutiveStatusZeroFailures, maxConsecutiveStatusZeroFailures)=>consecutiveStatusZeroFailures >= maxConsecutiveStatusZeroFailures && (0, external_globals_js_namespaceObject.isBrowserOnline)();
|
|
132
|
-
const updateStatusZeroFailureCount = (statusCode, consecutiveStatusZeroFailures, maxConsecutiveStatusZeroFailures, onCircuitBreakerTripped)=>{
|
|
133
|
-
if (0 === statusCode) {
|
|
134
|
-
if ((0, external_globals_js_namespaceObject.isBrowserOnline)()) {
|
|
135
|
-
const updatedConsecutiveStatusZeroFailures = consecutiveStatusZeroFailures + 1;
|
|
136
|
-
if (updatedConsecutiveStatusZeroFailures === maxConsecutiveStatusZeroFailures) onCircuitBreakerTripped();
|
|
137
|
-
return updatedConsecutiveStatusZeroFailures;
|
|
138
|
-
}
|
|
139
|
-
return consecutiveStatusZeroFailures;
|
|
140
|
-
}
|
|
141
|
-
return 0;
|
|
142
|
-
};
|
|
143
132
|
exports._getHashParam = __webpack_exports__._getHashParam;
|
|
144
133
|
exports.convertToURL = __webpack_exports__.convertToURL;
|
|
145
134
|
exports.formDataToQuery = __webpack_exports__.formDataToQuery;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isArray, isError, isFile, isUndefined, safeJsonStringify } from "@posthog/core";
|
|
2
2
|
import { each, errorToProperties } from "./general-utils.mjs";
|
|
3
|
-
import { document as external_globals_mjs_document,
|
|
3
|
+
import { document as external_globals_mjs_document, location as external_globals_mjs_location } from "./globals.mjs";
|
|
4
4
|
import { logger } from "./logger.mjs";
|
|
5
5
|
const localDomains = [
|
|
6
6
|
'localhost',
|
|
@@ -88,16 +88,5 @@ const _getHashParam = function(hash, param) {
|
|
|
88
88
|
return matches ? matches[1] : null;
|
|
89
89
|
};
|
|
90
90
|
const isLocalhost = ()=>localDomains.includes(external_globals_mjs_location.hostname);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (0 === statusCode) {
|
|
94
|
-
if (isBrowserOnline()) {
|
|
95
|
-
const updatedConsecutiveStatusZeroFailures = consecutiveStatusZeroFailures + 1;
|
|
96
|
-
if (updatedConsecutiveStatusZeroFailures === maxConsecutiveStatusZeroFailures) onCircuitBreakerTripped();
|
|
97
|
-
return updatedConsecutiveStatusZeroFailures;
|
|
98
|
-
}
|
|
99
|
-
return consecutiveStatusZeroFailures;
|
|
100
|
-
}
|
|
101
|
-
return 0;
|
|
102
|
-
};
|
|
103
|
-
export { _getHashParam, convertToURL, formDataToQuery, getQueryParam, isLocalhost, isStatusZeroFailureCircuitBreakerTripped, jsonStringify, maskQueryParams, updateStatusZeroFailureCount };
|
|
91
|
+
export { isStatusZeroFailureCircuitBreakerTripped, updateStatusZeroFailureCount } from "./request-reachability.mjs";
|
|
92
|
+
export { _getHashParam, convertToURL, formDataToQuery, getQueryParam, isLocalhost, jsonStringify, maskQueryParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTimezone(): string | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
function getTimezone() {
|
|
31
|
+
try {
|
|
32
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
38
|
+
getTimezone: ()=>getTimezone
|
|
39
|
+
});
|
|
40
|
+
exports.getTimezone = __webpack_exports__.getTimezone;
|
|
41
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
42
|
+
"getTimezone"
|
|
43
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
44
|
+
Object.defineProperty(exports, '__esModule', {
|
|
45
|
+
value: true
|
|
46
|
+
});
|