posthog-js 1.138.0 → 1.138.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.
Files changed (57) hide show
  1. package/dist/array.full.js +2 -2
  2. package/dist/array.full.js.map +1 -1
  3. package/dist/array.js +1 -1
  4. package/dist/array.js.map +1 -1
  5. package/dist/es.js +1 -1
  6. package/dist/es.js.map +1 -1
  7. package/dist/lib/src/extensions/replay/rrweb-plugins/patch.d.ts +3 -0
  8. package/dist/lib/src/extensions/sentry-integration.d.ts +22 -2
  9. package/dist/lib/src/extensions/surveys/surveys-utils.d.ts +2 -0
  10. package/dist/lib/src/extensions/tracing-headers.d.ts +10 -0
  11. package/dist/lib/src/loader-recorder.d.ts +0 -3
  12. package/dist/lib/src/loader-tracing-headers.d.ts +1 -0
  13. package/dist/lib/src/posthog-core.d.ts +2 -1
  14. package/dist/lib/src/posthog-surveys-types.d.ts +2 -0
  15. package/dist/lib/src/types.d.ts +5 -0
  16. package/dist/module.d.ts +29 -2
  17. package/dist/module.js +1 -1
  18. package/dist/module.js.map +1 -1
  19. package/dist/recorder-v2.js +1 -1
  20. package/dist/recorder-v2.js.map +1 -1
  21. package/dist/recorder.js +1 -1
  22. package/dist/recorder.js.map +1 -1
  23. package/dist/surveys-module-previews.js +1 -1
  24. package/dist/surveys-module-previews.js.map +1 -1
  25. package/dist/surveys.js +1 -1
  26. package/dist/surveys.js.map +1 -1
  27. package/dist/tracing-headers.js +2 -0
  28. package/dist/tracing-headers.js.map +1 -0
  29. package/lib/package.json +2 -2
  30. package/lib/src/extensions/replay/rrweb-plugins/patch.d.ts +3 -0
  31. package/lib/src/extensions/replay/rrweb-plugins/patch.js +39 -0
  32. package/lib/src/extensions/replay/rrweb-plugins/patch.js.map +1 -0
  33. package/lib/src/extensions/sentry-integration.d.ts +22 -2
  34. package/lib/src/extensions/sentry-integration.js +55 -39
  35. package/lib/src/extensions/sentry-integration.js.map +1 -1
  36. package/lib/src/extensions/surveys/surveys-utils.d.ts +2 -0
  37. package/lib/src/extensions/surveys/surveys-utils.jsx +37 -3
  38. package/lib/src/extensions/surveys/surveys-utils.jsx.map +1 -1
  39. package/lib/src/extensions/surveys.jsx +5 -20
  40. package/lib/src/extensions/surveys.jsx.map +1 -1
  41. package/lib/src/extensions/tracing-headers.d.ts +10 -0
  42. package/lib/src/extensions/tracing-headers.js +51 -0
  43. package/lib/src/extensions/tracing-headers.js.map +1 -0
  44. package/lib/src/loader-recorder.d.ts +0 -3
  45. package/lib/src/loader-recorder.js +2 -42
  46. package/lib/src/loader-recorder.js.map +1 -1
  47. package/lib/src/loader-tracing-headers.d.ts +1 -0
  48. package/lib/src/loader-tracing-headers.js +87 -0
  49. package/lib/src/loader-tracing-headers.js.map +1 -0
  50. package/lib/src/posthog-core.d.ts +2 -1
  51. package/lib/src/posthog-core.js +5 -1
  52. package/lib/src/posthog-core.js.map +1 -1
  53. package/lib/src/posthog-surveys-types.d.ts +2 -0
  54. package/lib/src/posthog-surveys-types.js.map +1 -1
  55. package/lib/src/types.d.ts +5 -0
  56. package/lib/src/types.js.map +1 -1
  57. package/package.json +2 -2
@@ -27,7 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  };
28
28
  import { SurveyQuestionType, SurveyType } from '../posthog-surveys-types';
29
29
  import { window as _window, document as _document } from '../utils/globals';
30
- import { style, defaultSurveyAppearance, sendSurveyEvent, createShadow, getContrastingTextColor, SurveyContext, getDisplayOrderQuestions, } from './surveys/surveys-utils';
30
+ import { style, defaultSurveyAppearance, sendSurveyEvent, dismissedSurveyEvent, createShadow, getContrastingTextColor, SurveyContext, getDisplayOrderQuestions, getSurveySeenKey, } from './surveys/surveys-utils';
31
31
  import * as Preact from 'preact';
32
32
  import { createWidgetShadow, createWidgetStyle } from './surveys-widget';
33
33
  import { useState, useEffect, useRef, useContext, useMemo } from 'preact/hooks';
@@ -99,7 +99,7 @@ export var callSurveys = function (posthog, forceReload) {
99
99
  return;
100
100
  }
101
101
  }
102
- if (!localStorage.getItem("seenSurvey_".concat(survey.id))) {
102
+ if (!localStorage.getItem(getSurveySeenKey(survey))) {
103
103
  var shadow = createShadow(style(survey === null || survey === void 0 ? void 0 : survey.appearance), survey.id);
104
104
  Preact.render(<SurveyPopup key={'popover-survey'} posthog={posthog} survey={survey}/>, shadow);
105
105
  }
@@ -172,6 +172,8 @@ export function SurveyPopup(_a) {
172
172
  posthog.capture('survey shown', {
173
173
  $survey_name: survey.name,
174
174
  $survey_id: survey.id,
175
+ $survey_iteration: survey.current_iteration,
176
+ $survey_iteration_start_date: survey.current_iteration_start_date,
175
177
  sessionRecordingUrl: (_a = posthog.get_session_replay_url) === null || _a === void 0 ? void 0 : _a.call(posthog),
176
178
  });
177
179
  localStorage.setItem("lastSeenSurveyDate", new Date().toISOString());
@@ -194,7 +196,7 @@ export function SurveyPopup(_a) {
194
196
  return isPopupVisible ? (<SurveyContext.Provider value={{
195
197
  isPreviewMode: isPreviewMode,
196
198
  previewPageIndex: previewPageIndex,
197
- handleCloseSurveyPopup: function () { return closeSurveyPopup(survey, posthog, isPreviewMode); },
199
+ handleCloseSurveyPopup: function () { return dismissedSurveyEvent(survey, posthog, isPreviewMode); },
198
200
  }}>
199
201
  {!shouldShowConfirmation ? (<Questions survey={survey} forceDisableHtml={!!forceDisableHtml} posthog={posthog} styleOverrides={style}/>) : (<ConfirmationMessage header={((_b = survey.appearance) === null || _b === void 0 ? void 0 : _b.thankYouMessageHeader) || 'Thank you!'} description={((_c = survey.appearance) === null || _c === void 0 ? void 0 : _c.thankYouMessageDescription) || ''} forceDisableHtml={!!forceDisableHtml} contentType={(_d = survey.appearance) === null || _d === void 0 ? void 0 : _d.thankYouMessageDescriptionContentType} appearance={survey.appearance || defaultSurveyAppearance} styleOverrides={__assign(__assign({}, style), confirmationBoxLeftStyle)} onClose={function () { return setIsPopupVisible(false); }}/>)}
200
202
  </SurveyContext.Provider>) : (<></>);
@@ -275,23 +277,6 @@ export function Questions(_a) {
275
277
  })}
276
278
  </form>);
277
279
  }
278
- var closeSurveyPopup = function (survey, posthog, isPreviewMode) {
279
- var _a;
280
- var _b;
281
- if (isPreviewMode || !posthog) {
282
- return;
283
- }
284
- posthog.capture('survey dismissed', {
285
- $survey_name: survey.name,
286
- $survey_id: survey.id,
287
- sessionRecordingUrl: (_b = posthog.get_session_replay_url) === null || _b === void 0 ? void 0 : _b.call(posthog),
288
- $set: (_a = {},
289
- _a["$survey_dismissed/".concat(survey.id)] = true,
290
- _a),
291
- });
292
- localStorage.setItem("seenSurvey_".concat(survey.id), 'true');
293
- window.dispatchEvent(new Event('PHSurveyClosed'));
294
- };
295
280
  export function FeedbackWidget(_a) {
296
281
  var _b, _c;
297
282
  var survey = _a.survey, forceDisableHtml = _a.forceDisableHtml, posthog = _a.posthog, readOnly = _a.readOnly;
@@ -1 +1 @@
1
- {"version":3,"file":"surveys.jsx","sourceRoot":"","sources":["../../../src/extensions/surveys.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAA4C,kBAAkB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAEnH,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EACH,KAAK,EACL,uBAAuB,EACvB,eAAe,EACf,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,wBAAwB,GAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAC9E,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Aa,CAAC,CAAC,UAAU,CAAC,EAAvC,CAAuC,CAAC,CACvD,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAEzE;oBAAA,CAAC,GAAG,CAAC,SAAS,CAAC,2BAA2B,CAAC,EAAE,GAAG,CAChD;oBAAA,CAAC,CAAA,MAAA,MAAM,CAAC,UAAU,0CAAE,WAAW,KAAI,EAAE,CACzC;gBAAA,EAAE,GAAG,CAAC,CACT,CACD;YAAA,CAAC,UAAU,IAAI,CACX,CAAC,WAAW,CACR,GAAG,CAAC,CAAC,wBAAwB,CAAC,CAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,MAAM,CAAC,CAAC,MAAM,CAAC,CACf,gBAAgB,CAAC,CAAC,gBAAgB,CAAC,CACnC,KAAK,CAAC,CAAC,cAAc,CAAC,EACxB,CACL,CACL;QAAA,GAAG,CACN,CAAA;AACL,CAAC","sourcesContent":["import { PostHog } from '../posthog-core'\nimport { Survey, SurveyAppearance, SurveyQuestion, SurveyQuestionType, SurveyType } from '../posthog-surveys-types'\n\nimport { window as _window, document as _document } from '../utils/globals'\nimport {\n style,\n defaultSurveyAppearance,\n sendSurveyEvent,\n createShadow,\n getContrastingTextColor,\n SurveyContext,\n getDisplayOrderQuestions,\n} from './surveys/surveys-utils'\nimport * as Preact from 'preact'\nimport { createWidgetShadow, createWidgetStyle } from './surveys-widget'\nimport { useState, useEffect, useRef, useContext, useMemo } from 'preact/hooks'\nimport { isNumber } from '../utils/type-utils'\nimport { ConfirmationMessage } from './surveys/components/ConfirmationMessage'\nimport {\n OpenTextQuestion,\n LinkQuestion,\n RatingQuestion,\n MultipleChoiceQuestion,\n} from './surveys/components/QuestionTypes'\n\n// We cast the types here which is dangerous but protected by the top level generateSurveys call\nconst window = _window as Window & typeof globalThis\nconst document = _document as Document\n\nconst handleWidget = (posthog: PostHog, survey: Survey) => {\n const shadow = createWidgetShadow(survey)\n const surveyStyleSheet = style(survey.appearance)\n shadow.appendChild(Object.assign(document.createElement('style'), { innerText: surveyStyleSheet }))\n Preact.render(<FeedbackWidget key={'feedback-survey'} posthog={posthog} survey={survey} />, shadow)\n}\n\nexport const callSurveys = (posthog: PostHog, forceReload: boolean = false) => {\n posthog?.getActiveMatchingSurveys((surveys) => {\n const nonAPISurveys = surveys.filter((survey) => survey.type !== 'api')\n nonAPISurveys.forEach((survey) => {\n if (survey.type === SurveyType.Widget) {\n if (\n survey.appearance?.widgetType === 'tab' &&\n document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0\n ) {\n handleWidget(posthog, survey)\n }\n if (survey.appearance?.widgetType === 'selector' && survey.appearance?.widgetSelector) {\n const selectorOnPage = document.querySelector(survey.appearance.widgetSelector)\n if (selectorOnPage) {\n if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0) {\n handleWidget(posthog, survey)\n } else if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 1) {\n // we have to check if user selector already has a survey listener attached to it because we always have to check if it's on the page or not\n if (!selectorOnPage.getAttribute('PHWidgetSurveyClickListener')) {\n const surveyPopup = document\n .querySelector(`.PostHogWidget${survey.id}`)\n ?.shadowRoot?.querySelector(`.survey-form`) as HTMLFormElement\n selectorOnPage.addEventListener('click', () => {\n if (surveyPopup) {\n surveyPopup.style.display =\n surveyPopup.style.display === 'none' ? 'block' : 'none'\n surveyPopup.addEventListener(\n 'PHSurveyClosed',\n () => (surveyPopup.style.display = 'none')\n )\n }\n })\n selectorOnPage.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }\n }\n }\n }\n // with event based surveys, we need to show the next survey without reloading the page.\n // A simple check for div elements with the class name pattern of PostHogSurvey_xyz doesn't work here\n // because preact leaves behind the div element for any surveys responded/dismissed with a <style> node.\n // To alleviate this, we check the last div in the dom and see if it has any elements other than a Style node.\n // if the last PostHogSurvey_xyz div has only one style node, we can show the next survey in the queue\n // without reloading the page.\n const surveyPopups = document.querySelectorAll(`div[class^=PostHogSurvey]`)\n const canShowSurvey =\n surveyPopups.length > 0\n ? surveyPopups[surveyPopups.length - 1].shadowRoot?.childElementCount === 1\n : true\n\n if (survey.type === SurveyType.Popover && canShowSurvey) {\n const surveyWaitPeriodInDays = survey.conditions?.seenSurveyWaitPeriodInDays\n const lastSeenSurveyDate = localStorage.getItem(`lastSeenSurveyDate`)\n if (surveyWaitPeriodInDays && lastSeenSurveyDate) {\n const today = new Date()\n const diff = Math.abs(today.getTime() - new Date(lastSeenSurveyDate).getTime())\n const diffDaysFromToday = Math.ceil(diff / (1000 * 3600 * 24))\n if (diffDaysFromToday < surveyWaitPeriodInDays) {\n return\n }\n }\n\n if (!localStorage.getItem(`seenSurvey_${survey.id}`)) {\n const shadow = createShadow(style(survey?.appearance), survey.id)\n Preact.render(<SurveyPopup key={'popover-survey'} posthog={posthog} survey={survey} />, shadow)\n }\n }\n })\n }, forceReload)\n}\n\nexport const renderSurveysPreview = ({\n survey,\n parentElement,\n previewPageIndex,\n forceDisableHtml,\n}: {\n survey: Survey\n parentElement: HTMLElement\n previewPageIndex: number\n forceDisableHtml?: boolean\n}) => {\n const surveyStyleSheet = style(survey.appearance)\n const styleElement = Object.assign(document.createElement('style'), { innerText: surveyStyleSheet })\n\n // Remove previously attached <style>\n Array.from(parentElement.children).forEach((child) => {\n if (child instanceof HTMLStyleElement) {\n parentElement.removeChild(child)\n }\n })\n\n parentElement.appendChild(styleElement)\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor || 'white'\n )\n\n Preact.render(\n <SurveyPopup\n key=\"surveys-render-preview\"\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={{\n position: 'relative',\n right: 0,\n borderBottom: `1px solid ${survey.appearance?.borderColor}`,\n borderRadius: 10,\n color: textColor,\n }}\n previewPageIndex={previewPageIndex}\n />,\n parentElement\n )\n}\nexport const renderFeedbackWidgetPreview = ({\n survey,\n root,\n forceDisableHtml,\n}: {\n survey: Survey\n root: HTMLElement\n forceDisableHtml?: boolean\n}) => {\n const widgetStyleSheet = createWidgetStyle(survey.appearance?.widgetColor)\n const styleElement = Object.assign(document.createElement('style'), { innerText: widgetStyleSheet })\n root.appendChild(styleElement)\n Preact.render(\n <FeedbackWidget\n key={'feedback-render-preview'}\n forceDisableHtml={forceDisableHtml}\n survey={survey}\n readOnly={true}\n />,\n root\n )\n}\n\n// This is the main exported function\nexport function generateSurveys(posthog: PostHog) {\n // NOTE: Important to ensure we never try and run surveys without a window environment\n if (!document || !window) {\n return\n }\n callSurveys(posthog, true)\n\n // recalculate surveys every 3 seconds to check if URL or selectors have changed\n setInterval(() => {\n callSurveys(posthog, false)\n }, 3000)\n}\n\nexport function SurveyPopup({\n survey,\n forceDisableHtml,\n posthog,\n style,\n previewPageIndex,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n style?: React.CSSProperties\n previewPageIndex?: number | undefined\n}) {\n const [isPopupVisible, setIsPopupVisible] = useState(true)\n const [isSurveySent, setIsSurveySent] = useState(false)\n const shouldShowConfirmation = isSurveySent || previewPageIndex === survey.questions.length\n const isPreviewMode = Number.isInteger(previewPageIndex)\n const confirmationBoxLeftStyle = style?.left && isNumber(style?.left) ? { left: style.left - 40 } : {}\n\n // Ensure the popup stays in the same position for the preview\n if (isPreviewMode) {\n style = style || {}\n style.left = 'unset'\n style.right = 'unset'\n style.transform = 'unset'\n }\n\n useEffect(() => {\n if (isPreviewMode || !posthog) {\n return\n }\n\n window.dispatchEvent(new Event('PHSurveyShown'))\n posthog.capture('survey shown', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n })\n localStorage.setItem(`lastSeenSurveyDate`, new Date().toISOString())\n\n window.addEventListener('PHSurveyClosed', () => {\n setIsPopupVisible(false)\n })\n window.addEventListener('PHSurveySent', () => {\n if (!survey.appearance?.displayThankYouMessage) {\n return setIsPopupVisible(false)\n }\n\n setIsSurveySent(true)\n\n if (survey.appearance?.autoDisappear) {\n setTimeout(() => {\n setIsPopupVisible(false)\n }, 5000)\n }\n })\n }, [])\n\n return isPopupVisible ? (\n <SurveyContext.Provider\n value={{\n isPreviewMode,\n previewPageIndex: previewPageIndex,\n handleCloseSurveyPopup: () => closeSurveyPopup(survey, posthog, isPreviewMode),\n }}\n >\n {!shouldShowConfirmation ? (\n <Questions\n survey={survey}\n forceDisableHtml={!!forceDisableHtml}\n posthog={posthog}\n styleOverrides={style}\n />\n ) : (\n <ConfirmationMessage\n header={survey.appearance?.thankYouMessageHeader || 'Thank you!'}\n description={survey.appearance?.thankYouMessageDescription || ''}\n forceDisableHtml={!!forceDisableHtml}\n contentType={survey.appearance?.thankYouMessageDescriptionContentType}\n appearance={survey.appearance || defaultSurveyAppearance}\n styleOverrides={{ ...style, ...confirmationBoxLeftStyle }}\n onClose={() => setIsPopupVisible(false)}\n />\n )}\n </SurveyContext.Provider>\n ) : (\n <></>\n )\n}\n\ninterface GetQuestionComponentProps {\n question: SurveyQuestion\n forceDisableHtml: boolean\n displayQuestionIndex: number\n appearance: SurveyAppearance\n onSubmit: (res: string | string[] | number | null) => void\n}\n\nconst getQuestionComponent = ({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance,\n onSubmit,\n}: GetQuestionComponentProps): JSX.Element => {\n const questionComponents = {\n [SurveyQuestionType.Open]: OpenTextQuestion,\n [SurveyQuestionType.Link]: LinkQuestion,\n [SurveyQuestionType.Rating]: RatingQuestion,\n [SurveyQuestionType.SingleChoice]: MultipleChoiceQuestion,\n [SurveyQuestionType.MultipleChoice]: MultipleChoiceQuestion,\n }\n\n const commonProps = {\n question,\n forceDisableHtml,\n appearance,\n onSubmit,\n }\n\n const additionalProps: Record<SurveyQuestionType, any> = {\n [SurveyQuestionType.Open]: {},\n [SurveyQuestionType.Link]: {},\n [SurveyQuestionType.Rating]: { displayQuestionIndex },\n [SurveyQuestionType.SingleChoice]: { displayQuestionIndex },\n [SurveyQuestionType.MultipleChoice]: { displayQuestionIndex },\n }\n\n const Component = questionComponents[question.type]\n const componentProps = { ...commonProps, ...additionalProps[question.type] }\n\n return <Component {...componentProps} />\n}\n\nexport function Questions({\n survey,\n forceDisableHtml,\n posthog,\n styleOverrides,\n}: {\n survey: Survey\n forceDisableHtml: boolean\n posthog?: PostHog\n styleOverrides?: React.CSSProperties\n}) {\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor\n )\n const [questionsResponses, setQuestionsResponses] = useState({})\n const { isPreviewMode, previewPageIndex } = useContext(SurveyContext)\n const [currentQuestionIndex, setCurrentQuestionIndex] = useState(previewPageIndex || 0)\n const surveyQuestions = useMemo(() => getDisplayOrderQuestions(survey), [survey])\n\n // Sync preview state\n useEffect(() => {\n setCurrentQuestionIndex(previewPageIndex ?? 0)\n }, [previewPageIndex])\n\n const onNextButtonClick = ({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }: {\n res: string | string[] | number | null\n originalQuestionIndex: number\n displayQuestionIndex: number\n }) => {\n const isLastDisplayedQuestion = displayQuestionIndex === survey.questions.length - 1\n\n const responseKey =\n originalQuestionIndex === 0 ? `$survey_response` : `$survey_response_${originalQuestionIndex}`\n\n if (isLastDisplayedQuestion) {\n return sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)\n } else {\n setQuestionsResponses({ ...questionsResponses, [responseKey]: res })\n setCurrentQuestionIndex(displayQuestionIndex + 1)\n }\n }\n\n return (\n <form\n className=\"survey-form\"\n style={{\n color: textColor,\n borderColor: survey.appearance?.borderColor,\n ...styleOverrides,\n }}\n >\n {surveyQuestions.map((question, displayQuestionIndex) => {\n const { originalQuestionIndex } = question\n\n const isVisible = isPreviewMode\n ? currentQuestionIndex === originalQuestionIndex\n : currentQuestionIndex === displayQuestionIndex\n return (\n isVisible && (\n <div>\n {getQuestionComponent({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance: survey.appearance || defaultSurveyAppearance,\n onSubmit: (res) =>\n onNextButtonClick({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }),\n })}\n </div>\n )\n )\n })}\n </form>\n )\n}\n\nconst closeSurveyPopup = (survey: Survey, posthog?: PostHog, isPreviewMode?: boolean) => {\n if (isPreviewMode || !posthog) {\n return\n }\n\n posthog.capture('survey dismissed', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n $set: {\n [`$survey_dismissed/${survey.id}`]: true,\n },\n })\n localStorage.setItem(`seenSurvey_${survey.id}`, 'true')\n window.dispatchEvent(new Event('PHSurveyClosed'))\n}\n\nexport function FeedbackWidget({\n survey,\n forceDisableHtml,\n posthog,\n readOnly,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n readOnly?: boolean\n}): JSX.Element {\n const [showSurvey, setShowSurvey] = useState(false)\n const [styleOverrides, setStyle] = useState({})\n const widgetRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n if (readOnly || !posthog) {\n return\n }\n\n if (survey.appearance?.widgetType === 'tab') {\n if (widgetRef.current) {\n const widgetPos = widgetRef.current.getBoundingClientRect()\n const style = {\n top: '50%',\n left: parseInt(`${widgetPos.right - 360}`),\n bottom: 'auto',\n borderRadius: 10,\n borderBottom: `1.5px solid ${survey.appearance?.borderColor || '#c9c6c6'}`,\n }\n setStyle(style)\n }\n }\n if (survey.appearance?.widgetType === 'selector') {\n const widget = document.querySelector(survey.appearance.widgetSelector || '')\n widget?.addEventListener('click', () => {\n setShowSurvey(!showSurvey)\n })\n widget?.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }, [])\n\n return (\n <>\n {survey.appearance?.widgetType === 'tab' && (\n <div\n className=\"ph-survey-widget-tab\"\n ref={widgetRef}\n onClick={() => !readOnly && setShowSurvey(!showSurvey)}\n style={{ color: getContrastingTextColor(survey.appearance.widgetColor) }}\n >\n <div className=\"ph-survey-widget-tab-icon\"></div>\n {survey.appearance?.widgetLabel || ''}\n </div>\n )}\n {showSurvey && (\n <SurveyPopup\n key={'feedback-widget-survey'}\n posthog={posthog}\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={styleOverrides}\n />\n )}\n </>\n )\n}\n"]}
1
+ {"version":3,"file":"surveys.jsx","sourceRoot":"","sources":["../../../src/extensions/surveys.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAA4C,kBAAkB,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAEnH,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EACH,KAAK,EACL,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,wBAAwB,EACxB,gBAAgB,GACnB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAC9E,OAAO,EACH,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,sBAAsB,GACzB,MAAM,oCAAoC,CAAA;AAE3C,gGAAgG;AAChG,IAAM,MAAM,GAAG,OAAqC,CAAA;AACpD,IAAM,QAAQ,GAAG,SAAqB,CAAA;AAEtC,IAAM,YAAY,GAAG,UAAC,OAAgB,EAAE,MAAc;IAClD,IAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACzC,IAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,UAA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AAC,UAAU,CAAC,CAAA;YAC9B,CAAC,CAAC,CAAA;YACF,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,YAAY,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAA;SAC9D;IACL,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACH,EACI;YAAA,CAAC,CAAA,MAAA,MAAM,CAAC,UAAU,0CAAE,UAAU,MAAK,KAAK,IAAI,CACxC,CAAC,GAAG,CACA,SAAS,CAAC,sBAAsB,CAChC,GAAG,CAAC,CAAC,SAAS,CAAC,CACf,OAAO,CAAC,CAAC,cAAM,OAAA,CAAC,QAAQ,IAAI,aAAa,CAAC,CAAC,UAAU,CAAC,EAAvC,CAAuC,CAAC,CACvD,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC,CAEzE;oBAAA,CAAC,GAAG,CAAC,SAAS,CAAC,2BAA2B,CAAC,EAAE,GAAG,CAChD;oBAAA,CAAC,CAAA,MAAA,MAAM,CAAC,UAAU,0CAAE,WAAW,KAAI,EAAE,CACzC;gBAAA,EAAE,GAAG,CAAC,CACT,CACD;YAAA,CAAC,UAAU,IAAI,CACX,CAAC,WAAW,CACR,GAAG,CAAC,CAAC,wBAAwB,CAAC,CAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,CACjB,MAAM,CAAC,CAAC,MAAM,CAAC,CACf,gBAAgB,CAAC,CAAC,gBAAgB,CAAC,CACnC,KAAK,CAAC,CAAC,cAAc,CAAC,EACxB,CACL,CACL;QAAA,GAAG,CACN,CAAA;AACL,CAAC","sourcesContent":["import { PostHog } from '../posthog-core'\nimport { Survey, SurveyAppearance, SurveyQuestion, SurveyQuestionType, SurveyType } from '../posthog-surveys-types'\n\nimport { window as _window, document as _document } from '../utils/globals'\nimport {\n style,\n defaultSurveyAppearance,\n sendSurveyEvent,\n dismissedSurveyEvent,\n createShadow,\n getContrastingTextColor,\n SurveyContext,\n getDisplayOrderQuestions,\n getSurveySeenKey,\n} from './surveys/surveys-utils'\nimport * as Preact from 'preact'\nimport { createWidgetShadow, createWidgetStyle } from './surveys-widget'\nimport { useState, useEffect, useRef, useContext, useMemo } from 'preact/hooks'\nimport { isNumber } from '../utils/type-utils'\nimport { ConfirmationMessage } from './surveys/components/ConfirmationMessage'\nimport {\n OpenTextQuestion,\n LinkQuestion,\n RatingQuestion,\n MultipleChoiceQuestion,\n} from './surveys/components/QuestionTypes'\n\n// We cast the types here which is dangerous but protected by the top level generateSurveys call\nconst window = _window as Window & typeof globalThis\nconst document = _document as Document\n\nconst handleWidget = (posthog: PostHog, survey: Survey) => {\n const shadow = createWidgetShadow(survey)\n const surveyStyleSheet = style(survey.appearance)\n shadow.appendChild(Object.assign(document.createElement('style'), { innerText: surveyStyleSheet }))\n Preact.render(<FeedbackWidget key={'feedback-survey'} posthog={posthog} survey={survey} />, shadow)\n}\n\nexport const callSurveys = (posthog: PostHog, forceReload: boolean = false) => {\n posthog?.getActiveMatchingSurveys((surveys) => {\n const nonAPISurveys = surveys.filter((survey) => survey.type !== 'api')\n nonAPISurveys.forEach((survey) => {\n if (survey.type === SurveyType.Widget) {\n if (\n survey.appearance?.widgetType === 'tab' &&\n document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0\n ) {\n handleWidget(posthog, survey)\n }\n if (survey.appearance?.widgetType === 'selector' && survey.appearance?.widgetSelector) {\n const selectorOnPage = document.querySelector(survey.appearance.widgetSelector)\n if (selectorOnPage) {\n if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0) {\n handleWidget(posthog, survey)\n } else if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 1) {\n // we have to check if user selector already has a survey listener attached to it because we always have to check if it's on the page or not\n if (!selectorOnPage.getAttribute('PHWidgetSurveyClickListener')) {\n const surveyPopup = document\n .querySelector(`.PostHogWidget${survey.id}`)\n ?.shadowRoot?.querySelector(`.survey-form`) as HTMLFormElement\n selectorOnPage.addEventListener('click', () => {\n if (surveyPopup) {\n surveyPopup.style.display =\n surveyPopup.style.display === 'none' ? 'block' : 'none'\n surveyPopup.addEventListener(\n 'PHSurveyClosed',\n () => (surveyPopup.style.display = 'none')\n )\n }\n })\n selectorOnPage.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }\n }\n }\n }\n // with event based surveys, we need to show the next survey without reloading the page.\n // A simple check for div elements with the class name pattern of PostHogSurvey_xyz doesn't work here\n // because preact leaves behind the div element for any surveys responded/dismissed with a <style> node.\n // To alleviate this, we check the last div in the dom and see if it has any elements other than a Style node.\n // if the last PostHogSurvey_xyz div has only one style node, we can show the next survey in the queue\n // without reloading the page.\n const surveyPopups = document.querySelectorAll(`div[class^=PostHogSurvey]`)\n const canShowSurvey =\n surveyPopups.length > 0\n ? surveyPopups[surveyPopups.length - 1].shadowRoot?.childElementCount === 1\n : true\n\n if (survey.type === SurveyType.Popover && canShowSurvey) {\n const surveyWaitPeriodInDays = survey.conditions?.seenSurveyWaitPeriodInDays\n const lastSeenSurveyDate = localStorage.getItem(`lastSeenSurveyDate`)\n if (surveyWaitPeriodInDays && lastSeenSurveyDate) {\n const today = new Date()\n const diff = Math.abs(today.getTime() - new Date(lastSeenSurveyDate).getTime())\n const diffDaysFromToday = Math.ceil(diff / (1000 * 3600 * 24))\n if (diffDaysFromToday < surveyWaitPeriodInDays) {\n return\n }\n }\n\n if (!localStorage.getItem(getSurveySeenKey(survey))) {\n const shadow = createShadow(style(survey?.appearance), survey.id)\n Preact.render(<SurveyPopup key={'popover-survey'} posthog={posthog} survey={survey} />, shadow)\n }\n }\n })\n }, forceReload)\n}\n\nexport const renderSurveysPreview = ({\n survey,\n parentElement,\n previewPageIndex,\n forceDisableHtml,\n}: {\n survey: Survey\n parentElement: HTMLElement\n previewPageIndex: number\n forceDisableHtml?: boolean\n}) => {\n const surveyStyleSheet = style(survey.appearance)\n const styleElement = Object.assign(document.createElement('style'), { innerText: surveyStyleSheet })\n\n // Remove previously attached <style>\n Array.from(parentElement.children).forEach((child) => {\n if (child instanceof HTMLStyleElement) {\n parentElement.removeChild(child)\n }\n })\n\n parentElement.appendChild(styleElement)\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor || 'white'\n )\n\n Preact.render(\n <SurveyPopup\n key=\"surveys-render-preview\"\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={{\n position: 'relative',\n right: 0,\n borderBottom: `1px solid ${survey.appearance?.borderColor}`,\n borderRadius: 10,\n color: textColor,\n }}\n previewPageIndex={previewPageIndex}\n />,\n parentElement\n )\n}\nexport const renderFeedbackWidgetPreview = ({\n survey,\n root,\n forceDisableHtml,\n}: {\n survey: Survey\n root: HTMLElement\n forceDisableHtml?: boolean\n}) => {\n const widgetStyleSheet = createWidgetStyle(survey.appearance?.widgetColor)\n const styleElement = Object.assign(document.createElement('style'), { innerText: widgetStyleSheet })\n root.appendChild(styleElement)\n Preact.render(\n <FeedbackWidget\n key={'feedback-render-preview'}\n forceDisableHtml={forceDisableHtml}\n survey={survey}\n readOnly={true}\n />,\n root\n )\n}\n\n// This is the main exported function\nexport function generateSurveys(posthog: PostHog) {\n // NOTE: Important to ensure we never try and run surveys without a window environment\n if (!document || !window) {\n return\n }\n callSurveys(posthog, true)\n\n // recalculate surveys every 3 seconds to check if URL or selectors have changed\n setInterval(() => {\n callSurveys(posthog, false)\n }, 3000)\n}\n\nexport function SurveyPopup({\n survey,\n forceDisableHtml,\n posthog,\n style,\n previewPageIndex,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n style?: React.CSSProperties\n previewPageIndex?: number | undefined\n}) {\n const [isPopupVisible, setIsPopupVisible] = useState(true)\n const [isSurveySent, setIsSurveySent] = useState(false)\n const shouldShowConfirmation = isSurveySent || previewPageIndex === survey.questions.length\n const isPreviewMode = Number.isInteger(previewPageIndex)\n const confirmationBoxLeftStyle = style?.left && isNumber(style?.left) ? { left: style.left - 40 } : {}\n\n // Ensure the popup stays in the same position for the preview\n if (isPreviewMode) {\n style = style || {}\n style.left = 'unset'\n style.right = 'unset'\n style.transform = 'unset'\n }\n\n useEffect(() => {\n if (isPreviewMode || !posthog) {\n return\n }\n\n window.dispatchEvent(new Event('PHSurveyShown'))\n posthog.capture('survey shown', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n $survey_iteration: survey.current_iteration,\n $survey_iteration_start_date: survey.current_iteration_start_date,\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n })\n localStorage.setItem(`lastSeenSurveyDate`, new Date().toISOString())\n\n window.addEventListener('PHSurveyClosed', () => {\n setIsPopupVisible(false)\n })\n window.addEventListener('PHSurveySent', () => {\n if (!survey.appearance?.displayThankYouMessage) {\n return setIsPopupVisible(false)\n }\n\n setIsSurveySent(true)\n\n if (survey.appearance?.autoDisappear) {\n setTimeout(() => {\n setIsPopupVisible(false)\n }, 5000)\n }\n })\n }, [])\n\n return isPopupVisible ? (\n <SurveyContext.Provider\n value={{\n isPreviewMode,\n previewPageIndex: previewPageIndex,\n handleCloseSurveyPopup: () => dismissedSurveyEvent(survey, posthog, isPreviewMode),\n }}\n >\n {!shouldShowConfirmation ? (\n <Questions\n survey={survey}\n forceDisableHtml={!!forceDisableHtml}\n posthog={posthog}\n styleOverrides={style}\n />\n ) : (\n <ConfirmationMessage\n header={survey.appearance?.thankYouMessageHeader || 'Thank you!'}\n description={survey.appearance?.thankYouMessageDescription || ''}\n forceDisableHtml={!!forceDisableHtml}\n contentType={survey.appearance?.thankYouMessageDescriptionContentType}\n appearance={survey.appearance || defaultSurveyAppearance}\n styleOverrides={{ ...style, ...confirmationBoxLeftStyle }}\n onClose={() => setIsPopupVisible(false)}\n />\n )}\n </SurveyContext.Provider>\n ) : (\n <></>\n )\n}\n\ninterface GetQuestionComponentProps {\n question: SurveyQuestion\n forceDisableHtml: boolean\n displayQuestionIndex: number\n appearance: SurveyAppearance\n onSubmit: (res: string | string[] | number | null) => void\n}\n\nconst getQuestionComponent = ({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance,\n onSubmit,\n}: GetQuestionComponentProps): JSX.Element => {\n const questionComponents = {\n [SurveyQuestionType.Open]: OpenTextQuestion,\n [SurveyQuestionType.Link]: LinkQuestion,\n [SurveyQuestionType.Rating]: RatingQuestion,\n [SurveyQuestionType.SingleChoice]: MultipleChoiceQuestion,\n [SurveyQuestionType.MultipleChoice]: MultipleChoiceQuestion,\n }\n\n const commonProps = {\n question,\n forceDisableHtml,\n appearance,\n onSubmit,\n }\n\n const additionalProps: Record<SurveyQuestionType, any> = {\n [SurveyQuestionType.Open]: {},\n [SurveyQuestionType.Link]: {},\n [SurveyQuestionType.Rating]: { displayQuestionIndex },\n [SurveyQuestionType.SingleChoice]: { displayQuestionIndex },\n [SurveyQuestionType.MultipleChoice]: { displayQuestionIndex },\n }\n\n const Component = questionComponents[question.type]\n const componentProps = { ...commonProps, ...additionalProps[question.type] }\n\n return <Component {...componentProps} />\n}\n\nexport function Questions({\n survey,\n forceDisableHtml,\n posthog,\n styleOverrides,\n}: {\n survey: Survey\n forceDisableHtml: boolean\n posthog?: PostHog\n styleOverrides?: React.CSSProperties\n}) {\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor\n )\n const [questionsResponses, setQuestionsResponses] = useState({})\n const { isPreviewMode, previewPageIndex } = useContext(SurveyContext)\n const [currentQuestionIndex, setCurrentQuestionIndex] = useState(previewPageIndex || 0)\n const surveyQuestions = useMemo(() => getDisplayOrderQuestions(survey), [survey])\n\n // Sync preview state\n useEffect(() => {\n setCurrentQuestionIndex(previewPageIndex ?? 0)\n }, [previewPageIndex])\n\n const onNextButtonClick = ({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }: {\n res: string | string[] | number | null\n originalQuestionIndex: number\n displayQuestionIndex: number\n }) => {\n const isLastDisplayedQuestion = displayQuestionIndex === survey.questions.length - 1\n\n const responseKey =\n originalQuestionIndex === 0 ? `$survey_response` : `$survey_response_${originalQuestionIndex}`\n\n if (isLastDisplayedQuestion) {\n return sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)\n } else {\n setQuestionsResponses({ ...questionsResponses, [responseKey]: res })\n setCurrentQuestionIndex(displayQuestionIndex + 1)\n }\n }\n\n return (\n <form\n className=\"survey-form\"\n style={{\n color: textColor,\n borderColor: survey.appearance?.borderColor,\n ...styleOverrides,\n }}\n >\n {surveyQuestions.map((question, displayQuestionIndex) => {\n const { originalQuestionIndex } = question\n\n const isVisible = isPreviewMode\n ? currentQuestionIndex === originalQuestionIndex\n : currentQuestionIndex === displayQuestionIndex\n return (\n isVisible && (\n <div>\n {getQuestionComponent({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance: survey.appearance || defaultSurveyAppearance,\n onSubmit: (res) =>\n onNextButtonClick({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }),\n })}\n </div>\n )\n )\n })}\n </form>\n )\n}\n\nexport function FeedbackWidget({\n survey,\n forceDisableHtml,\n posthog,\n readOnly,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n readOnly?: boolean\n}): JSX.Element {\n const [showSurvey, setShowSurvey] = useState(false)\n const [styleOverrides, setStyle] = useState({})\n const widgetRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n if (readOnly || !posthog) {\n return\n }\n\n if (survey.appearance?.widgetType === 'tab') {\n if (widgetRef.current) {\n const widgetPos = widgetRef.current.getBoundingClientRect()\n const style = {\n top: '50%',\n left: parseInt(`${widgetPos.right - 360}`),\n bottom: 'auto',\n borderRadius: 10,\n borderBottom: `1.5px solid ${survey.appearance?.borderColor || '#c9c6c6'}`,\n }\n setStyle(style)\n }\n }\n if (survey.appearance?.widgetType === 'selector') {\n const widget = document.querySelector(survey.appearance.widgetSelector || '')\n widget?.addEventListener('click', () => {\n setShowSurvey(!showSurvey)\n })\n widget?.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }, [])\n\n return (\n <>\n {survey.appearance?.widgetType === 'tab' && (\n <div\n className=\"ph-survey-widget-tab\"\n ref={widgetRef}\n onClick={() => !readOnly && setShowSurvey(!showSurvey)}\n style={{ color: getContrastingTextColor(survey.appearance.widgetColor) }}\n >\n <div className=\"ph-survey-widget-tab-icon\"></div>\n {survey.appearance?.widgetLabel || ''}\n </div>\n )}\n {showSurvey && (\n <SurveyPopup\n key={'feedback-widget-survey'}\n posthog={posthog}\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={styleOverrides}\n />\n )}\n </>\n )\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { PostHog } from '../posthog-core';
2
+ export declare class TracingHeaders {
3
+ private readonly instance;
4
+ private _restoreXHRPatch;
5
+ private _restoreFetchPatch;
6
+ constructor(instance: PostHog);
7
+ private _loadScript;
8
+ startIfEnabledOrStop(): void;
9
+ private _startCapturing;
10
+ }
@@ -0,0 +1,51 @@
1
+ import { assignableWindow } from '../utils/globals';
2
+ import { logger } from '../utils/logger';
3
+ import { loadScript } from '../utils';
4
+ import Config from '../config';
5
+ import { isUndefined } from '../utils/type-utils';
6
+ var LOGGER_PREFIX = '[TRACING-HEADERS]';
7
+ var TracingHeaders = /** @class */ (function () {
8
+ function TracingHeaders(instance) {
9
+ var _this = this;
10
+ this.instance = instance;
11
+ this._restoreXHRPatch = undefined;
12
+ this._restoreFetchPatch = undefined;
13
+ this._startCapturing = function () {
14
+ // NB: we can assert sessionManager is present only because we've checked previously
15
+ if (isUndefined(_this._restoreXHRPatch)) {
16
+ assignableWindow.postHogTracingHeadersPatchFns._patchXHR(_this.instance.sessionManager);
17
+ }
18
+ if (isUndefined(_this._restoreFetchPatch)) {
19
+ assignableWindow.postHogTracingHeadersPatchFns._patchFetch(_this.instance.sessionManager);
20
+ }
21
+ };
22
+ }
23
+ TracingHeaders.prototype._loadScript = function (cb) {
24
+ if (assignableWindow.postHogTracingHeadersPatchFns) {
25
+ // already loaded
26
+ cb();
27
+ }
28
+ loadScript(this.instance.requestRouter.endpointFor('assets', "/static/tracing-headers.js?v=".concat(Config.LIB_VERSION)), function (err) {
29
+ if (err) {
30
+ logger.error(LOGGER_PREFIX + ' failed to load script', err);
31
+ }
32
+ cb();
33
+ });
34
+ };
35
+ TracingHeaders.prototype.startIfEnabledOrStop = function () {
36
+ var _a, _b;
37
+ if (this.instance.config.__add_tracing_headers) {
38
+ this._loadScript(this._startCapturing);
39
+ }
40
+ else {
41
+ (_a = this._restoreXHRPatch) === null || _a === void 0 ? void 0 : _a.call(this);
42
+ (_b = this._restoreFetchPatch) === null || _b === void 0 ? void 0 : _b.call(this);
43
+ // we don't want to call these twice so we reset them
44
+ this._restoreXHRPatch = undefined;
45
+ this._restoreFetchPatch = undefined;
46
+ }
47
+ };
48
+ return TracingHeaders;
49
+ }());
50
+ export { TracingHeaders };
51
+ //# sourceMappingURL=tracing-headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-headers.js","sourceRoot":"","sources":["../../../src/extensions/tracing-headers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,IAAM,aAAa,GAAG,mBAAmB,CAAA;AAEzC;IAII,wBAA6B,QAAiB;QAA9C,iBAAkD;QAArB,aAAQ,GAAR,QAAQ,CAAS;QAHtC,qBAAgB,GAA6B,SAAS,CAAA;QACtD,uBAAkB,GAA6B,SAAS,CAAA;QAgCxD,oBAAe,GAAG;YACtB,oFAAoF;YACpF,IAAI,WAAW,CAAC,KAAI,CAAC,gBAAgB,CAAC,EAAE;gBACpC,gBAAgB,CAAC,6BAA6B,CAAC,SAAS,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAe,CAAC,CAAA;aAC1F;YACD,IAAI,WAAW,CAAC,KAAI,CAAC,kBAAkB,CAAC,EAAE;gBACtC,gBAAgB,CAAC,6BAA6B,CAAC,WAAW,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAe,CAAC,CAAA;aAC5F;QACL,CAAC,CAAA;IAtCgD,CAAC;IAE1C,oCAAW,GAAnB,UAAoB,EAAc;QAC9B,IAAI,gBAAgB,CAAC,6BAA6B,EAAE;YAChD,iBAAiB;YACjB,EAAE,EAAE,CAAA;SACP;QAED,UAAU,CACN,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,WAAW,CAAC,QAAQ,EAAE,uCAAgC,MAAM,CAAC,WAAW,CAAE,CAAC,EACvG,UAAC,GAAG;YACA,IAAI,GAAG,EAAE;gBACL,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,wBAAwB,EAAE,GAAG,CAAC,CAAA;aAC9D;YACD,EAAE,EAAE,CAAA;QACR,CAAC,CACJ,CAAA;IACL,CAAC;IACM,6CAAoB,GAA3B;;QACI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,EAAE;YAC5C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;SACzC;aAAM;YACH,MAAA,IAAI,CAAC,gBAAgB,oDAAI,CAAA;YACzB,MAAA,IAAI,CAAC,kBAAkB,oDAAI,CAAA;YAC3B,qDAAqD;YACrD,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAA;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;SACtC;IACL,CAAC;IAWL,qBAAC;AAAD,CAAC,AA3CD,IA2CC","sourcesContent":["import { PostHog } from '../posthog-core'\nimport { assignableWindow } from '../utils/globals'\nimport { logger } from '../utils/logger'\nimport { loadScript } from '../utils'\nimport Config from '../config'\nimport { isUndefined } from '../utils/type-utils'\n\nconst LOGGER_PREFIX = '[TRACING-HEADERS]'\n\nexport class TracingHeaders {\n private _restoreXHRPatch: (() => void) | undefined = undefined\n private _restoreFetchPatch: (() => void) | undefined = undefined\n\n constructor(private readonly instance: PostHog) {}\n\n private _loadScript(cb: () => void): void {\n if (assignableWindow.postHogTracingHeadersPatchFns) {\n // already loaded\n cb()\n }\n\n loadScript(\n this.instance.requestRouter.endpointFor('assets', `/static/tracing-headers.js?v=${Config.LIB_VERSION}`),\n (err) => {\n if (err) {\n logger.error(LOGGER_PREFIX + ' failed to load script', err)\n }\n cb()\n }\n )\n }\n public startIfEnabledOrStop() {\n if (this.instance.config.__add_tracing_headers) {\n this._loadScript(this._startCapturing)\n } else {\n this._restoreXHRPatch?.()\n this._restoreFetchPatch?.()\n // we don't want to call these twice so we reset them\n this._restoreXHRPatch = undefined\n this._restoreFetchPatch = undefined\n }\n }\n\n private _startCapturing = () => {\n // NB: we can assert sessionManager is present only because we've checked previously\n if (isUndefined(this._restoreXHRPatch)) {\n assignableWindow.postHogTracingHeadersPatchFns._patchXHR(this.instance.sessionManager!)\n }\n if (isUndefined(this._restoreFetchPatch)) {\n assignableWindow.postHogTracingHeadersPatchFns._patchFetch(this.instance.sessionManager!)\n }\n }\n}\n"]}
@@ -5,9 +5,6 @@ export type NetworkData = {
5
5
  requests: CapturedNetworkRequest[];
6
6
  isInitial?: boolean;
7
7
  };
8
- export declare function patch(source: {
9
- [key: string]: any;
10
- }, name: string, replacement: (...args: unknown[]) => unknown): () => void;
11
8
  export declare function findLast<T>(array: Array<T>, predicate: (value: T) => boolean): T | undefined;
12
9
  export declare const NETWORK_PLUGIN_NAME = "rrweb/network@1";
13
10
  export declare const getRecordNetworkPlugin: (options?: NetworkRecordOptions) => RecordPlugin;
@@ -64,56 +64,16 @@ import rrwebRecord from 'rrweb/es/rrweb/packages/rrweb/src/record';
64
64
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
65
  // @ts-ignore
66
66
  import { getRecordConsolePlugin } from 'rrweb/es/rrweb/packages/rrweb/src/plugins/console/record';
67
- import { isArray, isBoolean, isDocument, isFormData, isFunction, isNull, isNullish, isObject, isString, isUndefined, } from './utils/type-utils';
67
+ import { isArray, isBoolean, isDocument, isFormData, isNull, isNullish, isObject, isString, isUndefined, } from './utils/type-utils';
68
68
  import { logger } from './utils/logger';
69
69
  import { window } from './utils/globals';
70
70
  import { defaultNetworkOptions } from './extensions/replay/config';
71
71
  import { formDataToQuery } from './utils/request-utils';
72
+ import { patch } from './extensions/replay/rrweb-plugins/patch';
72
73
  var isNavigationTiming = function (entry) {
73
74
  return entry.entryType === 'navigation';
74
75
  };
75
76
  var isResourceTiming = function (entry) { return entry.entryType === 'resource'; };
76
- // import { patch } from 'rrweb/typings/utils'
77
- // copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129
78
- // which was copied from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts
79
- export function patch(source, name, replacement) {
80
- try {
81
- if (!(name in source)) {
82
- return function () {
83
- //
84
- };
85
- }
86
- var original_1 = source[name];
87
- var wrapped = replacement(original_1);
88
- // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
89
- // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
90
- if (isFunction(wrapped)) {
91
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
92
- wrapped.prototype = wrapped.prototype || {};
93
- Object.defineProperties(wrapped, {
94
- __rrweb_original__: {
95
- enumerable: false,
96
- value: original_1,
97
- },
98
- __posthog_wrapped__: {
99
- enumerable: false,
100
- value: true,
101
- },
102
- });
103
- }
104
- source[name] = wrapped;
105
- return function () {
106
- source[name] = original_1;
107
- };
108
- }
109
- catch (_a) {
110
- return function () {
111
- //
112
- };
113
- // This can throw if multiple fill happens on a global object like XMLHttpRequest
114
- // Fixes https://github.com/getsentry/sentry-javascript/issues/2043
115
- }
116
- }
117
77
  export function findLast(array, predicate) {
118
78
  var length = array.length;
119
79
  for (var i = length - 1; i >= 0; i -= 1) {
@@ -1 +1 @@
1
- {"version":3,"file":"loader-recorder.js","sourceRoot":"","sources":["../../src/loader-recorder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,4DAA4D;AAC5D,6DAA6D;AAC7D,aAAa;AACb,OAAO,WAAW,MAAM,0CAA0C,CAAA;AAClE,6DAA6D;AAC7D,aAAa;AACb,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAA;AAYjG,OAAO,EACH,OAAO,EACP,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,WAAW,GACd,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AASvD,IAAM,kBAAkB,GAAG,UAAC,KAAuB;IAC/C,OAAA,KAAK,CAAC,SAAS,KAAK,YAAY;AAAhC,CAAgC,CAAA;AACpC,IAAM,gBAAgB,GAAG,UAAC,KAAuB,IAAyC,OAAA,KAAK,CAAC,SAAS,KAAK,UAAU,EAA9B,CAA8B,CAAA;AAMxH,8CAA8C;AAC9C,+HAA+H;AAC/H,kJAAkJ;AAClJ,MAAM,UAAU,KAAK,CACjB,MAA8B,EAC9B,IAAY,EACZ,WAA4C;IAE5C,IAAI;QACA,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE;YACnB,OAAO;gBACH,EAAE;YACN,CAAC,CAAA;SACJ;QAED,IAAM,UAAQ,GAAG,MAAM,CAAC,IAAI,C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AC;IAAC,MAAc,CAAC,KAAK,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CACrF;IAAC,MAAc,CAAC,kBAAkB,GAAG,EAAE,sBAAsB,wBAAA,EAAE,CAC/D;IAAC,MAAc,CAAC,sBAAsB,GAAG,sBAAsB,CAAA;CACnE;AAED,eAAe,WAAW,CAAA","sourcesContent":["import { version } from 'rrweb/package.json'\n\n// Same as loader-globals.ts except includes rrweb2 scripts.\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport rrwebRecord from 'rrweb/es/rrweb/packages/rrweb/src/record'\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { getRecordConsolePlugin } from 'rrweb/es/rrweb/packages/rrweb/src/plugins/console/record'\n\n// rrweb/network@1 code starts\n// most of what is below here will be removed when rrweb release their code for this\n// see https://github.com/rrweb-io/rrweb/pull/1105\n/// <reference lib=\"dom\" />\n// NB adopted from https://github.com/rrweb-io/rrweb/pull/1105 which looks like it will be accepted into rrweb\n// however, in the PR, it throws when the performance observer data is not available\n// and assumes it is running in a browser with the Request API (i.e. not IE11)\n// copying here so that we can use it before rrweb adopt it\nimport type { IWindow, listenerHandler, RecordPlugin } from '@rrweb/types'\nimport { CapturedNetworkRequest, Headers, InitiatorType, NetworkRecordOptions } from './types'\nimport {\n isArray,\n isBoolean,\n isDocument,\n isFormData,\n isFunction,\n isNull,\n isNullish,\n isObject,\n isString,\n isUndefined,\n} from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window } from './utils/globals'\nimport { defaultNetworkOptions } from './extensions/replay/config'\nimport { formDataToQuery } from './utils/request-utils'\n\nexport type NetworkData = {\n requests: CapturedNetworkRequest[]\n isInitial?: boolean\n}\n\ntype networkCallback = (data: NetworkData) => void\n\nconst isNavigationTiming = (entry: PerformanceEntry): entry is PerformanceNavigationTiming =>\n entry.entryType === 'navigation'\nconst isResourceTiming = (entry: PerformanceEntry): entry is PerformanceResourceTiming => entry.entryType === 'resource'\n\ntype ObservedPerformanceEntry = (PerformanceNavigationTiming | PerformanceResourceTiming) & {\n responseStatus?: number\n}\n\n// import { patch } from 'rrweb/typings/utils'\n// copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129\n// which was copied from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n }\n }\n\n const original = source[name] as () => unknown\n const wrapped = replacement(original)\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (isFunction(wrapped)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {}\n Object.defineProperties(wrapped, {\n __rrweb_original__: {\n enumerable: false,\n value: original,\n },\n __posthog_wrapped__: {\n enumerable: false,\n value: true,\n },\n })\n }\n\n source[name] = wrapped\n\n return () => {\n source[name] = original\n }\n } catch {\n return () => {\n //\n }\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n\nexport function findLast<T>(array: Array<T>, predicate: (value: T) => boolean): T | undefined {\n const length = array.length\n for (let i = length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) {\n return array[i]\n }\n }\n return undefined\n}\n\nfunction initPerformanceObserver(cb: networkCallback, win: IWindow, options: Required<NetworkRecordOptions>) {\n // if we are only observing timings then we could have a single observer for all types, with buffer true,\n // but we are going to filter by initiatorType _if we are wrapping fetch and xhr as the wrapped functions\n // will deal with those.\n // so we have a block which captures requests from before fetch/xhr is wrapped\n // these are marked `isInitial` so playback can display them differently if needed\n // they will never have method/status/headers/body because they are pre-wrapping that provides that\n if (options.recordInitialRequests) {\n const initialPerformanceEntries = win.performance\n .getEntries()\n .filter(\n (entry): entry is ObservedPerformanceEntry =>\n isNavigationTiming(entry) ||\n (isResourceTiming(entry) && options.initiatorTypes.includes(entry.initiatorType as InitiatorType))\n )\n cb({\n requests: initialPerformanceEntries.flatMap((entry) =>\n prepareRequest(entry, undefined, undefined, {}, true)\n ),\n isInitial: true,\n })\n }\n const observer = new win.PerformanceObserver((entries) => {\n // if recordBody or recordHeaders is true then we don't want to record fetch or xhr here\n // as the wrapped functions will do that. Otherwise, this filter becomes a noop\n // because we do want to record them here\n const wrappedInitiatorFilter = (entry: ObservedPerformanceEntry) =>\n options.recordBody || options.recordHeaders\n ? entry.initiatorType !== 'xmlhttprequest' && entry.initiatorType !== 'fetch'\n : true\n\n const performanceEntries = entries.getEntries().filter(\n (entry): entry is ObservedPerformanceEntry =>\n isNavigationTiming(entry) ||\n (isResourceTiming(entry) &&\n options.initiatorTypes.includes(entry.initiatorType as InitiatorType) &&\n // TODO if we are _only_ capturing timing we don't want to filter initiator here\n wrappedInitiatorFilter(entry))\n )\n\n cb({\n requests: performanceEntries.flatMap((entry) => prepareRequest(entry, undefined, undefined, {})),\n })\n })\n // compat checked earlier\n // eslint-disable-next-line compat/compat\n const entryTypes = PerformanceObserver.supportedEntryTypes.filter((x) =>\n options.performanceEntryTypeToObserve.includes(x)\n )\n // initial records are gathered above, so we don't need to observe and buffer each type separately\n observer.observe({ entryTypes })\n return () => {\n observer.disconnect()\n }\n}\n\nfunction shouldRecordHeaders(type: 'request' | 'response', recordHeaders: NetworkRecordOptions['recordHeaders']) {\n return !!recordHeaders && (isBoolean(recordHeaders) || recordHeaders[type])\n}\n\nfunction shouldRecordBody(\n type: 'request' | 'response',\n recordBody: NetworkRecordOptions['recordBody'],\n headers: Headers\n) {\n function matchesContentType(contentTypes: string[]) {\n const contentTypeHeader = Object.keys(headers).find((key) => key.toLowerCase() === 'content-type')\n const contentType = contentTypeHeader && headers[contentTypeHeader]\n return contentTypes.some((ct) => contentType?.includes(ct))\n }\n\n if (!recordBody) return false\n if (isBoolean(recordBody)) return true\n if (isArray(recordBody)) return matchesContentType(recordBody)\n const recordBodyType = recordBody[type]\n if (isBoolean(recordBodyType)) return recordBodyType\n return matchesContentType(recordBodyType)\n}\n\nasync function getRequestPerformanceEntry(\n win: IWindow,\n initiatorType: string,\n url: string,\n after?: number,\n before?: number,\n attempt = 0\n): Promise<PerformanceResourceTiming | null> {\n if (attempt > 10) {\n logger.warn('Failed to get performance entry for request', { url, initiatorType })\n return null\n }\n const urlPerformanceEntries = win.performance.getEntriesByName(url) as PerformanceResourceTiming[]\n const performanceEntry = findLast(\n urlPerformanceEntries,\n (entry) =>\n isResourceTiming(entry) &&\n entry.initiatorType === initiatorType &&\n (!after || entry.startTime >= after) &&\n (!before || entry.startTime <= before)\n )\n if (!performanceEntry) {\n await new Promise((resolve) => setTimeout(resolve, 50 * attempt))\n return getRequestPerformanceEntry(win, initiatorType, url, after, before, attempt + 1)\n }\n return performanceEntry\n}\n\n/**\n * According to MDN https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response\n * xhr response is typed as any but can be an ArrayBuffer, a Blob, a Document, a JavaScript object,\n * or a string, depending on the value of XMLHttpRequest.responseType, that contains the response entity body.\n *\n * XHR request body is Document | XMLHttpRequestBodyInit | null | undefined\n */\nfunction _tryReadXHRBody(body: Document | XMLHttpRequestBodyInit | any | null | undefined): string | null {\n if (isNullish(body)) {\n return null\n }\n\n if (isString(body)) {\n return body\n }\n\n if (isDocument(body)) {\n return body.textContent\n }\n\n if (isFormData(body)) {\n return formDataToQuery(body)\n }\n\n if (isObject(body)) {\n try {\n return JSON.stringify(body)\n } catch (e) {\n return '[SessionReplay] Failed to stringify response object'\n }\n }\n\n return '[SessionReplay] Cannot read body of type ' + toString.call(body)\n}\n\nfunction initXhrObserver(cb: networkCallback, win: IWindow, options: Required<NetworkRecordOptions>): listenerHandler {\n if (!options.initiatorTypes.includes('xmlhttprequest')) {\n return () => {\n //\n }\n }\n const recordRequestHeaders = shouldRecordHeaders('request', options.recordHeaders)\n const recordResponseHeaders = shouldRecordHeaders('response', options.recordHeaders)\n\n const restorePatch = patch(\n win.XMLHttpRequest.prototype,\n 'open',\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (originalOpen: typeof XMLHttpRequest.prototype.open) => {\n return function (\n method: string,\n url: string | URL,\n async = true,\n username?: string | null,\n password?: string | null\n ) {\n // because this function is returned in its actual context `this` _is_ an XMLHttpRequest\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const xhr = this as XMLHttpRequest\n\n // check IE earlier than this, we only initialize if Request is present\n // eslint-disable-next-line compat/compat\n const req = new Request(url)\n const networkRequest: Partial<CapturedNetworkRequest> = {}\n let after: number | undefined\n let before: number | undefined\n\n const requestHeaders: Headers = {}\n const originalSetRequestHeader = xhr.setRequestHeader.bind(xhr)\n xhr.setRequestHeader = (header: string, value: string) => {\n requestHeaders[header] = value\n return originalSetRequestHeader(header, value)\n }\n if (recordRequestHeaders) {\n networkRequest.requestHeaders = requestHeaders\n }\n\n const originalSend = xhr.send.bind(xhr)\n xhr.send = (body) => {\n if (shouldRecordBody('request', options.recordBody, requestHeaders)) {\n if (isUndefined(body) || isNull(body)) {\n networkRequest.requestBody = null\n } else {\n networkRequest.requestBody = _tryReadXHRBody(body)\n }\n }\n after = win.performance.now()\n return originalSend(body)\n }\n\n xhr.addEventListener('readystatechange', () => {\n if (xhr.readyState !== xhr.DONE) {\n return\n }\n before = win.performance.now()\n const responseHeaders: Headers = {}\n const rawHeaders = xhr.getAllResponseHeaders()\n const headers = rawHeaders.trim().split(/[\\r\\n]+/)\n headers.forEach((line) => {\n const parts = line.split(': ')\n const header = parts.shift()\n const value = parts.join(': ')\n if (header) {\n responseHeaders[header] = value\n }\n })\n if (recordResponseHeaders) {\n networkRequest.responseHeaders = responseHeaders\n }\n if (shouldRecordBody('response', options.recordBody, responseHeaders)) {\n if (isNullish(xhr.response)) {\n networkRequest.responseBody = null\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n networkRequest.responseBody = _tryReadXHRBody(xhr.response)\n }\n }\n getRequestPerformanceEntry(win, 'xmlhttprequest', req.url, after, before)\n .then((entry) => {\n if (isNull(entry)) {\n return\n }\n const requests = prepareRequest(entry, req.method, xhr?.status, networkRequest)\n cb({ requests })\n })\n .catch(() => {\n //\n })\n })\n originalOpen.call(xhr, method, url, async, username, password)\n }\n }\n )\n return () => {\n restorePatch()\n }\n}\n\n/**\n * Check if this PerformanceEntry is either a PerformanceResourceTiming or a PerformanceNavigationTiming\n * NB PerformanceNavigationTiming extends PerformanceResourceTiming\n * Here we don't care which interface it implements as both expose `serverTimings`\n */\nconst exposesServerTiming = (event: PerformanceEntry): event is PerformanceResourceTiming =>\n event.entryType === 'navigation' || event.entryType === 'resource'\n\nfunction prepareRequest(\n entry: PerformanceResourceTiming,\n method: string | undefined,\n status: number | undefined,\n networkRequest: Partial<CapturedNetworkRequest>,\n isInitial?: boolean\n): CapturedNetworkRequest[] {\n // kudos to sentry javascript sdk for excellent background on why to use Date.now() here\n // https://github.com/getsentry/sentry-javascript/blob/e856e40b6e71a73252e788cd42b5260f81c9c88e/packages/utils/src/time.ts#L70\n // can't start observer if performance.now() is not available\n // eslint-disable-next-line compat/compat\n const timeOrigin = Math.floor(Date.now() - performance.now())\n // clickhouse can't ingest timestamps that are floats\n // (in this case representing fractions of a millisecond we don't care about anyway)\n const timestamp = Math.floor(timeOrigin + entry.startTime)\n\n const requests: CapturedNetworkRequest[] = [\n {\n ...entry.toJSON(),\n startTime: Math.round(entry.startTime),\n endTime: Math.round(entry.responseEnd),\n timeOrigin,\n timestamp,\n method: method,\n initiatorType: entry.initiatorType as InitiatorType,\n status,\n requestHeaders: networkRequest.requestHeaders,\n requestBody: networkRequest.requestBody,\n responseHeaders: networkRequest.responseHeaders,\n responseBody: networkRequest.responseBody,\n isInitial,\n },\n ]\n\n if (exposesServerTiming(entry)) {\n for (const timing of entry.serverTiming || []) {\n requests.push({\n timeOrigin,\n timestamp,\n startTime: Math.round(entry.startTime),\n name: timing.name,\n duration: timing.duration,\n // the spec has a closed list of possible types\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType\n // but, we need to know this was a server timing so that we know to\n // match it to the appropriate navigation or resource timing\n // that matching will have to be on timestamp and $current_url\n entryType: 'serverTiming',\n })\n }\n }\n\n return requests\n}\n\nconst contentTypePrefixDenyList = ['video/', 'audio/']\n\nfunction _checkForCannotReadResponseBody(r: Response): string | null {\n if (r.headers.get('Transfer-Encoding') === 'chunked') {\n return 'Chunked Transfer-Encoding is not supported'\n }\n\n // `get` and `has` are case-insensitive\n // but return the header value with the casing that was supplied\n const contentType = r.headers.get('Content-Type')?.toLowerCase()\n const contentTypeIsDenied = contentTypePrefixDenyList.some((prefix) => contentType?.startsWith(prefix))\n if (contentType && contentTypeIsDenied) {\n return `Content-Type ${contentType} is not supported`\n }\n\n return null\n}\n\nfunction _tryReadBody(r: Request | Response): Promise<string> {\n // there are now already multiple places where we're using Promise...\n // eslint-disable-next-line compat/compat\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => resolve('[SessionReplay] Timeout while trying to read body'), 500)\n r.clone()\n .text()\n .then(\n (txt) => resolve(txt),\n (reason) => reject(reason)\n )\n .finally(() => clearTimeout(timeout))\n })\n}\n\nasync function _tryReadResponseBody(r: Response): Promise<string> {\n const cannotReadBodyReason: string | null = _checkForCannotReadResponseBody(r)\n if (!isNull(cannotReadBodyReason)) {\n return Promise.resolve(cannotReadBodyReason)\n }\n\n return _tryReadBody(r)\n}\n\nfunction initFetchObserver(\n cb: networkCallback,\n win: IWindow,\n options: Required<NetworkRecordOptions>\n): listenerHandler {\n if (!options.initiatorTypes.includes('fetch')) {\n return () => {\n //\n }\n }\n const recordRequestHeaders = shouldRecordHeaders('request', options.recordHeaders)\n const recordResponseHeaders = shouldRecordHeaders('response', options.recordHeaders)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const restorePatch = patch(win, 'fetch', (originalFetch: typeof fetch) => {\n return async function (url: URL | RequestInfo, init?: RequestInit | undefined) {\n // check IE earlier than this, we only initialize if Request is present\n // eslint-disable-next-line compat/compat\n const req = new Request(url, init)\n let res: Response | undefined\n const networkRequest: Partial<CapturedNetworkRequest> = {}\n let after: number | undefined\n let before: number | undefined\n try {\n const requestHeaders: Headers = {}\n req.headers.forEach((value, header) => {\n requestHeaders[header] = value\n })\n if (recordRequestHeaders) {\n networkRequest.requestHeaders = requestHeaders\n }\n if (shouldRecordBody('request', options.recordBody, requestHeaders)) {\n networkRequest.requestBody = await _tryReadBody(req)\n }\n\n after = win.performance.now()\n res = await originalFetch(req)\n before = win.performance.now()\n\n const responseHeaders: Headers = {}\n res.headers.forEach((value, header) => {\n responseHeaders[header] = value\n })\n if (recordResponseHeaders) {\n networkRequest.responseHeaders = responseHeaders\n }\n if (shouldRecordBody('response', options.recordBody, responseHeaders)) {\n networkRequest.responseBody = await _tryReadResponseBody(res)\n }\n\n return res\n } finally {\n getRequestPerformanceEntry(win, 'fetch', req.url, after, before)\n .then((entry) => {\n if (isNull(entry)) {\n return\n }\n const requests = prepareRequest(entry, req.method, res?.status, networkRequest)\n cb({ requests })\n })\n .catch(() => {\n //\n })\n }\n }\n })\n return () => {\n restorePatch()\n }\n}\n\nfunction initNetworkObserver(\n callback: networkCallback,\n win: IWindow, // top window or in an iframe\n options: NetworkRecordOptions\n): listenerHandler {\n if (!('performance' in win)) {\n return () => {\n //\n }\n }\n const networkOptions = (\n options ? Object.assign({}, defaultNetworkOptions, options) : defaultNetworkOptions\n ) as Required<NetworkRecordOptions>\n\n const cb: networkCallback = (data) => {\n const requests: CapturedNetworkRequest[] = []\n data.requests.forEach((request) => {\n const maskedRequest = networkOptions.maskRequestFn(request)\n if (maskedRequest) {\n requests.push(maskedRequest)\n }\n })\n\n if (requests.length > 0) {\n callback({ ...data, requests })\n }\n }\n const performanceObserver = initPerformanceObserver(cb, win, networkOptions)\n\n // only wrap fetch and xhr if headers or body are being recorded\n let xhrObserver: listenerHandler = () => {}\n let fetchObserver: listenerHandler = () => {}\n if (networkOptions.recordHeaders || networkOptions.recordBody) {\n xhrObserver = initXhrObserver(cb, win, networkOptions)\n fetchObserver = initFetchObserver(cb, win, networkOptions)\n }\n\n return () => {\n performanceObserver()\n xhrObserver()\n fetchObserver()\n }\n}\n\n// use the plugin name so that when this functionality is adopted into rrweb\n// we can remove this plugin and use the core functionality with the same data\nexport const NETWORK_PLUGIN_NAME = 'rrweb/network@1'\n\n// TODO how should this be typed?\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nexport const getRecordNetworkPlugin: (options?: NetworkRecordOptions) => RecordPlugin = (options) => {\n return {\n name: NETWORK_PLUGIN_NAME,\n observer: initNetworkObserver,\n options: options,\n }\n}\n\n// rrweb/networ@1 ends\n\nif (window) {\n ;(window as any).rrweb = { record: rrwebRecord, version: 'v2', rrwebVersion: version }\n ;(window as any).rrwebConsoleRecord = { getRecordConsolePlugin }\n ;(window as any).getRecordNetworkPlugin = getRecordNetworkPlugin\n}\n\nexport default rrwebRecord\n"]}
1
+ {"version":3,"file":"loader-recorder.js","sourceRoot":"","sources":["../../src/loader-recorder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,4DAA4D;AAC5D,6DAA6D;AAC7D,aAAa;AACb,OAAO,WAAW,MAAM,0CAA0C,CAAA;AAClE,6DAA6D;AAC7D,aAAa;AACb,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAA;AAYjG,OAAO,EACH,OAAO,EACP,SAAS,EACT,UAAU,EACV,UAAU,EACV,MAAM,EACN,SAAS,EACT,QAA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AsB,wBAAA,EAAE,CAC/D;IAAC,MAAc,CAAC,sBAAsB,GAAG,sBAAsB,CAAA;CACnE;AAED,eAAe,WAAW,CAAA","sourcesContent":["import { version } from 'rrweb/package.json'\n\n// Same as loader-globals.ts except includes rrweb2 scripts.\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport rrwebRecord from 'rrweb/es/rrweb/packages/rrweb/src/record'\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { getRecordConsolePlugin } from 'rrweb/es/rrweb/packages/rrweb/src/plugins/console/record'\n\n// rrweb/network@1 code starts\n// most of what is below here will be removed when rrweb release their code for this\n// see https://github.com/rrweb-io/rrweb/pull/1105\n/// <reference lib=\"dom\" />\n// NB adopted from https://github.com/rrweb-io/rrweb/pull/1105 which looks like it will be accepted into rrweb\n// however, in the PR, it throws when the performance observer data is not available\n// and assumes it is running in a browser with the Request API (i.e. not IE11)\n// copying here so that we can use it before rrweb adopt it\nimport type { IWindow, listenerHandler, RecordPlugin } from '@rrweb/types'\nimport { CapturedNetworkRequest, Headers, InitiatorType, NetworkRecordOptions } from './types'\nimport {\n isArray,\n isBoolean,\n isDocument,\n isFormData,\n isNull,\n isNullish,\n isObject,\n isString,\n isUndefined,\n} from './utils/type-utils'\nimport { logger } from './utils/logger'\nimport { window } from './utils/globals'\nimport { defaultNetworkOptions } from './extensions/replay/config'\nimport { formDataToQuery } from './utils/request-utils'\nimport { patch } from './extensions/replay/rrweb-plugins/patch'\n\nexport type NetworkData = {\n requests: CapturedNetworkRequest[]\n isInitial?: boolean\n}\n\ntype networkCallback = (data: NetworkData) => void\n\nconst isNavigationTiming = (entry: PerformanceEntry): entry is PerformanceNavigationTiming =>\n entry.entryType === 'navigation'\nconst isResourceTiming = (entry: PerformanceEntry): entry is PerformanceResourceTiming => entry.entryType === 'resource'\n\ntype ObservedPerformanceEntry = (PerformanceNavigationTiming | PerformanceResourceTiming) & {\n responseStatus?: number\n}\n\nexport function findLast<T>(array: Array<T>, predicate: (value: T) => boolean): T | undefined {\n const length = array.length\n for (let i = length - 1; i >= 0; i -= 1) {\n if (predicate(array[i])) {\n return array[i]\n }\n }\n return undefined\n}\n\nfunction initPerformanceObserver(cb: networkCallback, win: IWindow, options: Required<NetworkRecordOptions>) {\n // if we are only observing timings then we could have a single observer for all types, with buffer true,\n // but we are going to filter by initiatorType _if we are wrapping fetch and xhr as the wrapped functions\n // will deal with those.\n // so we have a block which captures requests from before fetch/xhr is wrapped\n // these are marked `isInitial` so playback can display them differently if needed\n // they will never have method/status/headers/body because they are pre-wrapping that provides that\n if (options.recordInitialRequests) {\n const initialPerformanceEntries = win.performance\n .getEntries()\n .filter(\n (entry): entry is ObservedPerformanceEntry =>\n isNavigationTiming(entry) ||\n (isResourceTiming(entry) && options.initiatorTypes.includes(entry.initiatorType as InitiatorType))\n )\n cb({\n requests: initialPerformanceEntries.flatMap((entry) =>\n prepareRequest(entry, undefined, undefined, {}, true)\n ),\n isInitial: true,\n })\n }\n const observer = new win.PerformanceObserver((entries) => {\n // if recordBody or recordHeaders is true then we don't want to record fetch or xhr here\n // as the wrapped functions will do that. Otherwise, this filter becomes a noop\n // because we do want to record them here\n const wrappedInitiatorFilter = (entry: ObservedPerformanceEntry) =>\n options.recordBody || options.recordHeaders\n ? entry.initiatorType !== 'xmlhttprequest' && entry.initiatorType !== 'fetch'\n : true\n\n const performanceEntries = entries.getEntries().filter(\n (entry): entry is ObservedPerformanceEntry =>\n isNavigationTiming(entry) ||\n (isResourceTiming(entry) &&\n options.initiatorTypes.includes(entry.initiatorType as InitiatorType) &&\n // TODO if we are _only_ capturing timing we don't want to filter initiator here\n wrappedInitiatorFilter(entry))\n )\n\n cb({\n requests: performanceEntries.flatMap((entry) => prepareRequest(entry, undefined, undefined, {})),\n })\n })\n // compat checked earlier\n // eslint-disable-next-line compat/compat\n const entryTypes = PerformanceObserver.supportedEntryTypes.filter((x) =>\n options.performanceEntryTypeToObserve.includes(x)\n )\n // initial records are gathered above, so we don't need to observe and buffer each type separately\n observer.observe({ entryTypes })\n return () => {\n observer.disconnect()\n }\n}\n\nfunction shouldRecordHeaders(type: 'request' | 'response', recordHeaders: NetworkRecordOptions['recordHeaders']) {\n return !!recordHeaders && (isBoolean(recordHeaders) || recordHeaders[type])\n}\n\nfunction shouldRecordBody(\n type: 'request' | 'response',\n recordBody: NetworkRecordOptions['recordBody'],\n headers: Headers\n) {\n function matchesContentType(contentTypes: string[]) {\n const contentTypeHeader = Object.keys(headers).find((key) => key.toLowerCase() === 'content-type')\n const contentType = contentTypeHeader && headers[contentTypeHeader]\n return contentTypes.some((ct) => contentType?.includes(ct))\n }\n\n if (!recordBody) return false\n if (isBoolean(recordBody)) return true\n if (isArray(recordBody)) return matchesContentType(recordBody)\n const recordBodyType = recordBody[type]\n if (isBoolean(recordBodyType)) return recordBodyType\n return matchesContentType(recordBodyType)\n}\n\nasync function getRequestPerformanceEntry(\n win: IWindow,\n initiatorType: string,\n url: string,\n after?: number,\n before?: number,\n attempt = 0\n): Promise<PerformanceResourceTiming | null> {\n if (attempt > 10) {\n logger.warn('Failed to get performance entry for request', { url, initiatorType })\n return null\n }\n const urlPerformanceEntries = win.performance.getEntriesByName(url) as PerformanceResourceTiming[]\n const performanceEntry = findLast(\n urlPerformanceEntries,\n (entry) =>\n isResourceTiming(entry) &&\n entry.initiatorType === initiatorType &&\n (!after || entry.startTime >= after) &&\n (!before || entry.startTime <= before)\n )\n if (!performanceEntry) {\n await new Promise((resolve) => setTimeout(resolve, 50 * attempt))\n return getRequestPerformanceEntry(win, initiatorType, url, after, before, attempt + 1)\n }\n return performanceEntry\n}\n\n/**\n * According to MDN https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response\n * xhr response is typed as any but can be an ArrayBuffer, a Blob, a Document, a JavaScript object,\n * or a string, depending on the value of XMLHttpRequest.responseType, that contains the response entity body.\n *\n * XHR request body is Document | XMLHttpRequestBodyInit | null | undefined\n */\nfunction _tryReadXHRBody(body: Document | XMLHttpRequestBodyInit | any | null | undefined): string | null {\n if (isNullish(body)) {\n return null\n }\n\n if (isString(body)) {\n return body\n }\n\n if (isDocument(body)) {\n return body.textContent\n }\n\n if (isFormData(body)) {\n return formDataToQuery(body)\n }\n\n if (isObject(body)) {\n try {\n return JSON.stringify(body)\n } catch (e) {\n return '[SessionReplay] Failed to stringify response object'\n }\n }\n\n return '[SessionReplay] Cannot read body of type ' + toString.call(body)\n}\n\nfunction initXhrObserver(cb: networkCallback, win: IWindow, options: Required<NetworkRecordOptions>): listenerHandler {\n if (!options.initiatorTypes.includes('xmlhttprequest')) {\n return () => {\n //\n }\n }\n const recordRequestHeaders = shouldRecordHeaders('request', options.recordHeaders)\n const recordResponseHeaders = shouldRecordHeaders('response', options.recordHeaders)\n\n const restorePatch = patch(\n win.XMLHttpRequest.prototype,\n 'open',\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (originalOpen: typeof XMLHttpRequest.prototype.open) => {\n return function (\n method: string,\n url: string | URL,\n async = true,\n username?: string | null,\n password?: string | null\n ) {\n // because this function is returned in its actual context `this` _is_ an XMLHttpRequest\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const xhr = this as XMLHttpRequest\n\n // check IE earlier than this, we only initialize if Request is present\n // eslint-disable-next-line compat/compat\n const req = new Request(url)\n const networkRequest: Partial<CapturedNetworkRequest> = {}\n let after: number | undefined\n let before: number | undefined\n\n const requestHeaders: Headers = {}\n const originalSetRequestHeader = xhr.setRequestHeader.bind(xhr)\n xhr.setRequestHeader = (header: string, value: string) => {\n requestHeaders[header] = value\n return originalSetRequestHeader(header, value)\n }\n if (recordRequestHeaders) {\n networkRequest.requestHeaders = requestHeaders\n }\n\n const originalSend = xhr.send.bind(xhr)\n xhr.send = (body) => {\n if (shouldRecordBody('request', options.recordBody, requestHeaders)) {\n if (isUndefined(body) || isNull(body)) {\n networkRequest.requestBody = null\n } else {\n networkRequest.requestBody = _tryReadXHRBody(body)\n }\n }\n after = win.performance.now()\n return originalSend(body)\n }\n\n xhr.addEventListener('readystatechange', () => {\n if (xhr.readyState !== xhr.DONE) {\n return\n }\n before = win.performance.now()\n const responseHeaders: Headers = {}\n const rawHeaders = xhr.getAllResponseHeaders()\n const headers = rawHeaders.trim().split(/[\\r\\n]+/)\n headers.forEach((line) => {\n const parts = line.split(': ')\n const header = parts.shift()\n const value = parts.join(': ')\n if (header) {\n responseHeaders[header] = value\n }\n })\n if (recordResponseHeaders) {\n networkRequest.responseHeaders = responseHeaders\n }\n if (shouldRecordBody('response', options.recordBody, responseHeaders)) {\n if (isNullish(xhr.response)) {\n networkRequest.responseBody = null\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n networkRequest.responseBody = _tryReadXHRBody(xhr.response)\n }\n }\n getRequestPerformanceEntry(win, 'xmlhttprequest', req.url, after, before)\n .then((entry) => {\n if (isNull(entry)) {\n return\n }\n const requests = prepareRequest(entry, req.method, xhr?.status, networkRequest)\n cb({ requests })\n })\n .catch(() => {\n //\n })\n })\n originalOpen.call(xhr, method, url, async, username, password)\n }\n }\n )\n return () => {\n restorePatch()\n }\n}\n\n/**\n * Check if this PerformanceEntry is either a PerformanceResourceTiming or a PerformanceNavigationTiming\n * NB PerformanceNavigationTiming extends PerformanceResourceTiming\n * Here we don't care which interface it implements as both expose `serverTimings`\n */\nconst exposesServerTiming = (event: PerformanceEntry): event is PerformanceResourceTiming =>\n event.entryType === 'navigation' || event.entryType === 'resource'\n\nfunction prepareRequest(\n entry: PerformanceResourceTiming,\n method: string | undefined,\n status: number | undefined,\n networkRequest: Partial<CapturedNetworkRequest>,\n isInitial?: boolean\n): CapturedNetworkRequest[] {\n // kudos to sentry javascript sdk for excellent background on why to use Date.now() here\n // https://github.com/getsentry/sentry-javascript/blob/e856e40b6e71a73252e788cd42b5260f81c9c88e/packages/utils/src/time.ts#L70\n // can't start observer if performance.now() is not available\n // eslint-disable-next-line compat/compat\n const timeOrigin = Math.floor(Date.now() - performance.now())\n // clickhouse can't ingest timestamps that are floats\n // (in this case representing fractions of a millisecond we don't care about anyway)\n const timestamp = Math.floor(timeOrigin + entry.startTime)\n\n const requests: CapturedNetworkRequest[] = [\n {\n ...entry.toJSON(),\n startTime: Math.round(entry.startTime),\n endTime: Math.round(entry.responseEnd),\n timeOrigin,\n timestamp,\n method: method,\n initiatorType: entry.initiatorType as InitiatorType,\n status,\n requestHeaders: networkRequest.requestHeaders,\n requestBody: networkRequest.requestBody,\n responseHeaders: networkRequest.responseHeaders,\n responseBody: networkRequest.responseBody,\n isInitial,\n },\n ]\n\n if (exposesServerTiming(entry)) {\n for (const timing of entry.serverTiming || []) {\n requests.push({\n timeOrigin,\n timestamp,\n startTime: Math.round(entry.startTime),\n name: timing.name,\n duration: timing.duration,\n // the spec has a closed list of possible types\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType\n // but, we need to know this was a server timing so that we know to\n // match it to the appropriate navigation or resource timing\n // that matching will have to be on timestamp and $current_url\n entryType: 'serverTiming',\n })\n }\n }\n\n return requests\n}\n\nconst contentTypePrefixDenyList = ['video/', 'audio/']\n\nfunction _checkForCannotReadResponseBody(r: Response): string | null {\n if (r.headers.get('Transfer-Encoding') === 'chunked') {\n return 'Chunked Transfer-Encoding is not supported'\n }\n\n // `get` and `has` are case-insensitive\n // but return the header value with the casing that was supplied\n const contentType = r.headers.get('Content-Type')?.toLowerCase()\n const contentTypeIsDenied = contentTypePrefixDenyList.some((prefix) => contentType?.startsWith(prefix))\n if (contentType && contentTypeIsDenied) {\n return `Content-Type ${contentType} is not supported`\n }\n\n return null\n}\n\nfunction _tryReadBody(r: Request | Response): Promise<string> {\n // there are now already multiple places where we're using Promise...\n // eslint-disable-next-line compat/compat\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => resolve('[SessionReplay] Timeout while trying to read body'), 500)\n r.clone()\n .text()\n .then(\n (txt) => resolve(txt),\n (reason) => reject(reason)\n )\n .finally(() => clearTimeout(timeout))\n })\n}\n\nasync function _tryReadResponseBody(r: Response): Promise<string> {\n const cannotReadBodyReason: string | null = _checkForCannotReadResponseBody(r)\n if (!isNull(cannotReadBodyReason)) {\n return Promise.resolve(cannotReadBodyReason)\n }\n\n return _tryReadBody(r)\n}\n\nfunction initFetchObserver(\n cb: networkCallback,\n win: IWindow,\n options: Required<NetworkRecordOptions>\n): listenerHandler {\n if (!options.initiatorTypes.includes('fetch')) {\n return () => {\n //\n }\n }\n const recordRequestHeaders = shouldRecordHeaders('request', options.recordHeaders)\n const recordResponseHeaders = shouldRecordHeaders('response', options.recordHeaders)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const restorePatch = patch(win, 'fetch', (originalFetch: typeof fetch) => {\n return async function (url: URL | RequestInfo, init?: RequestInit | undefined) {\n // check IE earlier than this, we only initialize if Request is present\n // eslint-disable-next-line compat/compat\n const req = new Request(url, init)\n let res: Response | undefined\n const networkRequest: Partial<CapturedNetworkRequest> = {}\n let after: number | undefined\n let before: number | undefined\n try {\n const requestHeaders: Headers = {}\n req.headers.forEach((value, header) => {\n requestHeaders[header] = value\n })\n if (recordRequestHeaders) {\n networkRequest.requestHeaders = requestHeaders\n }\n if (shouldRecordBody('request', options.recordBody, requestHeaders)) {\n networkRequest.requestBody = await _tryReadBody(req)\n }\n\n after = win.performance.now()\n res = await originalFetch(req)\n before = win.performance.now()\n\n const responseHeaders: Headers = {}\n res.headers.forEach((value, header) => {\n responseHeaders[header] = value\n })\n if (recordResponseHeaders) {\n networkRequest.responseHeaders = responseHeaders\n }\n if (shouldRecordBody('response', options.recordBody, responseHeaders)) {\n networkRequest.responseBody = await _tryReadResponseBody(res)\n }\n\n return res\n } finally {\n getRequestPerformanceEntry(win, 'fetch', req.url, after, before)\n .then((entry) => {\n if (isNull(entry)) {\n return\n }\n const requests = prepareRequest(entry, req.method, res?.status, networkRequest)\n cb({ requests })\n })\n .catch(() => {\n //\n })\n }\n }\n })\n return () => {\n restorePatch()\n }\n}\n\nfunction initNetworkObserver(\n callback: networkCallback,\n win: IWindow, // top window or in an iframe\n options: NetworkRecordOptions\n): listenerHandler {\n if (!('performance' in win)) {\n return () => {\n //\n }\n }\n const networkOptions = (\n options ? Object.assign({}, defaultNetworkOptions, options) : defaultNetworkOptions\n ) as Required<NetworkRecordOptions>\n\n const cb: networkCallback = (data) => {\n const requests: CapturedNetworkRequest[] = []\n data.requests.forEach((request) => {\n const maskedRequest = networkOptions.maskRequestFn(request)\n if (maskedRequest) {\n requests.push(maskedRequest)\n }\n })\n\n if (requests.length > 0) {\n callback({ ...data, requests })\n }\n }\n const performanceObserver = initPerformanceObserver(cb, win, networkOptions)\n\n // only wrap fetch and xhr if headers or body are being recorded\n let xhrObserver: listenerHandler = () => {}\n let fetchObserver: listenerHandler = () => {}\n if (networkOptions.recordHeaders || networkOptions.recordBody) {\n xhrObserver = initXhrObserver(cb, win, networkOptions)\n fetchObserver = initFetchObserver(cb, win, networkOptions)\n }\n\n return () => {\n performanceObserver()\n xhrObserver()\n fetchObserver()\n }\n}\n\n// use the plugin name so that when this functionality is adopted into rrweb\n// we can remove this plugin and use the core functionality with the same data\nexport const NETWORK_PLUGIN_NAME = 'rrweb/network@1'\n\n// TODO how should this be typed?\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nexport const getRecordNetworkPlugin: (options?: NetworkRecordOptions) => RecordPlugin = (options) => {\n return {\n name: NETWORK_PLUGIN_NAME,\n observer: initNetworkObserver,\n options: options,\n }\n}\n\n// rrweb/networ@1 ends\n\nif (window) {\n ;(window as any).rrweb = { record: rrwebRecord, version: 'v2', rrwebVersion: version }\n ;(window as any).rrwebConsoleRecord = { getRecordConsolePlugin }\n ;(window as any).getRecordNetworkPlugin = getRecordNetworkPlugin\n}\n\nexport default rrwebRecord\n"]}
@@ -0,0 +1 @@
1
+ export {};