mixpanel-browser 2.76.0 → 2.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +8 -0
- package/.github/workflows/integration-tests.yml +2 -2
- package/.github/workflows/unit-tests.yml +2 -2
- package/CHANGELOG.md +4 -0
- package/dist/async-modules/{mixpanel-recorder-bIS4LMGd.js → mixpanel-recorder-DLKbUIEE.js} +84 -10
- package/dist/async-modules/mixpanel-recorder-wIWnMDLA.min.js +2 -0
- package/dist/async-modules/mixpanel-recorder-wIWnMDLA.min.js.map +1 -0
- package/dist/async-modules/{mixpanel-targeting-VOeN7RWY.min.js → mixpanel-targeting-CTcftSJC.min.js} +2 -2
- package/dist/async-modules/{mixpanel-targeting-VOeN7RWY.min.js.map → mixpanel-targeting-CTcftSJC.min.js.map} +1 -1
- package/dist/async-modules/{mixpanel-targeting-BcAPS-Mz.js → mixpanel-targeting-CmVvUyFM.js} +1 -1
- package/dist/mixpanel-core.cjs.d.ts +2 -1
- package/dist/mixpanel-core.cjs.js +183 -52
- package/dist/mixpanel-recorder.js +84 -10
- package/dist/mixpanel-recorder.min.js +1 -1
- package/dist/mixpanel-recorder.min.js.map +1 -1
- package/dist/mixpanel-targeting.js +1 -1
- package/dist/mixpanel-targeting.min.js +1 -1
- package/dist/mixpanel-targeting.min.js.map +1 -1
- package/dist/mixpanel-with-async-modules.cjs.d.ts +2 -1
- package/dist/mixpanel-with-async-modules.cjs.js +185 -54
- package/dist/mixpanel-with-async-recorder.cjs.d.ts +2 -1
- package/dist/mixpanel-with-async-recorder.cjs.js +185 -54
- package/dist/mixpanel-with-recorder.d.ts +2 -1
- package/dist/mixpanel-with-recorder.js +272 -90
- package/dist/mixpanel-with-recorder.min.d.ts +2 -1
- package/dist/mixpanel-with-recorder.min.js +1 -1
- package/dist/mixpanel.amd.d.ts +2 -1
- package/dist/mixpanel.amd.js +272 -90
- package/dist/mixpanel.cjs.d.ts +2 -1
- package/dist/mixpanel.cjs.js +272 -90
- package/dist/mixpanel.globals.js +185 -54
- package/dist/mixpanel.min.js +190 -186
- package/dist/mixpanel.module.d.ts +2 -1
- package/dist/mixpanel.module.js +272 -90
- package/dist/mixpanel.umd.d.ts +2 -1
- package/dist/mixpanel.umd.js +272 -90
- package/dist/rrweb-bundled.js +61 -9
- package/dist/rrweb-compiled.js +56 -9
- package/package.json +6 -5
- package/src/config.js +1 -1
- package/src/index.d.ts +2 -1
- package/src/mixpanel-core.js +1 -1
- package/src/recorder/session-recording.js +5 -1
- package/src/recorder/utils.js +27 -1
- package/src/recorder-manager.js +110 -2
- package/testServer.js +14 -1
- package/dist/async-modules/mixpanel-recorder-hFoTniVR.min.js +0 -2
- package/dist/async-modules/mixpanel-recorder-hFoTniVR.min.js.map +0 -1
- /package/src/loaders/{loader-module-with-async-recorder.d.ts → loader-module-with-async-modules.d.ts} +0 -0
package/dist/rrweb-bundled.js
CHANGED
|
@@ -9304,14 +9304,7 @@ class MutationBuffer {
|
|
|
9304
9304
|
};
|
|
9305
9305
|
while (this.mapRemoves.length) {
|
|
9306
9306
|
const removedNode = this.mapRemoves.shift();
|
|
9307
|
-
|
|
9308
|
-
try {
|
|
9309
|
-
this.iframeManager.removeIframe(removedNode);
|
|
9310
|
-
} catch (e2) {
|
|
9311
|
-
}
|
|
9312
|
-
} else {
|
|
9313
|
-
this.stylesheetManager.cleanupStylesheetsForRemovedNode(removedNode);
|
|
9314
|
-
}
|
|
9307
|
+
this.cleanupRemovedNode(removedNode);
|
|
9315
9308
|
this.mirror.removeNodeFromMap(removedNode);
|
|
9316
9309
|
}
|
|
9317
9310
|
for (const n2 of this.movedSet) {
|
|
@@ -9620,6 +9613,22 @@ class MutationBuffer {
|
|
|
9620
9613
|
}
|
|
9621
9614
|
}
|
|
9622
9615
|
});
|
|
9616
|
+
__publicField$1(this, "cleanupRemovedNode", (node2) => {
|
|
9617
|
+
if (node2.nodeName === "IFRAME") {
|
|
9618
|
+
try {
|
|
9619
|
+
this.iframeManager.removeIframe(node2);
|
|
9620
|
+
} catch (e2) {
|
|
9621
|
+
}
|
|
9622
|
+
} else {
|
|
9623
|
+
try {
|
|
9624
|
+
this.stylesheetManager.cleanupStylesheetsForRemovedNode(node2);
|
|
9625
|
+
} catch (e2) {
|
|
9626
|
+
}
|
|
9627
|
+
}
|
|
9628
|
+
node2.childNodes.forEach((child) => {
|
|
9629
|
+
this.cleanupRemovedNode(child);
|
|
9630
|
+
});
|
|
9631
|
+
});
|
|
9623
9632
|
}
|
|
9624
9633
|
init(options) {
|
|
9625
9634
|
[
|
|
@@ -11844,6 +11853,35 @@ class ProcessedNodeManager {
|
|
|
11844
11853
|
destroy() {
|
|
11845
11854
|
}
|
|
11846
11855
|
}
|
|
11856
|
+
function toOrigin(url) {
|
|
11857
|
+
try {
|
|
11858
|
+
const origin = new URL(url).origin;
|
|
11859
|
+
return origin !== "null" ? origin : null;
|
|
11860
|
+
} catch {
|
|
11861
|
+
return null;
|
|
11862
|
+
}
|
|
11863
|
+
}
|
|
11864
|
+
function buildAllowedOriginSet(origins) {
|
|
11865
|
+
if (!Array.isArray(origins) || origins.length === 0) {
|
|
11866
|
+
throw new Error(
|
|
11867
|
+
"[rrweb] allowedIframeOrigins must be a non-empty array of origin strings."
|
|
11868
|
+
);
|
|
11869
|
+
}
|
|
11870
|
+
const set = /* @__PURE__ */ new Set();
|
|
11871
|
+
for (let i2 = 0; i2 < origins.length; i2++) {
|
|
11872
|
+
const entry = origins[i2];
|
|
11873
|
+
if (typeof entry !== "string") {
|
|
11874
|
+
throw new Error(
|
|
11875
|
+
`[rrweb] allowedIframeOrigins[${i2}] must be a string, got ${typeof entry}.`
|
|
11876
|
+
);
|
|
11877
|
+
}
|
|
11878
|
+
const origin = toOrigin(entry);
|
|
11879
|
+
if (origin) {
|
|
11880
|
+
set.add(origin);
|
|
11881
|
+
}
|
|
11882
|
+
}
|
|
11883
|
+
return Object.freeze(set);
|
|
11884
|
+
}
|
|
11847
11885
|
let wrappedEmit;
|
|
11848
11886
|
let takeFullSnapshot$1;
|
|
11849
11887
|
let canvasManager;
|
|
@@ -11884,6 +11922,7 @@ function record(options = {}) {
|
|
|
11884
11922
|
recordDOM = true,
|
|
11885
11923
|
recordCanvas = false,
|
|
11886
11924
|
recordCrossOriginIframes = false,
|
|
11925
|
+
allowedIframeOrigins,
|
|
11887
11926
|
recordAfter = options.recordAfter === "DOMContentLoaded" ? options.recordAfter : "load",
|
|
11888
11927
|
userTriggeredOnInput = false,
|
|
11889
11928
|
collectFonts = false,
|
|
@@ -11894,6 +11933,13 @@ function record(options = {}) {
|
|
|
11894
11933
|
errorHandler: errorHandler2
|
|
11895
11934
|
} = options;
|
|
11896
11935
|
registerErrorHandler(errorHandler2);
|
|
11936
|
+
let validatedOrigins;
|
|
11937
|
+
if (recordCrossOriginIframes && allowedIframeOrigins && allowedIframeOrigins.length > 0) {
|
|
11938
|
+
validatedOrigins = buildAllowedOriginSet(allowedIframeOrigins);
|
|
11939
|
+
if (validatedOrigins.size === 0) {
|
|
11940
|
+
validatedOrigins = void 0;
|
|
11941
|
+
}
|
|
11942
|
+
}
|
|
11897
11943
|
const inEmittingFrame = recordCrossOriginIframes ? window.parent === window : true;
|
|
11898
11944
|
let passEmitsToParent = false;
|
|
11899
11945
|
if (!inEmittingFrame) {
|
|
@@ -11981,7 +12027,13 @@ function record(options = {}) {
|
|
|
11981
12027
|
origin: window.location.origin,
|
|
11982
12028
|
isCheckout
|
|
11983
12029
|
};
|
|
11984
|
-
|
|
12030
|
+
if (validatedOrigins) {
|
|
12031
|
+
for (const targetOrigin of validatedOrigins) {
|
|
12032
|
+
window.parent.postMessage(message, targetOrigin);
|
|
12033
|
+
}
|
|
12034
|
+
} else {
|
|
12035
|
+
window.parent.postMessage(message, "*");
|
|
12036
|
+
}
|
|
11985
12037
|
}
|
|
11986
12038
|
if (e2.type === EventType.FullSnapshot) {
|
|
11987
12039
|
lastFullSnapshotEvent = e2;
|
package/dist/rrweb-compiled.js
CHANGED
|
@@ -10695,13 +10695,7 @@ var MutationBuffer = /*#__PURE__*/ function() {
|
|
|
10695
10695
|
};
|
|
10696
10696
|
while(_this.mapRemoves.length){
|
|
10697
10697
|
var removedNode = _this.mapRemoves.shift();
|
|
10698
|
-
|
|
10699
|
-
try {
|
|
10700
|
-
_this.iframeManager.removeIframe(removedNode);
|
|
10701
|
-
} catch (e2) {}
|
|
10702
|
-
} else {
|
|
10703
|
-
_this.stylesheetManager.cleanupStylesheetsForRemovedNode(removedNode);
|
|
10704
|
-
}
|
|
10698
|
+
_this.cleanupRemovedNode(removedNode);
|
|
10705
10699
|
_this.mirror.removeNodeFromMap(removedNode);
|
|
10706
10700
|
}
|
|
10707
10701
|
for(var _iterator = _create_for_of_iterator_helper_loose(_this.movedSet), _step; !(_step = _iterator()).done;){
|
|
@@ -11021,6 +11015,20 @@ var MutationBuffer = /*#__PURE__*/ function() {
|
|
|
11021
11015
|
}
|
|
11022
11016
|
}
|
|
11023
11017
|
});
|
|
11018
|
+
__publicField$1(this, "cleanupRemovedNode", function(node2) {
|
|
11019
|
+
if (node2.nodeName === "IFRAME") {
|
|
11020
|
+
try {
|
|
11021
|
+
_this.iframeManager.removeIframe(node2);
|
|
11022
|
+
} catch (e2) {}
|
|
11023
|
+
} else {
|
|
11024
|
+
try {
|
|
11025
|
+
_this.stylesheetManager.cleanupStylesheetsForRemovedNode(node2);
|
|
11026
|
+
} catch (e2) {}
|
|
11027
|
+
}
|
|
11028
|
+
node2.childNodes.forEach(function(child) {
|
|
11029
|
+
_this.cleanupRemovedNode(child);
|
|
11030
|
+
});
|
|
11031
|
+
});
|
|
11024
11032
|
}
|
|
11025
11033
|
var _proto = MutationBuffer.prototype;
|
|
11026
11034
|
_proto.init = function init(options) {
|
|
@@ -13248,6 +13256,31 @@ var ProcessedNodeManager = /*#__PURE__*/ function() {
|
|
|
13248
13256
|
_proto.destroy = function destroy() {};
|
|
13249
13257
|
return ProcessedNodeManager;
|
|
13250
13258
|
}();
|
|
13259
|
+
function toOrigin(url) {
|
|
13260
|
+
try {
|
|
13261
|
+
var origin = new URL(url).origin;
|
|
13262
|
+
return origin !== "null" ? origin : null;
|
|
13263
|
+
} catch (e) {
|
|
13264
|
+
return null;
|
|
13265
|
+
}
|
|
13266
|
+
}
|
|
13267
|
+
function buildAllowedOriginSet(origins) {
|
|
13268
|
+
if (!Array.isArray(origins) || origins.length === 0) {
|
|
13269
|
+
throw new Error("[rrweb] allowedIframeOrigins must be a non-empty array of origin strings.");
|
|
13270
|
+
}
|
|
13271
|
+
var set = /* @__PURE__ */ new Set();
|
|
13272
|
+
for(var i2 = 0; i2 < origins.length; i2++){
|
|
13273
|
+
var entry = origins[i2];
|
|
13274
|
+
if (typeof entry !== "string") {
|
|
13275
|
+
throw new Error("[rrweb] allowedIframeOrigins[" + i2 + "] must be a string, got " + (typeof entry === "undefined" ? "undefined" : _type_of(entry)) + ".");
|
|
13276
|
+
}
|
|
13277
|
+
var origin = toOrigin(entry);
|
|
13278
|
+
if (origin) {
|
|
13279
|
+
set.add(origin);
|
|
13280
|
+
}
|
|
13281
|
+
}
|
|
13282
|
+
return Object.freeze(set);
|
|
13283
|
+
}
|
|
13251
13284
|
var wrappedEmit;
|
|
13252
13285
|
var takeFullSnapshot$1;
|
|
13253
13286
|
var canvasManager;
|
|
@@ -13269,10 +13302,17 @@ try {
|
|
|
13269
13302
|
var mirror = createMirror$2();
|
|
13270
13303
|
function record(options) {
|
|
13271
13304
|
if (options === void 0) options = {};
|
|
13272
|
-
var emit = options.emit, checkoutEveryNms = options.checkoutEveryNms, checkoutEveryNth = options.checkoutEveryNth, _options_blockClass = options.blockClass, blockClass = _options_blockClass === void 0 ? "rr-block" : _options_blockClass, _options_blockSelector = options.blockSelector, blockSelector = _options_blockSelector === void 0 ? null : _options_blockSelector, _options_ignoreClass = options.ignoreClass, ignoreClass = _options_ignoreClass === void 0 ? "rr-ignore" : _options_ignoreClass, _options_ignoreSelector = options.ignoreSelector, ignoreSelector = _options_ignoreSelector === void 0 ? null : _options_ignoreSelector, _options_maskTextClass = options.maskTextClass, maskTextClass = _options_maskTextClass === void 0 ? "rr-mask" : _options_maskTextClass, _options_maskTextSelector = options.maskTextSelector, maskTextSelector = _options_maskTextSelector === void 0 ? null : _options_maskTextSelector, _options_inlineStylesheet = options.inlineStylesheet, inlineStylesheet = _options_inlineStylesheet === void 0 ? true : _options_inlineStylesheet, maskAllInputs = options.maskAllInputs, _maskInputOptions = options.maskInputOptions, _slimDOMOptions = options.slimDOMOptions, maskInputFn = options.maskInputFn, maskTextFn = options.maskTextFn, hooks = options.hooks, packFn = options.packFn, _options_sampling = options.sampling, sampling = _options_sampling === void 0 ? {} : _options_sampling, _options_dataURLOptions = options.dataURLOptions, dataURLOptions = _options_dataURLOptions === void 0 ? {} : _options_dataURLOptions, mousemoveWait = options.mousemoveWait, _options_recordDOM = options.recordDOM, recordDOM = _options_recordDOM === void 0 ? true : _options_recordDOM, _options_recordCanvas = options.recordCanvas, recordCanvas = _options_recordCanvas === void 0 ? false : _options_recordCanvas, _options_recordCrossOriginIframes = options.recordCrossOriginIframes, recordCrossOriginIframes = _options_recordCrossOriginIframes === void 0 ? false : _options_recordCrossOriginIframes, _options_recordAfter = options.recordAfter, recordAfter = _options_recordAfter === void 0 ? options.recordAfter === "DOMContentLoaded" ? options.recordAfter : "load" : _options_recordAfter, _options_userTriggeredOnInput = options.userTriggeredOnInput, userTriggeredOnInput = _options_userTriggeredOnInput === void 0 ? false : _options_userTriggeredOnInput, _options_collectFonts = options.collectFonts, collectFonts = _options_collectFonts === void 0 ? false : _options_collectFonts, _options_inlineImages = options.inlineImages, inlineImages = _options_inlineImages === void 0 ? false : _options_inlineImages, plugins = options.plugins, _options_keepIframeSrcFn = options.keepIframeSrcFn, keepIframeSrcFn = _options_keepIframeSrcFn === void 0 ? function() {
|
|
13305
|
+
var emit = options.emit, checkoutEveryNms = options.checkoutEveryNms, checkoutEveryNth = options.checkoutEveryNth, _options_blockClass = options.blockClass, blockClass = _options_blockClass === void 0 ? "rr-block" : _options_blockClass, _options_blockSelector = options.blockSelector, blockSelector = _options_blockSelector === void 0 ? null : _options_blockSelector, _options_ignoreClass = options.ignoreClass, ignoreClass = _options_ignoreClass === void 0 ? "rr-ignore" : _options_ignoreClass, _options_ignoreSelector = options.ignoreSelector, ignoreSelector = _options_ignoreSelector === void 0 ? null : _options_ignoreSelector, _options_maskTextClass = options.maskTextClass, maskTextClass = _options_maskTextClass === void 0 ? "rr-mask" : _options_maskTextClass, _options_maskTextSelector = options.maskTextSelector, maskTextSelector = _options_maskTextSelector === void 0 ? null : _options_maskTextSelector, _options_inlineStylesheet = options.inlineStylesheet, inlineStylesheet = _options_inlineStylesheet === void 0 ? true : _options_inlineStylesheet, maskAllInputs = options.maskAllInputs, _maskInputOptions = options.maskInputOptions, _slimDOMOptions = options.slimDOMOptions, maskInputFn = options.maskInputFn, maskTextFn = options.maskTextFn, hooks = options.hooks, packFn = options.packFn, _options_sampling = options.sampling, sampling = _options_sampling === void 0 ? {} : _options_sampling, _options_dataURLOptions = options.dataURLOptions, dataURLOptions = _options_dataURLOptions === void 0 ? {} : _options_dataURLOptions, mousemoveWait = options.mousemoveWait, _options_recordDOM = options.recordDOM, recordDOM = _options_recordDOM === void 0 ? true : _options_recordDOM, _options_recordCanvas = options.recordCanvas, recordCanvas = _options_recordCanvas === void 0 ? false : _options_recordCanvas, _options_recordCrossOriginIframes = options.recordCrossOriginIframes, recordCrossOriginIframes = _options_recordCrossOriginIframes === void 0 ? false : _options_recordCrossOriginIframes, allowedIframeOrigins = options.allowedIframeOrigins, _options_recordAfter = options.recordAfter, recordAfter = _options_recordAfter === void 0 ? options.recordAfter === "DOMContentLoaded" ? options.recordAfter : "load" : _options_recordAfter, _options_userTriggeredOnInput = options.userTriggeredOnInput, userTriggeredOnInput = _options_userTriggeredOnInput === void 0 ? false : _options_userTriggeredOnInput, _options_collectFonts = options.collectFonts, collectFonts = _options_collectFonts === void 0 ? false : _options_collectFonts, _options_inlineImages = options.inlineImages, inlineImages = _options_inlineImages === void 0 ? false : _options_inlineImages, plugins = options.plugins, _options_keepIframeSrcFn = options.keepIframeSrcFn, keepIframeSrcFn = _options_keepIframeSrcFn === void 0 ? function() {
|
|
13273
13306
|
return false;
|
|
13274
13307
|
} : _options_keepIframeSrcFn, _options_ignoreCSSAttributes = options.ignoreCSSAttributes, ignoreCSSAttributes = _options_ignoreCSSAttributes === void 0 ? /* @__PURE__ */ new Set([]) : _options_ignoreCSSAttributes, errorHandler2 = options.errorHandler;
|
|
13275
13308
|
registerErrorHandler(errorHandler2);
|
|
13309
|
+
var validatedOrigins;
|
|
13310
|
+
if (recordCrossOriginIframes && allowedIframeOrigins && allowedIframeOrigins.length > 0) {
|
|
13311
|
+
validatedOrigins = buildAllowedOriginSet(allowedIframeOrigins);
|
|
13312
|
+
if (validatedOrigins.size === 0) {
|
|
13313
|
+
validatedOrigins = void 0;
|
|
13314
|
+
}
|
|
13315
|
+
}
|
|
13276
13316
|
var inEmittingFrame = recordCrossOriginIframes ? window.parent === window : true;
|
|
13277
13317
|
var passEmitsToParent = false;
|
|
13278
13318
|
if (!inEmittingFrame) {
|
|
@@ -13364,7 +13404,14 @@ function record(options) {
|
|
|
13364
13404
|
origin: window.location.origin,
|
|
13365
13405
|
isCheckout: isCheckout
|
|
13366
13406
|
};
|
|
13367
|
-
|
|
13407
|
+
if (validatedOrigins) {
|
|
13408
|
+
for(var _iterator = _create_for_of_iterator_helper_loose(validatedOrigins), _step; !(_step = _iterator()).done;){
|
|
13409
|
+
var targetOrigin = _step.value;
|
|
13410
|
+
window.parent.postMessage(message, targetOrigin);
|
|
13411
|
+
}
|
|
13412
|
+
} else {
|
|
13413
|
+
window.parent.postMessage(message, "*");
|
|
13414
|
+
}
|
|
13368
13415
|
}
|
|
13369
13416
|
if (e2.type === EventType.FullSnapshot) {
|
|
13370
13417
|
lastFullSnapshotEvent = e2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mixpanel-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.77.0",
|
|
4
4
|
"description": "The official Mixpanel JavaScript browser client library",
|
|
5
5
|
"main": "dist/mixpanel.cjs.js",
|
|
6
6
|
"module": "dist/mixpanel.module.js",
|
|
@@ -91,9 +91,10 @@
|
|
|
91
91
|
"webpack": "1.12.2"
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"@mixpanel/rrweb": "2.0.0-alpha.18.
|
|
95
|
-
"@mixpanel/rrweb-plugin-console-record": "2.0.0-alpha.18.
|
|
96
|
-
"@mixpanel/rrweb-utils": "2.0.0-alpha.18.
|
|
97
|
-
"json-logic-js": "2.0.5"
|
|
94
|
+
"@mixpanel/rrweb": "2.0.0-alpha.18.4",
|
|
95
|
+
"@mixpanel/rrweb-plugin-console-record": "2.0.0-alpha.18.4",
|
|
96
|
+
"@mixpanel/rrweb-utils": "2.0.0-alpha.18.4",
|
|
97
|
+
"json-logic-js": "2.0.5",
|
|
98
|
+
"@types/json-logic-js": "2.0.5"
|
|
98
99
|
}
|
|
99
100
|
}
|
package/src/config.js
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -252,11 +252,12 @@ export interface Config {
|
|
|
252
252
|
record_mask_all_inputs: boolean;
|
|
253
253
|
record_min_ms: number;
|
|
254
254
|
record_max_ms: number;
|
|
255
|
-
|
|
255
|
+
record_allowed_iframe_origins: string[];
|
|
256
256
|
record_canvas: boolean;
|
|
257
257
|
recording_event_triggers: RecordingEventTriggers;
|
|
258
258
|
record_heatmap_data: boolean;
|
|
259
259
|
remote_settings_mode: RemoteSettingType;
|
|
260
|
+
record_sessions_percent: number;
|
|
260
261
|
hooks: {
|
|
261
262
|
before_identify?: (new_distinct_id: string) => string | null;
|
|
262
263
|
before_register?: (
|
package/src/mixpanel-core.js
CHANGED
|
@@ -64,7 +64,6 @@ var INIT_SNIPPET = 1;
|
|
|
64
64
|
/** @const */ var SETTING_FALLBACK = 'fallback';
|
|
65
65
|
/** @const */ var SETTING_DISABLED = 'disabled';
|
|
66
66
|
|
|
67
|
-
|
|
68
67
|
/*
|
|
69
68
|
* Dynamic... constants? Is that an oxymoron?
|
|
70
69
|
*/
|
|
@@ -149,6 +148,7 @@ var DEFAULT_CONFIG = {
|
|
|
149
148
|
'batch_request_timeout_ms': 90000,
|
|
150
149
|
'batch_autostart': true,
|
|
151
150
|
'hooks': {},
|
|
151
|
+
'record_allowed_iframe_origins': [],
|
|
152
152
|
'record_block_class': new RegExp('^(mp-block|fs-exclude|amp-block|rr-block|ph-no-capture)$'),
|
|
153
153
|
'record_block_selector': 'img, video, audio',
|
|
154
154
|
'record_canvas': false,
|
|
@@ -10,7 +10,7 @@ import { addOptOutCheckMixpanelLib } from '../gdpr-utils';
|
|
|
10
10
|
import { RequestBatcher } from '../request-batcher';
|
|
11
11
|
|
|
12
12
|
import { Config } from '../config';
|
|
13
|
-
import { RECORD_ENQUEUE_THROTTLE_MS } from './utils';
|
|
13
|
+
import { RECORD_ENQUEUE_THROTTLE_MS, validateAllowedOrigins } from './utils';
|
|
14
14
|
import { shouldMaskInput, shouldMaskText, getPrivacyConfig } from './masking';
|
|
15
15
|
import { getRecordNetworkPlugin } from './rrweb-network-plugin';
|
|
16
16
|
|
|
@@ -265,6 +265,8 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
|
|
|
265
265
|
);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
var validatedOrigins = validateAllowedOrigins(this.getConfig('record_allowed_iframe_origins'), logger);
|
|
269
|
+
|
|
268
270
|
try {
|
|
269
271
|
this._stopRecording = this._rrwebRecord({
|
|
270
272
|
'emit': function (ev) {
|
|
@@ -299,6 +301,8 @@ SessionRecording.prototype.startRecording = function (shouldStopBatcher) {
|
|
|
299
301
|
'maskTextSelector': '*',
|
|
300
302
|
'maskInputFn': this._getMaskFn(shouldMaskInput, privacyConfig),
|
|
301
303
|
'maskTextFn': this._getMaskFn(shouldMaskText, privacyConfig),
|
|
304
|
+
'recordCrossOriginIframes': validatedOrigins.length > 0,
|
|
305
|
+
'allowedIframeOrigins': validatedOrigins,
|
|
302
306
|
'recordCanvas': this.getConfig('record_canvas'),
|
|
303
307
|
'sampling': {
|
|
304
308
|
'canvas': 15
|
package/src/recorder/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { _ } from '../utils';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @param {import('./session-recording').SerializedRecording} serializedRecording
|
|
3
5
|
* @returns {boolean}
|
|
@@ -10,7 +12,31 @@ var isRecordingExpired = function(serializedRecording) {
|
|
|
10
12
|
|
|
11
13
|
var RECORD_ENQUEUE_THROTTLE_MS = 250;
|
|
12
14
|
|
|
15
|
+
var validateAllowedOrigins = function(origins, logger) {
|
|
16
|
+
if (!_.isArray(origins)) {
|
|
17
|
+
if (origins) {
|
|
18
|
+
logger.critical('record_allowed_iframe_origins must be an array of origin strings, cross-origin recording will be disabled.');
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
var valid = [];
|
|
23
|
+
for (var i = 0; i < origins.length; i++) {
|
|
24
|
+
try {
|
|
25
|
+
var origin = new URL(origins[i]).origin;
|
|
26
|
+
if (origin === 'null') {
|
|
27
|
+
logger.critical(origins[i] + ' has an opaque origin. Skipping this entry.');
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
valid.push(origin);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
logger.critical(origins[i] + ' is not a valid origin URL. Skipping this entry.');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return valid;
|
|
36
|
+
};
|
|
37
|
+
|
|
13
38
|
export {
|
|
14
39
|
isRecordingExpired,
|
|
15
|
-
RECORD_ENQUEUE_THROTTLE_MS
|
|
40
|
+
RECORD_ENQUEUE_THROTTLE_MS,
|
|
41
|
+
validateAllowedOrigins
|
|
16
42
|
};
|
package/src/recorder-manager.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/* eslint camelcase: "off" */
|
|
2
|
+
|
|
2
3
|
import {RECORDER_FILENAME, TARGETING_FILENAME, RECORDER_GLOBAL_NAME} from './config';
|
|
3
|
-
import { _, console, safewrap, safewrapClass } from './utils';
|
|
4
|
+
import { _, console, console_with_prefix, safewrap, safewrapClass } from './utils';
|
|
4
5
|
import { window } from './window';
|
|
5
6
|
import { Promise } from './promise-polyfill';
|
|
6
7
|
import { IDBStorageWrapper, RECORDING_REGISTRY_STORE_NAME } from './storage/indexed-db';
|
|
7
|
-
import { isRecordingExpired } from './recorder/utils';
|
|
8
|
+
import { isRecordingExpired, validateAllowedOrigins } from './recorder/utils';
|
|
8
9
|
import { getTargetingPromise } from './targeting/loader';
|
|
9
10
|
|
|
11
|
+
var logger = console_with_prefix('recorder');
|
|
12
|
+
|
|
13
|
+
var IFRAME_HANDSHAKE_REQUEST = 'mp_iframe_handshake_request';
|
|
14
|
+
var IFRAME_HANDSHAKE_RESPONSE = 'mp_iframe_handshake_response';
|
|
15
|
+
|
|
10
16
|
|
|
11
17
|
/**
|
|
12
18
|
* RecorderManager: manages session recording initialization, lifecycle and state
|
|
@@ -27,6 +33,8 @@ var RecorderManager = function(initOptions) {
|
|
|
27
33
|
this.libBasePath = initOptions.libBasePath;
|
|
28
34
|
|
|
29
35
|
this._recorder = null;
|
|
36
|
+
this._parentReplayId = null;
|
|
37
|
+
this._parentFrameRetryInterval = null;
|
|
30
38
|
};
|
|
31
39
|
|
|
32
40
|
RecorderManager.prototype.shouldLoadRecorder = function() {
|
|
@@ -80,6 +88,22 @@ RecorderManager.prototype.checkAndStartSessionRecording = function(force_start,
|
|
|
80
88
|
}, this));
|
|
81
89
|
}, this);
|
|
82
90
|
|
|
91
|
+
// Cross-origin iframe handling
|
|
92
|
+
var allowedOrigins = validateAllowedOrigins(this.getMpConfig('record_allowed_iframe_origins'), logger);
|
|
93
|
+
var isCrossOriginRecordingEnabled = allowedOrigins.length > 0;
|
|
94
|
+
|
|
95
|
+
if (isCrossOriginRecordingEnabled) {
|
|
96
|
+
// listen for handshake requests from their own child iframes (including nested)
|
|
97
|
+
this._setupParentFrameListener(allowedOrigins);
|
|
98
|
+
|
|
99
|
+
if (window.parent !== window) {
|
|
100
|
+
// also wait for parent's replay ID
|
|
101
|
+
this._setupChildFrameListener(allowedOrigins, loadRecorder);
|
|
102
|
+
this._sendParentFrameRequestWithRetry(allowedOrigins);
|
|
103
|
+
return Promise.resolve();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
83
107
|
/**
|
|
84
108
|
* If the user is sampled or start_session_recording is called, we always load the recorder since it's guaranteed a recording should start.
|
|
85
109
|
* Otherwise, if the recording registry has any records then it's likely there's a recording in progress or orphaned data that needs to be flushed.
|
|
@@ -199,6 +223,10 @@ RecorderManager.prototype.getSessionReplayUrl = function() {
|
|
|
199
223
|
};
|
|
200
224
|
|
|
201
225
|
RecorderManager.prototype.getSessionReplayId = function() {
|
|
226
|
+
// Child iframe uses parent's replay ID
|
|
227
|
+
if (this._parentReplayId) {
|
|
228
|
+
return this._parentReplayId;
|
|
229
|
+
}
|
|
202
230
|
var replay_id = null;
|
|
203
231
|
if (this._recorder) {
|
|
204
232
|
replay_id = this._recorder['replayId'];
|
|
@@ -211,6 +239,86 @@ RecorderManager.prototype.getRecorder = function() {
|
|
|
211
239
|
return this._recorder;
|
|
212
240
|
};
|
|
213
241
|
|
|
242
|
+
RecorderManager.prototype._setupChildFrameListener = function(allowedOrigins, loadRecorder) {
|
|
243
|
+
if (this._childFrameMessageHandler) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
var self = this;
|
|
247
|
+
this._childFrameMessageHandler = function(event) {
|
|
248
|
+
if (allowedOrigins.indexOf(event.origin) === -1) return;
|
|
249
|
+
var data = event.data;
|
|
250
|
+
if (data && data['type'] === IFRAME_HANDSHAKE_RESPONSE && data['token'] === self.getMpConfig('token') && data['replayId']) {
|
|
251
|
+
self._parentReplayId = data['replayId'];
|
|
252
|
+
if (data['distinctId']) {
|
|
253
|
+
self.mixpanelInstance['identify'](data['distinctId']);
|
|
254
|
+
}
|
|
255
|
+
self._parentFrameRetryActive = false;
|
|
256
|
+
window.removeEventListener('message', self._childFrameMessageHandler);
|
|
257
|
+
self._childFrameMessageHandler = null;
|
|
258
|
+
loadRecorder(true);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
window.addEventListener('message', this._childFrameMessageHandler);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
RecorderManager.prototype._sendParentFrameRequest = function(allowedOrigins) {
|
|
265
|
+
var message = {};
|
|
266
|
+
message['type'] = IFRAME_HANDSHAKE_REQUEST;
|
|
267
|
+
message['token'] = this.getMpConfig('token');
|
|
268
|
+
for (var i = 0; i < allowedOrigins.length; i++) {
|
|
269
|
+
try {
|
|
270
|
+
window.parent.postMessage(message, allowedOrigins[i]);
|
|
271
|
+
} catch (e) {
|
|
272
|
+
// origin mismatch - ignore
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
RecorderManager.prototype._sendParentFrameRequestWithRetry = function(allowedOrigins) {
|
|
278
|
+
var self = this;
|
|
279
|
+
var maxRetries = 10;
|
|
280
|
+
var retryCount = 0;
|
|
281
|
+
var delay = 50;
|
|
282
|
+
this._parentFrameRetryActive = true;
|
|
283
|
+
|
|
284
|
+
this._sendParentFrameRequest(allowedOrigins);
|
|
285
|
+
|
|
286
|
+
function scheduleRetry() {
|
|
287
|
+
setTimeout(function() {
|
|
288
|
+
if (!self._parentFrameRetryActive || self._parentReplayId || ++retryCount >= maxRetries) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
self._sendParentFrameRequest(allowedOrigins);
|
|
292
|
+
delay *= 2;
|
|
293
|
+
scheduleRetry();
|
|
294
|
+
}, delay);
|
|
295
|
+
}
|
|
296
|
+
scheduleRetry();
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
RecorderManager.prototype._setupParentFrameListener = function(allowedOrigins) {
|
|
300
|
+
if (this._parentFrameMessageHandler) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
var self = this;
|
|
304
|
+
this._parentFrameMessageHandler = function(event) {
|
|
305
|
+
if (allowedOrigins.indexOf(event.origin) === -1) return;
|
|
306
|
+
var data = event.data;
|
|
307
|
+
if (data && data['type'] === IFRAME_HANDSHAKE_REQUEST && data['token'] === self.getMpConfig('token')) {
|
|
308
|
+
var replayId = self.getSessionReplayId();
|
|
309
|
+
if (replayId) {
|
|
310
|
+
var response = {};
|
|
311
|
+
response['type'] = IFRAME_HANDSHAKE_RESPONSE;
|
|
312
|
+
response['token'] = self.getMpConfig('token');
|
|
313
|
+
response['replayId'] = replayId;
|
|
314
|
+
response['distinctId'] = self.getDistinctId();
|
|
315
|
+
event.source.postMessage(response, event.origin);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
window.addEventListener('message', this._parentFrameMessageHandler);
|
|
320
|
+
};
|
|
321
|
+
|
|
214
322
|
safewrapClass(RecorderManager);
|
|
215
323
|
|
|
216
324
|
export { RecorderManager };
|
package/testServer.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const express = require('express');
|
|
4
4
|
const cookieParser = require('cookie-parser');
|
|
5
5
|
const logger = require('morgan');
|
|
6
|
+
const { PARENT_PORT, CHILD_PORT } = require('./tests/browser/test-ports');
|
|
6
7
|
|
|
7
8
|
const app = express();
|
|
8
9
|
|
|
@@ -119,8 +120,20 @@ for (const [suiteId, suite] of Object.entries(TEST_SUITES)) {
|
|
|
119
120
|
testUrl: suite.testUrl
|
|
120
121
|
});
|
|
121
122
|
});
|
|
123
|
+
|
|
124
|
+
// Cross-origin child iframe page for session recording tests
|
|
125
|
+
app.get('/tests/new/' + suiteId + '-cross-origin-page', function(req, res) {
|
|
126
|
+
res.render('cross-origin-page.pug', {
|
|
127
|
+
testUrl: './static/build/test/browser/cross-origin-page.js'
|
|
128
|
+
});
|
|
129
|
+
});
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
const server = app.listen(
|
|
132
|
+
const server = app.listen(PARENT_PORT, function () {
|
|
125
133
|
console.log(`Mixpanel test app listening on port ${server.address().port}`);
|
|
126
134
|
});
|
|
135
|
+
|
|
136
|
+
// Second port for cross-origin iframe tests
|
|
137
|
+
const server2 = app.listen(CHILD_PORT, function () {
|
|
138
|
+
console.log(`Mixpanel cross-origin test server listening on port ${server2.address().port}`);
|
|
139
|
+
});
|