@posthog/browser-common 0.9.8 → 0.9.10

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.
@@ -7,6 +7,8 @@ export interface SurveyCapturedEvent {
7
7
  export interface SurveyActionHost {
8
8
  subscribeCapture?: ((listener: (event: string, payload?: SurveyCapturedEvent) => void) => () => void) | undefined;
9
9
  setElementSelectors?: ((selectors: Set<string>, owner?: object) => void) | undefined;
10
+ /** Local fallback for action URL steps only; does not change captured properties. */
11
+ getActionUrl?: (() => string | undefined) | undefined;
10
12
  }
11
13
  export interface SurveyEventHost extends SurveyActionHost {
12
14
  subscribeSession?: ((listener: (sessionId: string) => void) => () => void) | undefined;
@@ -1,5 +1,6 @@
1
1
  import type { Survey } from './types/surveys';
2
2
  import type { Client } from './client';
3
+ import type { SurveyActionHost } from './survey-event-host';
3
4
  import type { SurveyCapturedEvent as CaptureResult } from './survey-event-host';
4
5
  import { type ActivationOutcome, EventReceiver } from './survey-event-receiver-base';
5
6
  import { createLogger } from './utils/logger';
@@ -10,7 +11,7 @@ export interface SurveyTriggerHost {
10
11
  export declare class SurveyEventReceiver extends EventReceiver<Survey> {
11
12
  private readonly _client;
12
13
  private readonly _surveys;
13
- constructor(_client: Client, _surveys: SurveyTriggerHost, onActivationChanged?: () => void);
14
+ constructor(_client: Client, _surveys: SurveyTriggerHost, actions?: Pick<SurveyActionHost, 'getActionUrl' | 'setElementSelectors'>, onActivationChanged?: () => void);
14
15
  protected _getActivatedKey(): string;
15
16
  protected _getActivatedSessionKey(): string;
16
17
  protected _getActivationTimestampsKey(): string;
@@ -37,7 +37,7 @@ const external_survey_constants_js_namespaceObject = require("./survey-constants
37
37
  const survey_utils_js_namespaceObject = require("./utils/survey-utils.js");
38
38
  const external_survey_event_receiver_base_js_namespaceObject = require("./survey-event-receiver-base.js");
39
39
  class SurveyEventReceiver extends external_survey_event_receiver_base_js_namespaceObject.EventReceiver {
40
- constructor(_client, _surveys, onActivationChanged){
40
+ constructor(_client, _surveys, actions, onActivationChanged){
41
41
  super({
42
42
  subscribeCapture: (listener)=>{
43
43
  const subscription = _client.onEvent((event)=>listener(event.event, event));
@@ -49,7 +49,8 @@ class SurveyEventReceiver extends external_survey_event_receiver_base_js_namespa
49
49
  },
50
50
  getSessionId: ()=>_client.session?.sessionId,
51
51
  getProperty: (key)=>_client.kv.get(key),
52
- setElementSelectors: (selectors, owner)=>_client.getExtension('autocapture')?.setElementSelectors(selectors, owner)
52
+ getActionUrl: actions?.getActionUrl,
53
+ setElementSelectors: actions?.setElementSelectors ?? ((selectors, owner)=>_client.getExtension('autocapture')?.setElementSelectors(selectors, owner))
53
54
  }, onActivationChanged), this._client = _client, this._surveys = _surveys;
54
55
  this._subscribeSession();
55
56
  }
@@ -5,7 +5,7 @@ import { SurveyEventName } from "./survey-constants.mjs";
5
5
  import { SURVEY_LOGGER } from "./utils/survey-utils.mjs";
6
6
  import { EventReceiver } from "./survey-event-receiver-base.mjs";
7
7
  class SurveyEventReceiver extends EventReceiver {
8
- constructor(_client, _surveys, onActivationChanged){
8
+ constructor(_client, _surveys, actions, onActivationChanged){
9
9
  super({
10
10
  subscribeCapture: (listener)=>{
11
11
  const subscription = _client.onEvent((event)=>listener(event.event, event));
@@ -17,7 +17,8 @@ class SurveyEventReceiver extends EventReceiver {
17
17
  },
18
18
  getSessionId: ()=>_client.session?.sessionId,
19
19
  getProperty: (key)=>_client.kv.get(key),
20
- setElementSelectors: (selectors, owner)=>_client.getExtension('autocapture')?.setElementSelectors(selectors, owner)
20
+ getActionUrl: actions?.getActionUrl,
21
+ setElementSelectors: actions?.setElementSelectors ?? ((selectors, owner)=>_client.getExtension('autocapture')?.setElementSelectors(selectors, owner))
21
22
  }, onActivationChanged), this._client = _client, this._surveys = _surveys;
22
23
  this._subscribeSession();
23
24
  }
package/dist/surveys.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { SurveyEventType, SurveyWidgetType, SurveyPosition, SurveyTabPosition, SurveyType, SurveyQuestionType, SurveyQuestionBranchingType, SurveySchedule, SurveyEventName, SurveyEventProperties, DisplaySurveyType, } from './survey-constants';
2
+ import { SurveyEventReceiver } from './survey-event-receiver';
2
3
  import type { SurveyRenderContext } from './survey-render-context';
3
4
  import type { Client } from './client';
4
5
  import type { DeepReadonly } from './client';
@@ -44,6 +45,7 @@ export declare class PostHogSurveys implements Extension {
44
45
  loadIfEnabled(): void;
45
46
  /** Helper to finalize survey initialization */
46
47
  private _completeSurveyInitialization;
48
+ protected _createEventReceiver(client: Client, onActivationChanged?: () => void): SurveyEventReceiver;
47
49
  /** Helper to handle errors during survey loading */
48
50
  private _handleSurveyLoadError;
49
51
  /**
@@ -70,6 +72,7 @@ export declare class PostHogSurveys implements Extension {
70
72
  getSurveys(callback: SurveyCallback, forceReload?: boolean): void;
71
73
  private _handleSurveyResponse;
72
74
  private _registerEventOrActionBasedSurveys;
75
+ protected _registerSurveyTriggers(surveys: Survey[]): void;
73
76
  /**
74
77
  * Whether to kick off a background refresh of the cached definitions: the cache is stale, no
75
78
  * fetch is already in flight, and we're not backing off after a recent failure.
package/dist/surveys.js CHANGED
@@ -195,7 +195,7 @@ class PostHogSurveys {
195
195
  _completeSurveyInitialization(generateSurveysFn, isSurveysEnabled) {
196
196
  if (this._disposed) return;
197
197
  this._surveyManager = generateSurveysFn(isSurveysEnabled);
198
- this._surveyEventReceiver = new external_survey_event_receiver_js_namespaceObject.SurveyEventReceiver(this._client, this, this._notifyActiveMatchingSurveyCallbacks);
198
+ this._surveyEventReceiver = this._createEventReceiver(this._client, this._notifyActiveMatchingSurveyCallbacks);
199
199
  const cachedSurveys = this._client?.kv.get(external_surveys_config_js_namespaceObject.SURVEYS);
200
200
  if (cachedSurveys) this._registerEventOrActionBasedSurveys(cachedSurveys);
201
201
  survey_utils_js_namespaceObject.SURVEY_LOGGER.info('Surveys loaded successfully');
@@ -205,6 +205,9 @@ class PostHogSurveys {
205
205
  isLoaded: true
206
206
  });
207
207
  }
208
+ _createEventReceiver(client, onActivationChanged) {
209
+ return new external_survey_event_receiver_js_namespaceObject.SurveyEventReceiver(client, this, void 0, onActivationChanged);
210
+ }
208
211
  _handleSurveyLoadError(message, error) {
209
212
  this._surveyInitializationFailed = true;
210
213
  survey_utils_js_namespaceObject.SURVEY_LOGGER.error(message, error);
@@ -319,7 +322,10 @@ class PostHogSurveys {
319
322
  }
320
323
  _registerEventOrActionBasedSurveys(surveys) {
321
324
  const eventOrActionBasedSurveys = surveys.filter((survey)=>(0, survey_utils_js_namespaceObject.isSurveyRunning)(survey) && ((0, survey_utils_js_namespaceObject.doesSurveyActivateByEvent)(survey) || (0, survey_utils_js_namespaceObject.doesSurveyActivateByAction)(survey)));
322
- this._surveyEventReceiver?.replace(eventOrActionBasedSurveys);
325
+ this._registerSurveyTriggers(eventOrActionBasedSurveys);
326
+ }
327
+ _registerSurveyTriggers(surveys) {
328
+ this._surveyEventReceiver?.replace(surveys);
323
329
  }
324
330
  _shouldBackgroundRefreshSurveys() {
325
331
  return this._isSurveyCacheStale() && !this._getSurveysInFlightPromise && !this._isSurveyRefreshBackingOff();
package/dist/surveys.mjs CHANGED
@@ -152,7 +152,7 @@ class PostHogSurveys {
152
152
  _completeSurveyInitialization(generateSurveysFn, isSurveysEnabled) {
153
153
  if (this._disposed) return;
154
154
  this._surveyManager = generateSurveysFn(isSurveysEnabled);
155
- this._surveyEventReceiver = new SurveyEventReceiver(this._client, this, this._notifyActiveMatchingSurveyCallbacks);
155
+ this._surveyEventReceiver = this._createEventReceiver(this._client, this._notifyActiveMatchingSurveyCallbacks);
156
156
  const cachedSurveys = this._client?.kv.get(SURVEYS);
157
157
  if (cachedSurveys) this._registerEventOrActionBasedSurveys(cachedSurveys);
158
158
  SURVEY_LOGGER.info('Surveys loaded successfully');
@@ -162,6 +162,9 @@ class PostHogSurveys {
162
162
  isLoaded: true
163
163
  });
164
164
  }
165
+ _createEventReceiver(client, onActivationChanged) {
166
+ return new SurveyEventReceiver(client, this, void 0, onActivationChanged);
167
+ }
165
168
  _handleSurveyLoadError(message, error) {
166
169
  this._surveyInitializationFailed = true;
167
170
  SURVEY_LOGGER.error(message, error);
@@ -276,7 +279,10 @@ class PostHogSurveys {
276
279
  }
277
280
  _registerEventOrActionBasedSurveys(surveys) {
278
281
  const eventOrActionBasedSurveys = surveys.filter((survey)=>isSurveyRunning(survey) && (doesSurveyActivateByEvent(survey) || doesSurveyActivateByAction(survey)));
279
- this._surveyEventReceiver?.replace(eventOrActionBasedSurveys);
282
+ this._registerSurveyTriggers(eventOrActionBasedSurveys);
283
+ }
284
+ _registerSurveyTriggers(surveys) {
285
+ this._surveyEventReceiver?.replace(surveys);
280
286
  }
281
287
  _shouldBackgroundRefreshSurveys() {
282
288
  return this._isSurveyCacheStale() && !this._getSurveysInFlightPromise && !this._isSurveyRefreshBackingOff();
@@ -227,7 +227,8 @@ const DEFAULT_DEAD_CLICK_IGNORE_LIST = [
227
227
  '.ph-no-capture'
228
228
  ];
229
229
  function shouldCaptureDeadClick(el, _config) {
230
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
230
+ const win = "u" < typeof window ? void 0 : window;
231
+ if (!win || cannotCheckForAutocapture(el)) return false;
231
232
  const selectorIgnoreList = (0, core_namespaceObject.isBoolean)(_config) ? DEFAULT_DEAD_CLICK_IGNORE_LIST : _config?.css_selector_ignorelist ?? DEFAULT_DEAD_CLICK_IGNORE_LIST;
232
233
  const { targetElementList } = getElementAndParentsForElement(el, false);
233
234
  return !checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList);
@@ -258,7 +259,8 @@ function isTextSelectionTarget(el) {
258
259
  return isContentEditableTarget(el);
259
260
  }
260
261
  function shouldCaptureRageclick(el, _config) {
261
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
262
+ const win = "u" < typeof window ? void 0 : window;
263
+ if (!win || cannotCheckForAutocapture(el)) return false;
262
264
  let selectorIgnoreList;
263
265
  let contentIgnorelist;
264
266
  let ignoreTextSelection;
@@ -279,7 +281,8 @@ function shouldCaptureRageclick(el, _config) {
279
281
  }
280
282
  const cannotCheckForAutocapture = (el)=>!el || (0, external_element_utils_js_namespaceObject.isTag)(el, 'html') || !(0, external_element_utils_js_namespaceObject.isElementNode)(el);
281
283
  const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
282
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return {
284
+ const win = "u" < typeof window ? void 0 : window;
285
+ if (!win || cannotCheckForAutocapture(el)) return {
283
286
  parentIsUsefulElement: false,
284
287
  targetElementList: []
285
288
  };
@@ -298,7 +301,7 @@ const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
298
301
  if (!parentNode) break;
299
302
  if (captureOnAnyElement || autocaptureCompatibleElements.indexOf(parentNode.tagName.toLowerCase()) > -1) parentIsUsefulElement = true;
300
303
  else try {
301
- const compStyles = window.getComputedStyle(parentNode);
304
+ const compStyles = win.getComputedStyle(parentNode);
302
305
  if (compStyles && 'pointer' === compStyles.getPropertyValue('cursor')) parentIsUsefulElement = true;
303
306
  } catch {}
304
307
  targetElementList.push(parentNode);
@@ -310,12 +313,14 @@ const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
310
313
  };
311
314
  };
312
315
  function shouldSkipDeadClick(el) {
313
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
316
+ const win = "u" < typeof window ? void 0 : window;
317
+ if (!win || cannotCheckForAutocapture(el)) return false;
314
318
  const { targetElementList } = getElementAndParentsForElement(el, false);
315
319
  return targetElementList.some((node)=>(0, external_element_utils_js_namespaceObject.isTag)(node, 'a'));
316
320
  }
317
321
  function shouldCaptureDomEvent(el, event, autocaptureConfig, captureOnAnyElement, allowedEventTypes, instance) {
318
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
322
+ const win = "u" < typeof window ? void 0 : window;
323
+ if (!win || cannotCheckForAutocapture(el)) return false;
319
324
  if (autocaptureConfig?.url_allowlist) {
320
325
  if (!checkForURLMatches(autocaptureConfig.url_allowlist, instance)) return false;
321
326
  }
@@ -332,7 +337,7 @@ function shouldCaptureDomEvent(el, event, autocaptureConfig, captureOnAnyElement
332
337
  const selectorIgnoreList = autocaptureConfig?.css_selector_ignorelist ?? DEFAULT_AUTOCAPTURE_IGNORE_LIST;
333
338
  if (checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList)) return false;
334
339
  try {
335
- const compStyles = window.getComputedStyle(el);
340
+ const compStyles = win.getComputedStyle(el);
336
341
  if (compStyles && 'pointer' === compStyles.getPropertyValue('cursor') && 'click' === event.type) return true;
337
342
  } catch {}
338
343
  const tag = el.tagName.toLowerCase();
@@ -173,7 +173,8 @@ const DEFAULT_DEAD_CLICK_IGNORE_LIST = [
173
173
  '.ph-no-capture'
174
174
  ];
175
175
  function shouldCaptureDeadClick(el, _config) {
176
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
176
+ const win = "u" < typeof window ? void 0 : window;
177
+ if (!win || cannotCheckForAutocapture(el)) return false;
177
178
  const selectorIgnoreList = isBoolean(_config) ? DEFAULT_DEAD_CLICK_IGNORE_LIST : _config?.css_selector_ignorelist ?? DEFAULT_DEAD_CLICK_IGNORE_LIST;
178
179
  const { targetElementList } = getElementAndParentsForElement(el, false);
179
180
  return !checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList);
@@ -204,7 +205,8 @@ function isTextSelectionTarget(el) {
204
205
  return isContentEditableTarget(el);
205
206
  }
206
207
  function shouldCaptureRageclick(el, _config) {
207
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
208
+ const win = "u" < typeof window ? void 0 : window;
209
+ if (!win || cannotCheckForAutocapture(el)) return false;
208
210
  let selectorIgnoreList;
209
211
  let contentIgnorelist;
210
212
  let ignoreTextSelection;
@@ -225,7 +227,8 @@ function shouldCaptureRageclick(el, _config) {
225
227
  }
226
228
  const cannotCheckForAutocapture = (el)=>!el || isTag(el, 'html') || !isElementNode(el);
227
229
  const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
228
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return {
230
+ const win = "u" < typeof window ? void 0 : window;
231
+ if (!win || cannotCheckForAutocapture(el)) return {
229
232
  parentIsUsefulElement: false,
230
233
  targetElementList: []
231
234
  };
@@ -244,7 +247,7 @@ const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
244
247
  if (!parentNode) break;
245
248
  if (captureOnAnyElement || autocaptureCompatibleElements.indexOf(parentNode.tagName.toLowerCase()) > -1) parentIsUsefulElement = true;
246
249
  else try {
247
- const compStyles = window.getComputedStyle(parentNode);
250
+ const compStyles = win.getComputedStyle(parentNode);
248
251
  if (compStyles && 'pointer' === compStyles.getPropertyValue('cursor')) parentIsUsefulElement = true;
249
252
  } catch {}
250
253
  targetElementList.push(parentNode);
@@ -256,12 +259,14 @@ const getElementAndParentsForElement = (el, captureOnAnyElement)=>{
256
259
  };
257
260
  };
258
261
  function shouldSkipDeadClick(el) {
259
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
262
+ const win = "u" < typeof window ? void 0 : window;
263
+ if (!win || cannotCheckForAutocapture(el)) return false;
260
264
  const { targetElementList } = getElementAndParentsForElement(el, false);
261
265
  return targetElementList.some((node)=>isTag(node, 'a'));
262
266
  }
263
267
  function shouldCaptureDomEvent(el, event, autocaptureConfig, captureOnAnyElement, allowedEventTypes, instance) {
264
- if ("u" < typeof window || cannotCheckForAutocapture(el)) return false;
268
+ const win = "u" < typeof window ? void 0 : window;
269
+ if (!win || cannotCheckForAutocapture(el)) return false;
265
270
  if (autocaptureConfig?.url_allowlist) {
266
271
  if (!checkForURLMatches(autocaptureConfig.url_allowlist, instance)) return false;
267
272
  }
@@ -278,7 +283,7 @@ function shouldCaptureDomEvent(el, event, autocaptureConfig, captureOnAnyElement
278
283
  const selectorIgnoreList = autocaptureConfig?.css_selector_ignorelist ?? DEFAULT_AUTOCAPTURE_IGNORE_LIST;
279
284
  if (checkIfElementsMatchCSSSelector(targetElementList, selectorIgnoreList)) return false;
280
285
  try {
281
- const compStyles = window.getComputedStyle(el);
286
+ const compStyles = win.getComputedStyle(el);
282
287
  if (compStyles && 'pointer' === compStyles.getPropertyValue('cursor') && 'click' === event.type) return true;
283
288
  } catch {}
284
289
  const tag = el.tagName.toLowerCase();
@@ -0,0 +1,7 @@
1
+ /**
2
+ * IE11 doesn't support `new URL`
3
+ * so we can create an anchor element and use that to parse the URL
4
+ * there's a lot of overlap between HTMLHyperlinkElementUtils and URL
5
+ * meaning useful properties like `pathname` are available on both
6
+ */
7
+ export declare const convertToURL: (url: string) => HTMLAnchorElement | null;
@@ -0,0 +1,47 @@
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
+ __webpack_require__.d(__webpack_exports__, {
31
+ convertToURL: ()=>convertToURL
32
+ });
33
+ const core_namespaceObject = require("@posthog/core");
34
+ const convertToURL = (url)=>{
35
+ const doc = "u" < typeof document ? void 0 : document;
36
+ const location = doc?.createElement('a');
37
+ if ((0, core_namespaceObject.isUndefined)(location)) return null;
38
+ location.href = url;
39
+ return location;
40
+ };
41
+ exports.convertToURL = __webpack_exports__.convertToURL;
42
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
43
+ "convertToURL"
44
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
45
+ Object.defineProperty(exports, '__esModule', {
46
+ value: true
47
+ });
@@ -0,0 +1,9 @@
1
+ import { isUndefined } from "@posthog/core";
2
+ const convertToURL = (url)=>{
3
+ const doc = "u" < typeof document ? void 0 : document;
4
+ const location = doc?.createElement('a');
5
+ if (isUndefined(location)) return null;
6
+ location.href = url;
7
+ return location;
8
+ };
9
+ export { convertToURL };
@@ -1,11 +1,5 @@
1
1
  export declare const jsonStringify: (data: any, space?: string | number) => string;
2
- /**
3
- * IE11 doesn't support `new URL`
4
- * so we can create an anchor element and use that to parse the URL
5
- * there's a lot of overlap between HTMLHyperlinkElementUtils and URL
6
- * meaning useful properties like `pathname` are available on both
7
- */
8
- export declare const convertToURL: (url: string) => HTMLAnchorElement | null;
2
+ export { convertToURL } from './convert-to-url';
9
3
  export declare const formDataToQuery: (formdata: Record<string, any> | FormData, arg_separator?: string) => string;
10
4
  export declare const getQueryParam: (url: string, param: string) => string;
11
5
  export declare const maskQueryParams: <T extends string | undefined>(url: T, maskedParams: string[] | undefined, mask: string) => T extends string ? string : undefined;
@@ -29,7 +29,7 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  _getHashParam: ()=>_getHashParam,
32
- convertToURL: ()=>convertToURL,
32
+ convertToURL: ()=>external_convert_to_url_js_namespaceObject.convertToURL,
33
33
  formDataToQuery: ()=>formDataToQuery,
34
34
  getQueryParam: ()=>getQueryParam,
35
35
  isLocalhost: ()=>isLocalhost,
@@ -42,6 +42,7 @@ 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_convert_to_url_js_namespaceObject = require("./convert-to-url.js");
45
46
  const external_request_reachability_js_namespaceObject = require("./request-reachability.js");
46
47
  const localDomains = [
47
48
  'localhost',
@@ -62,12 +63,6 @@ const jsonStringify = (data, space)=>{
62
63
  return (0, core_namespaceObject.safeJsonStringify)(data);
63
64
  }
64
65
  };
65
- const convertToURL = (url)=>{
66
- const location = external_globals_js_namespaceObject.document?.createElement('a');
67
- if ((0, core_namespaceObject.isUndefined)(location)) return null;
68
- location.href = url;
69
- return location;
70
- };
71
66
  const formDataToQuery = function(formdata, arg_separator = '&') {
72
67
  let use_val;
73
68
  let use_key;
@@ -87,7 +82,7 @@ const getQueryParam = function(url, param) {
87
82
  const queryParts = cleanedQueryParams.split('&');
88
83
  let keyValuePair;
89
84
  for(let i = 0; i < queryParts.length; i++){
90
- const parts = queryParts[i].split('=');
85
+ const parts = queryParts[i].split(/=(.*)/);
91
86
  if (parts[0] === param) {
92
87
  keyValuePair = parts;
93
88
  break;
@@ -95,13 +90,13 @@ const getQueryParam = function(url, param) {
95
90
  }
96
91
  if (!(0, core_namespaceObject.isArray)(keyValuePair) || keyValuePair.length < 2) return '';
97
92
  {
98
- let result = keyValuePair[1];
93
+ let result = keyValuePair[1].replace(/\+/g, ' ');
99
94
  try {
100
95
  result = decodeURIComponent(result);
101
96
  } catch {
102
97
  external_logger_js_namespaceObject.logger.error('Skipping decoding for malformed query param: ' + result);
103
98
  }
104
- return result.replace(/\+/g, ' ');
99
+ return result;
105
100
  }
106
101
  };
107
102
  const maskQueryParams = function(url, maskedParams, mask) {
@@ -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, location as external_globals_mjs_location } from "./globals.mjs";
3
+ import { location as external_globals_mjs_location } from "./globals.mjs";
4
4
  import { logger } from "./logger.mjs";
5
5
  const localDomains = [
6
6
  'localhost',
@@ -21,12 +21,6 @@ const jsonStringify = (data, space)=>{
21
21
  return safeJsonStringify(data);
22
22
  }
23
23
  };
24
- const convertToURL = (url)=>{
25
- const location = external_globals_mjs_document?.createElement('a');
26
- if (isUndefined(location)) return null;
27
- location.href = url;
28
- return location;
29
- };
30
24
  const formDataToQuery = function(formdata, arg_separator = '&') {
31
25
  let use_val;
32
26
  let use_key;
@@ -46,7 +40,7 @@ const getQueryParam = function(url, param) {
46
40
  const queryParts = cleanedQueryParams.split('&');
47
41
  let keyValuePair;
48
42
  for(let i = 0; i < queryParts.length; i++){
49
- const parts = queryParts[i].split('=');
43
+ const parts = queryParts[i].split(/=(.*)/);
50
44
  if (parts[0] === param) {
51
45
  keyValuePair = parts;
52
46
  break;
@@ -54,13 +48,13 @@ const getQueryParam = function(url, param) {
54
48
  }
55
49
  if (!isArray(keyValuePair) || keyValuePair.length < 2) return '';
56
50
  {
57
- let result = keyValuePair[1];
51
+ let result = keyValuePair[1].replace(/\+/g, ' ');
58
52
  try {
59
53
  result = decodeURIComponent(result);
60
54
  } catch {
61
55
  logger.error('Skipping decoding for malformed query param: ' + result);
62
56
  }
63
- return result.replace(/\+/g, ' ');
57
+ return result;
64
58
  }
65
59
  };
66
60
  const maskQueryParams = function(url, maskedParams, mask) {
@@ -88,5 +82,6 @@ const _getHashParam = function(hash, param) {
88
82
  return matches ? matches[1] : null;
89
83
  };
90
84
  const isLocalhost = ()=>localDomains.includes(external_globals_mjs_location.hostname);
85
+ export { convertToURL } from "./convert-to-url.mjs";
91
86
  export { isStatusZeroFailureCircuitBreakerTripped, updateStatusZeroFailureCount } from "./request-reachability.mjs";
92
- export { _getHashParam, convertToURL, formDataToQuery, getQueryParam, isLocalhost, jsonStringify, maskQueryParams };
87
+ export { _getHashParam, formDataToQuery, getQueryParam, isLocalhost, jsonStringify, maskQueryParams };
@@ -45,7 +45,8 @@ function applyUrlTargetingOverride(instance, defaultUrl) {
45
45
  }
46
46
  }
47
47
  function getTargetingUrl(instance) {
48
- const defaultUrl = "u" > typeof window ? window.location?.href : void 0;
48
+ const win = "u" < typeof window ? void 0 : window;
49
+ const defaultUrl = win?.location?.href;
49
50
  return (0, core_namespaceObject.isUndefined)(defaultUrl) ? void 0 : applyUrlTargetingOverride(instance, defaultUrl);
50
51
  }
51
52
  exports.applyUrlTargetingOverride = __webpack_exports__.applyUrlTargetingOverride;
@@ -12,7 +12,8 @@ function applyUrlTargetingOverride(instance, defaultUrl) {
12
12
  }
13
13
  }
14
14
  function getTargetingUrl(instance) {
15
- const defaultUrl = "u" > typeof window ? window.location?.href : void 0;
15
+ const win = "u" < typeof window ? void 0 : window;
16
+ const defaultUrl = win?.location?.href;
16
17
  return isUndefined(defaultUrl) ? void 0 : applyUrlTargetingOverride(instance, defaultUrl);
17
18
  }
18
19
  export { applyUrlTargetingOverride, getTargetingUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/browser-common",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
4
4
  "description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -91,6 +91,15 @@
91
91
  ],
92
92
  "surveys/survey-translations": [
93
93
  "dist/surveys/survey-translations.d.ts"
94
+ ],
95
+ "autocapture": [
96
+ "dist/autocapture.d.ts"
97
+ ],
98
+ "autocapture-config": [
99
+ "dist/autocapture-config.d.ts"
100
+ ],
101
+ "rageclick": [
102
+ "dist/rageclick.d.ts"
94
103
  ]
95
104
  }
96
105
  },
@@ -214,12 +223,27 @@
214
223
  "types": "./dist/surveys/survey-translations.d.ts",
215
224
  "require": "./dist/surveys/survey-translations.js",
216
225
  "import": "./dist/surveys/survey-translations.mjs"
226
+ },
227
+ "./autocapture": {
228
+ "types": "./dist/autocapture.d.ts",
229
+ "require": "./dist/autocapture.js",
230
+ "import": "./dist/autocapture.mjs"
231
+ },
232
+ "./autocapture-config": {
233
+ "types": "./dist/autocapture-config.d.ts",
234
+ "require": "./dist/autocapture-config.js",
235
+ "import": "./dist/autocapture-config.mjs"
236
+ },
237
+ "./rageclick": {
238
+ "types": "./dist/rageclick.d.ts",
239
+ "require": "./dist/rageclick.js",
240
+ "import": "./dist/rageclick.mjs"
217
241
  }
218
242
  },
219
243
  "dependencies": {
220
244
  "preact": "^10.29.3",
221
- "@posthog/types": "^1.416.0",
222
- "@posthog/core": "^1.59.4"
245
+ "@posthog/core": "^1.60.0",
246
+ "@posthog/types": "^1.416.0"
223
247
  },
224
248
  "devDependencies": {
225
249
  "@rsbuild/plugin-react": "^2.1.0",