@amplitude/session-replay-browser 1.51.4 → 1.52.0-codexsemantic-review-integration.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.
Files changed (87) hide show
  1. package/lib/cjs/config/joined-config.d.ts.map +1 -1
  2. package/lib/cjs/config/joined-config.js +25 -18
  3. package/lib/cjs/config/joined-config.js.map +1 -1
  4. package/lib/cjs/config/local-config.d.ts +3 -0
  5. package/lib/cjs/config/local-config.d.ts.map +1 -1
  6. package/lib/cjs/config/local-config.js +2 -0
  7. package/lib/cjs/config/local-config.js.map +1 -1
  8. package/lib/cjs/config/types.d.ts +6 -0
  9. package/lib/cjs/config/types.d.ts.map +1 -1
  10. package/lib/cjs/config/types.js.map +1 -1
  11. package/lib/cjs/hooks/click.d.ts +8 -2
  12. package/lib/cjs/hooks/click.d.ts.map +1 -1
  13. package/lib/cjs/hooks/click.js +42 -3
  14. package/lib/cjs/hooks/click.js.map +1 -1
  15. package/lib/cjs/plugins/url-tracking-plugin.d.ts +3 -0
  16. package/lib/cjs/plugins/url-tracking-plugin.d.ts.map +1 -1
  17. package/lib/cjs/plugins/url-tracking-plugin.js +16 -9
  18. package/lib/cjs/plugins/url-tracking-plugin.js.map +1 -1
  19. package/lib/cjs/semantic-identity.d.ts +5 -0
  20. package/lib/cjs/semantic-identity.d.ts.map +1 -0
  21. package/lib/cjs/semantic-identity.js +67 -0
  22. package/lib/cjs/semantic-identity.js.map +1 -0
  23. package/lib/cjs/semantic.d.ts +24 -0
  24. package/lib/cjs/semantic.d.ts.map +1 -0
  25. package/lib/cjs/semantic.js +131 -0
  26. package/lib/cjs/semantic.js.map +1 -0
  27. package/lib/cjs/session-replay.d.ts +4 -1
  28. package/lib/cjs/session-replay.d.ts.map +1 -1
  29. package/lib/cjs/session-replay.js +155 -80
  30. package/lib/cjs/session-replay.js.map +1 -1
  31. package/lib/cjs/utils/rrweb.d.ts +3 -0
  32. package/lib/cjs/utils/rrweb.d.ts.map +1 -1
  33. package/lib/cjs/utils/rrweb.js.map +1 -1
  34. package/lib/cjs/version.d.ts +1 -1
  35. package/lib/cjs/version.d.ts.map +1 -1
  36. package/lib/cjs/version.js +1 -1
  37. package/lib/cjs/version.js.map +1 -1
  38. package/lib/esm/config/joined-config.d.ts.map +1 -1
  39. package/lib/esm/config/joined-config.js +25 -18
  40. package/lib/esm/config/joined-config.js.map +1 -1
  41. package/lib/esm/config/local-config.d.ts +3 -0
  42. package/lib/esm/config/local-config.d.ts.map +1 -1
  43. package/lib/esm/config/local-config.js +2 -0
  44. package/lib/esm/config/local-config.js.map +1 -1
  45. package/lib/esm/config/types.d.ts +6 -0
  46. package/lib/esm/config/types.d.ts.map +1 -1
  47. package/lib/esm/config/types.js.map +1 -1
  48. package/lib/esm/hooks/click.d.ts +8 -2
  49. package/lib/esm/hooks/click.d.ts.map +1 -1
  50. package/lib/esm/hooks/click.js +42 -3
  51. package/lib/esm/hooks/click.js.map +1 -1
  52. package/lib/esm/plugins/url-tracking-plugin.d.ts +3 -0
  53. package/lib/esm/plugins/url-tracking-plugin.d.ts.map +1 -1
  54. package/lib/esm/plugins/url-tracking-plugin.js +16 -9
  55. package/lib/esm/plugins/url-tracking-plugin.js.map +1 -1
  56. package/lib/esm/semantic-identity.d.ts +5 -0
  57. package/lib/esm/semantic-identity.d.ts.map +1 -0
  58. package/lib/esm/semantic-identity.js +63 -0
  59. package/lib/esm/semantic-identity.js.map +1 -0
  60. package/lib/esm/semantic.d.ts +24 -0
  61. package/lib/esm/semantic.d.ts.map +1 -0
  62. package/lib/esm/semantic.js +128 -0
  63. package/lib/esm/semantic.js.map +1 -0
  64. package/lib/esm/session-replay.d.ts +4 -1
  65. package/lib/esm/session-replay.d.ts.map +1 -1
  66. package/lib/esm/session-replay.js +155 -80
  67. package/lib/esm/session-replay.js.map +1 -1
  68. package/lib/esm/utils/rrweb.d.ts +3 -0
  69. package/lib/esm/utils/rrweb.d.ts.map +1 -1
  70. package/lib/esm/utils/rrweb.js.map +1 -1
  71. package/lib/esm/version.d.ts +1 -1
  72. package/lib/esm/version.d.ts.map +1 -1
  73. package/lib/esm/version.js +1 -1
  74. package/lib/esm/version.js.map +1 -1
  75. package/lib/scripts/console-plugin-min.js +1 -1
  76. package/lib/scripts/console-plugin-min.js.gz +0 -0
  77. package/lib/scripts/console-plugin-min.js.map +1 -1
  78. package/lib/scripts/index-min.js +1 -1
  79. package/lib/scripts/index-min.js.gz +0 -0
  80. package/lib/scripts/index-min.js.map +1 -1
  81. package/lib/scripts/rrweb-record-min.js +1 -1
  82. package/lib/scripts/rrweb-record-min.js.gz +0 -0
  83. package/lib/scripts/rrweb-record-min.js.map +1 -1
  84. package/lib/scripts/session-replay-browser-min.js +1 -1
  85. package/lib/scripts/session-replay-browser-min.js.gz +0 -0
  86. package/lib/scripts/session-replay-browser-min.js.map +1 -1
  87. package/package.json +7 -6
@@ -1 +1 @@
1
- {"version":3,"file":"session-replay.d.ts","sourceRoot":"","sources":["../../src/session-replay.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,OAAO,EASR,MAAM,2BAA2B,CAAC;AAKnC,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,kCAAkC,EAInC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,EAQjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAuB,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAavF,OAAO,EACL,sBAAsB,EACtB,0BAA0B,IAAI,mCAAmC,EAIjE,kBAAkB,IAAI,mBAAmB,EACzC,oBAAoB,EACpB,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,KAAK,WAAW,GAAG,CAAC,CAAC,EAAE,mBAAmB,GAAG,KAAK,KAAK,IAAI,CAAC;AAE5D,qBAAa,aAAc,YAAW,sBAAs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F,WAAW;IAIX,YAAY;IAIZ,KAAK;YAIS,MAAM;IAMpB,IAAI;IAQE,KAAK,CAAC,QAAQ,UAAQ;IAS5B,QAAQ;IAYR,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,WAAW;YAyBL,0BAA0B;CAUzC"}
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SessionReplay = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var semantic_1 = require("./semantic");
6
+ var semantic_identity_1 = require("./semantic-identity");
7
+ var finder_1 = require("./libs/finder");
5
8
  var session_replay_dom_privacy_1 = require("@amplitude/session-replay-dom-privacy");
6
9
  var analytics_core_1 = require("@amplitude/analytics-core");
7
10
  // Import only specific types to avoid pulling in the entire rrweb-types package
@@ -264,18 +267,21 @@ var SessionReplay = /** @class */ (function () {
264
267
  });
265
268
  });
266
269
  };
267
- this.stopRecordingEvents = function () {
268
- var _a, _b, _c;
270
+ this.stopRecordingEvents = function (reason, state) {
271
+ var _a, _b, _c, _d;
272
+ if (reason === void 0) { reason = 'targeting'; }
273
+ if (state === void 0) { state = 'stop'; }
269
274
  try {
275
+ (_a = _this.semanticAdapter) === null || _a === void 0 ? void 0 : _a.stop(reason, state);
270
276
  _this.loggerProvider.log('Session Replay capture stopping.');
271
277
  _this.recordCancelCallback && _this.recordCancelCallback();
272
278
  _this.recordCancelCallback = null;
273
- (_a = _this.networkObservers) === null || _a === void 0 ? void 0 : _a.stop();
274
- (_b = _this.crossOriginIframeCoordinator) === null || _b === void 0 ? void 0 : _b.stop();
279
+ (_b = _this.networkObservers) === null || _b === void 0 ? void 0 : _b.stop();
280
+ (_c = _this.crossOriginIframeCoordinator) === null || _c === void 0 ? void 0 : _c.stop();
275
281
  _this.crossOriginIframeCoordinator = null;
276
282
  // Remove the child-mode parent signal listener so a later mode change
277
283
  // (e.g. crossOriginIframes disabled) does not leave a stale listener.
278
- (_c = _this.crossOriginParentSignalCleanup) === null || _c === void 0 ? void 0 : _c.call(_this);
284
+ (_d = _this.crossOriginParentSignalCleanup) === null || _d === void 0 ? void 0 : _d.call(_this);
279
285
  _this.crossOriginParentSignalCleanup = null;
280
286
  }
281
287
  catch (error) {
@@ -346,17 +352,19 @@ var SessionReplay = /** @class */ (function () {
346
352
  return currentUrl != null ? { url: currentUrl } : undefined;
347
353
  };
348
354
  SessionReplay.prototype._init = function (apiKey, options) {
349
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
355
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
350
356
  return tslib_1.__awaiter(this, void 0, void 0, function () {
351
- var now, _q, _r, joinedConfig, localConfig, remoteConfig, scrollWatcher, managers, storeType, compressionWorkerScript, trackDestinationWorkerScript, globalScope, _s, compressionScript, trackDestinationScript, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError, onFullSnapshotProcessed, pending_2, pending_1, pending_1_1, _t, event_1, sessionId, messenger, needsUrlTracking;
352
- var e_2, _u;
357
+ var now, _r, _s, joinedConfig, localConfig, remoteConfig, scrollWatcher, managers, storeType, compressionWorkerScript, trackDestinationWorkerScript, globalScope, _t, compressionScript, trackDestinationScript, rrwebEventManager, error_1, typedError, payloadBatcher, interactionEventManager, error_2, typedError, onFullSnapshotProcessed, pending_2, pending_1, pending_1_1, _u, event_1, sessionId, messenger, needsUrlTracking;
358
+ var e_2, _v;
353
359
  var _this = this;
354
- return tslib_1.__generator(this, function (_v) {
355
- switch (_v.label) {
360
+ return tslib_1.__generator(this, function (_w) {
361
+ switch (_w.label) {
356
362
  case 0:
357
363
  // Re-init should always tear down any previous URL-change subscription, even when the
358
364
  // next config has no targeting config and we don't subscribe again.
359
365
  (_a = this.urlChangeCleanup) === null || _a === void 0 ? void 0 : _a.call(this);
366
+ (_b = this.semanticAdapter) === null || _b === void 0 ? void 0 : _b.stop('customer_stop');
367
+ this.semanticAdapter = undefined;
360
368
  // A new init always allows capture again. `stop()` only pauses the current instance.
361
369
  this.recordingEnabled = true;
362
370
  this.startChildRecordingOnSetup = false;
@@ -369,19 +377,19 @@ var SessionReplay = /** @class */ (function () {
369
377
  (0, replay_start_time_store_1.pruneStaleReplayStartTimes)(apiKey, now, this.loggerProvider);
370
378
  this.sessionStartTime =
371
379
  options.sessionId !== undefined
372
- ? (_b = (0, replay_start_time_store_1.getOrInitReplayStartTime)(apiKey, options.sessionId, now, this.loggerProvider)) !== null && _b !== void 0 ? _b : now
380
+ ? (_c = (0, replay_start_time_store_1.getOrInitReplayStartTime)(apiKey, options.sessionId, now, this.loggerProvider)) !== null && _c !== void 0 ? _c : now
373
381
  : now;
374
- _q = this;
382
+ _r = this;
375
383
  return [4 /*yield*/, (0, joined_config_1.createSessionReplayJoinedConfigGenerator)(apiKey, options)];
376
384
  case 1:
377
- _q.joinedConfigGenerator = _v.sent();
385
+ _r.joinedConfigGenerator = _w.sent();
378
386
  return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig()];
379
387
  case 2:
380
- _r = _v.sent(), joinedConfig = _r.joinedConfig, localConfig = _r.localConfig, remoteConfig = _r.remoteConfig;
388
+ _s = _w.sent(), joinedConfig = _s.joinedConfig, localConfig = _s.localConfig, remoteConfig = _s.remoteConfig;
381
389
  this.config = joinedConfig;
382
- this.setMetadata(options.sessionId, joinedConfig, localConfig, remoteConfig, (_c = options.version) === null || _c === void 0 ? void 0 : _c.version, version_1.VERSION, (_d = options.version) === null || _d === void 0 ? void 0 : _d.type);
390
+ this.setMetadata(options.sessionId, joinedConfig, localConfig, remoteConfig, (_d = options.version) === null || _d === void 0 ? void 0 : _d.version, version_1.VERSION, (_e = options.version) === null || _e === void 0 ? void 0 : _e.type);
383
391
  this.pageLeaveFns = [];
384
- if (options.sessionId && ((_e = this.config.interactionConfig) === null || _e === void 0 ? void 0 : _e.enabled)) {
392
+ if (options.sessionId && ((_f = this.config.interactionConfig) === null || _f === void 0 ? void 0 : _f.enabled)) {
385
393
  scrollWatcher = scroll_1.ScrollWatcher.default({
386
394
  sessionId: options.sessionId,
387
395
  type: 'interaction',
@@ -392,7 +400,7 @@ var SessionReplay = /** @class */ (function () {
392
400
  }
393
401
  managers = [];
394
402
  storeType = this.config.storeType;
395
- if (storeType === 'idb' && !((_f = (0, analytics_core_1.getGlobalScope)()) === null || _f === void 0 ? void 0 : _f.indexedDB)) {
403
+ if (storeType === 'idb' && !((_g = (0, analytics_core_1.getGlobalScope)()) === null || _g === void 0 ? void 0 : _g.indexedDB)) {
396
404
  storeType = 'memory';
397
405
  this.loggerProvider.warn('Could not use preferred indexedDB storage, reverting to in memory option.');
398
406
  }
@@ -401,42 +409,42 @@ var SessionReplay = /** @class */ (function () {
401
409
  if (!(this.config.useWebWorker && globalScope && globalScope.Worker)) return [3 /*break*/, 4];
402
410
  return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('./worker')); })];
403
411
  case 3:
404
- _s = _v.sent(), compressionScript = _s.compressionScript, trackDestinationScript = _s.trackDestinationScript;
412
+ _t = _w.sent(), compressionScript = _t.compressionScript, trackDestinationScript = _t.trackDestinationScript;
405
413
  compressionWorkerScript = compressionScript;
406
414
  trackDestinationWorkerScript = trackDestinationScript;
407
- _v.label = 4;
415
+ _w.label = 4;
408
416
  case 4:
409
- _v.trys.push([4, 6, , 7]);
417
+ _w.trys.push([4, 6, , 7]);
410
418
  return [4 /*yield*/, (0, events_manager_1.createEventsManager)({
411
419
  config: this.config,
412
420
  type: 'replay',
413
- minInterval: (_g = this.config.flushIntervalConfig) === null || _g === void 0 ? void 0 : _g.minIntervalMs,
414
- maxInterval: (_h = this.config.flushIntervalConfig) === null || _h === void 0 ? void 0 : _h.maxIntervalMs,
421
+ minInterval: (_h = this.config.flushIntervalConfig) === null || _h === void 0 ? void 0 : _h.minIntervalMs,
422
+ maxInterval: (_j = this.config.flushIntervalConfig) === null || _j === void 0 ? void 0 : _j.maxIntervalMs,
415
423
  maxPersistedEventsSize: this.config.maxPersistedEventsSizeBytes,
416
424
  storeType: storeType,
417
425
  trackDestinationWorkerScript: trackDestinationWorkerScript,
418
426
  shouldSend: function () { return !_this.isBelowMinSessionDuration(); },
419
427
  })];
420
428
  case 5:
421
- rrwebEventManager = _v.sent();
429
+ rrwebEventManager = _w.sent();
422
430
  this.rrwebEventManager = rrwebEventManager;
423
431
  managers.push({ name: 'replay', manager: rrwebEventManager });
424
432
  return [3 /*break*/, 7];
425
433
  case 6:
426
- error_1 = _v.sent();
434
+ error_1 = _w.sent();
427
435
  typedError = error_1;
428
436
  this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(typedError.toString()));
429
437
  return [3 /*break*/, 7];
430
438
  case 7:
431
- if (!((_j = this.config.interactionConfig) === null || _j === void 0 ? void 0 : _j.enabled)) return [3 /*break*/, 11];
439
+ if (!((_k = this.config.interactionConfig) === null || _k === void 0 ? void 0 : _k.enabled)) return [3 /*break*/, 11];
432
440
  payloadBatcher = this.config.interactionConfig.batch ? click_1.clickBatcher : click_1.clickNonBatcher;
433
- _v.label = 8;
441
+ _w.label = 8;
434
442
  case 8:
435
- _v.trys.push([8, 10, , 11]);
443
+ _w.trys.push([8, 10, , 11]);
436
444
  return [4 /*yield*/, (0, events_manager_1.createEventsManager)({
437
445
  config: this.config,
438
446
  type: 'interaction',
439
- minInterval: (_k = this.config.interactionConfig.trackEveryNms) !== null && _k !== void 0 ? _k : constants_1.INTERACTION_MIN_INTERVAL,
447
+ minInterval: (_l = this.config.interactionConfig.trackEveryNms) !== null && _l !== void 0 ? _l : constants_1.INTERACTION_MIN_INTERVAL,
440
448
  maxInterval: constants_1.INTERACTION_MAX_INTERVAL,
441
449
  maxPersistedEventsSize: this.config.maxPersistedEventsSizeBytes,
442
450
  payloadBatcher: payloadBatcher,
@@ -444,11 +452,11 @@ var SessionReplay = /** @class */ (function () {
444
452
  trackDestinationWorkerScript: trackDestinationWorkerScript,
445
453
  })];
446
454
  case 9:
447
- interactionEventManager = _v.sent();
455
+ interactionEventManager = _w.sent();
448
456
  managers.push({ name: 'interaction', manager: interactionEventManager });
449
457
  return [3 /*break*/, 11];
450
458
  case 10:
451
- error_2 = _v.sent();
459
+ error_2 = _w.sent();
452
460
  typedError = error_2;
453
461
  this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(typedError.toString()));
454
462
  return [3 /*break*/, 11];
@@ -466,14 +474,14 @@ var SessionReplay = /** @class */ (function () {
466
474
  pending_2 = this.pendingEmitEvents.splice(0);
467
475
  try {
468
476
  for (pending_1 = tslib_1.__values(pending_2), pending_1_1 = pending_1.next(); !pending_1_1.done; pending_1_1 = pending_1.next()) {
469
- _t = pending_1_1.value, event_1 = _t.event, sessionId = _t.sessionId;
477
+ _u = pending_1_1.value, event_1 = _u.event, sessionId = _u.sessionId;
470
478
  this.eventCompressor.enqueueEvent(event_1, sessionId);
471
479
  }
472
480
  }
473
481
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
474
482
  finally {
475
483
  try {
476
- if (pending_1_1 && !pending_1_1.done && (_u = pending_1.return)) _u.call(pending_1);
484
+ if (pending_1_1 && !pending_1_1.done && (_v = pending_1.return)) _v.call(pending_1);
477
485
  }
478
486
  finally { if (e_2) throw e_2.error; }
479
487
  }
@@ -510,11 +518,11 @@ var SessionReplay = /** @class */ (function () {
510
518
  ], false);
511
519
  return [4 /*yield*/, this.initializeNetworkObservers()];
512
520
  case 12:
513
- _v.sent();
521
+ _w.sent();
514
522
  // Enable background capture when this page is opened by the Amplitude app
515
523
  // (window.opener exists). Uses the shared messenger singleton so that if
516
524
  // autocapture is also loaded, both share a single messenger and script load.
517
- if ((_l = (0, analytics_core_1.getGlobalScope)()) === null || _l === void 0 ? void 0 : _l.opener) {
525
+ if ((_m = (0, analytics_core_1.getGlobalScope)()) === null || _m === void 0 ? void 0 : _m.opener) {
518
526
  messenger = (0, analytics_core_1.getOrCreateWindowMessenger)();
519
527
  (0, analytics_core_1.enableBackgroundCapture)(messenger);
520
528
  messenger.setup(tslib_1.__assign({ logger: this.loggerProvider }, (this.config.serverZone && { endpoint: analytics_core_1.AMPLITUDE_ORIGINS_MAP[this.config.serverZone] })));
@@ -523,8 +531,8 @@ var SessionReplay = /** @class */ (function () {
523
531
  this.teardownEventListeners(false);
524
532
  return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options.userProperties, page: this.getCurrentPageForTargeting() }, true)];
525
533
  case 13:
526
- _v.sent();
527
- needsUrlTracking = this.config.targetingConfig || ((_p = (_o = (_m = this.config.privacyConfig) === null || _m === void 0 ? void 0 : _m.urlMaskLevels) === null || _o === void 0 ? void 0 : _o.length) !== null && _p !== void 0 ? _p : 0) > 0;
534
+ _w.sent();
535
+ needsUrlTracking = this.config.targetingConfig || ((_q = (_p = (_o = this.config.privacyConfig) === null || _o === void 0 ? void 0 : _o.urlMaskLevels) === null || _p === void 0 ? void 0 : _p.length) !== null && _q !== void 0 ? _q : 0) > 0;
528
536
  if (needsUrlTracking) {
529
537
  this.setupUrlChangeListener();
530
538
  }
@@ -537,11 +545,11 @@ var SessionReplay = /** @class */ (function () {
537
545
  return (0, analytics_core_1.returnWrapper)(this.asyncSetSessionId(sessionId, deviceId));
538
546
  };
539
547
  SessionReplay.prototype.asyncSetSessionId = function (sessionId, deviceId, options) {
540
- var _a, _b, _c, _d;
548
+ var _a, _b, _c, _d, _e, _f;
541
549
  return tslib_1.__awaiter(this, void 0, void 0, function () {
542
550
  var previousSessionId, currentDeviceId, isSessionChange, deviceIdForReplayId, joinedConfig;
543
- return tslib_1.__generator(this, function (_e) {
544
- switch (_e.label) {
551
+ return tslib_1.__generator(this, function (_g) {
552
+ switch (_g.label) {
545
553
  case 0:
546
554
  previousSessionId = (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId;
547
555
  currentDeviceId = this.getDeviceId();
@@ -564,13 +572,16 @@ var SessionReplay = /** @class */ (function () {
564
572
  this.sendEvents(previousSessionId);
565
573
  }
566
574
  isSessionChange = previousSessionId !== sessionId;
575
+ if (isSessionChange && ((_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.semanticCapture) === null || _c === void 0 ? void 0 : _c.enabled) && this.semanticAdapter) {
576
+ this.stopRecordingEvents('new_session');
577
+ }
567
578
  // Drop any beacon-buffered events from the previous session BEFORE installing the
568
579
  // new identifiers / start time. Otherwise the page-leave beacon path could attribute
569
580
  // old-session events to the new session id, and the gate (using the new start time)
570
581
  // would compute the wrong elapsed duration. Skip on a redundant same-sessionId call —
571
582
  // the buffer belongs to the *continuing* session and should ship via beacon as normal.
572
583
  if (isSessionChange) {
573
- (_b = this.rrwebEventManager) === null || _b === void 0 ? void 0 : _b.dropPendingBeaconEvents();
584
+ (_d = this.rrwebEventManager) === null || _d === void 0 ? void 0 : _d.dropPendingBeaconEvents();
574
585
  }
575
586
  deviceIdForReplayId = deviceId || this.getDeviceId();
576
587
  this.identifiers = new identifiers_1.SessionIdentifiers({
@@ -585,7 +596,7 @@ var SessionReplay = /** @class */ (function () {
585
596
  this.sessionStartTime = Date.now();
586
597
  this.suppressedSendCount = 0;
587
598
  this.hasEmittedGateDecision = false;
588
- if ((_c = this.config) === null || _c === void 0 ? void 0 : _c.apiKey) {
599
+ if ((_e = this.config) === null || _e === void 0 ? void 0 : _e.apiKey) {
589
600
  (0, replay_start_time_store_1.setReplayStartTime)(this.config.apiKey, sessionId, this.sessionStartTime, this.loggerProvider);
590
601
  if (previousSessionId !== undefined) {
591
602
  (0, replay_start_time_store_1.removeReplayStartTime)(this.config.apiKey, previousSessionId, this.loggerProvider);
@@ -595,19 +606,19 @@ var SessionReplay = /** @class */ (function () {
595
606
  if (!(this.joinedConfigGenerator && previousSessionId)) return [3 /*break*/, 2];
596
607
  return [4 /*yield*/, this.joinedConfigGenerator.generateJoinedConfig()];
597
608
  case 1:
598
- joinedConfig = (_e.sent()).joinedConfig;
609
+ joinedConfig = (_g.sent()).joinedConfig;
599
610
  this.config = joinedConfig;
600
- _e.label = 2;
611
+ _g.label = 2;
601
612
  case 2:
602
- if (!((_d = this.config) === null || _d === void 0 ? void 0 : _d.targetingConfig)) return [3 /*break*/, 4];
613
+ if (!((_f = this.config) === null || _f === void 0 ? void 0 : _f.targetingConfig)) return [3 /*break*/, 4];
603
614
  return [4 /*yield*/, this.evaluateTargetingAndCapture({ userProperties: options === null || options === void 0 ? void 0 : options.userProperties, page: this.getCurrentPageForTargeting() }, false, true)];
604
615
  case 3:
605
- _e.sent();
616
+ _g.sent();
606
617
  return [3 /*break*/, 6];
607
618
  case 4: return [4 /*yield*/, this.recordEvents()];
608
619
  case 5:
609
- _e.sent();
610
- _e.label = 6;
620
+ _g.sent();
621
+ _g.label = 6;
611
622
  case 6: return [2 /*return*/];
612
623
  }
613
624
  });
@@ -891,65 +902,71 @@ var SessionReplay = /** @class */ (function () {
891
902
  return !this.recordingEnabled || generation !== this.recordingGeneration;
892
903
  };
893
904
  SessionReplay.prototype._recordEvents = function (shouldLogMetadata) {
894
- var _a, _b, _c, _d, _e, _f, _g, _h;
905
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
895
906
  if (shouldLogMetadata === void 0) { shouldLogMetadata = true; }
896
907
  return tslib_1.__awaiter(this, void 0, void 0, function () {
897
- var config, shouldRecord, sessionId, generation, recordFunction, networkLoggingConfig, trackUrl, ignoredUrls, interactionConfig, loggingConfig, hooks, ugcFilterRules, crossOriginIframesEnabled, coordinateChildren, childMode, plugins, error_5;
908
+ var config, shouldRecord, sessionId, generation, recordFunction, networkLoggingConfig, trackUrl, ignoredUrls, interactionConfig, loggingConfig, heatmapHook, sharedSemanticClicks, mouseInteraction, clickHandler, hooks, ugcFilterRules, crossOriginIframesEnabled, coordinateChildren, childMode, plugins, error_5;
898
909
  var _this = this;
899
- return tslib_1.__generator(this, function (_j) {
900
- switch (_j.label) {
910
+ return tslib_1.__generator(this, function (_p) {
911
+ switch (_p.label) {
901
912
  case 0:
902
913
  config = this.config;
903
914
  shouldRecord = this.getShouldRecord();
904
915
  sessionId = (_a = this.identifiers) === null || _a === void 0 ? void 0 : _a.sessionId;
905
916
  if (!shouldRecord || !sessionId || !config) {
917
+ if (((_b = config === null || config === void 0 ? void 0 : config.semanticCapture) === null || _b === void 0 ? void 0 : _b.enabled) && this.semanticAdapter && this.recordCancelCallback) {
918
+ this.stopRecordingEvents(this.shouldOptOut() ? 'opt_out' : config.targetingConfig ? 'targeting' : 'sampled_out');
919
+ }
906
920
  return [2 /*return*/];
907
921
  }
908
- this.stopRecordingEvents();
922
+ this.stopRecordingEvents('focus', 'pause');
909
923
  generation = this.recordingGeneration;
910
924
  return [4 /*yield*/, this.getRecordFunction()];
911
925
  case 1:
912
- recordFunction = _j.sent();
926
+ recordFunction = _p.sent();
913
927
  // May be undefined if cannot import rrweb-record
914
928
  if (!recordFunction || this.shouldAbandonRecordStart(generation)) {
915
929
  return [2 /*return*/];
916
930
  }
917
931
  return [4 /*yield*/, this.initializeNetworkObservers()];
918
932
  case 2:
919
- _j.sent();
933
+ _p.sent();
920
934
  if (this.shouldAbandonRecordStart(generation)) {
921
935
  return [2 /*return*/];
922
936
  }
923
- networkLoggingConfig = (_b = config.loggingConfig) === null || _b === void 0 ? void 0 : _b.network;
937
+ networkLoggingConfig = (_c = config.loggingConfig) === null || _c === void 0 ? void 0 : _c.network;
924
938
  trackUrl = (0, helpers_1.getServerUrl)(config.serverZone, config.trackServerUrl);
925
939
  ignoredUrls = [constants_1.SESSION_REPLAY_SERVER_URL, constants_1.SESSION_REPLAY_EU_URL, constants_1.SESSION_REPLAY_STAGING_URL, trackUrl];
926
- (_c = this.networkObservers) === null || _c === void 0 ? void 0 : _c.start(function (event) {
940
+ (_d = this.networkObservers) === null || _d === void 0 ? void 0 : _d.start(function (event) {
927
941
  if (ignoredUrls.some(function (url) { return event.url.startsWith(url); }))
928
942
  return;
929
943
  void _this.addCustomRRWebEvent(constants_1.CustomRRwebEvent.FETCH_REQUEST, event);
930
944
  }, networkLoggingConfig);
931
945
  interactionConfig = config.interactionConfig, loggingConfig = config.loggingConfig;
932
- hooks = (interactionConfig === null || interactionConfig === void 0 ? void 0 : interactionConfig.enabled)
933
- ? {
934
- mouseInteraction: this.eventsManager &&
935
- ((_d = this.clickHandler) === null || _d === void 0 ? void 0 : _d.createHook({
936
- eventsManager: this.eventsManager,
937
- sessionId: sessionId,
938
- deviceIdFn: this.getDeviceId.bind(this),
939
- mirror: recordFunction.mirror,
940
- ugcFilterRules: (_e = interactionConfig.ugcFilterRules) !== null && _e !== void 0 ? _e : [],
941
- performanceOptions: (_f = config.performanceConfig) === null || _f === void 0 ? void 0 : _f.interaction,
942
- })),
943
- scroll: this.scrollHook,
944
- }
945
- : {};
946
+ heatmapHook = (interactionConfig === null || interactionConfig === void 0 ? void 0 : interactionConfig.enabled) && this.eventsManager
947
+ ? (_e = this.clickHandler) === null || _e === void 0 ? void 0 : _e.createHook({
948
+ eventsManager: this.eventsManager,
949
+ sessionId: sessionId,
950
+ deviceIdFn: this.getDeviceId.bind(this),
951
+ mirror: recordFunction.mirror,
952
+ ugcFilterRules: (_f = interactionConfig.ugcFilterRules) !== null && _f !== void 0 ? _f : [],
953
+ performanceOptions: (_g = config.performanceConfig) === null || _g === void 0 ? void 0 : _g.interaction,
954
+ })
955
+ : undefined;
956
+ sharedSemanticClicks = ((_h = config.semanticCapture) === null || _h === void 0 ? void 0 : _h.enabled) && recordFunction.supportsNativeMouseInteraction;
957
+ mouseInteraction = heatmapHook;
958
+ if (sharedSemanticClicks) {
959
+ clickHandler = (_j = this.clickHandler) !== null && _j !== void 0 ? _j : (this.clickHandler = new click_1.ClickHandler(this.loggerProvider));
960
+ mouseInteraction = clickHandler.createSharedHook(heatmapHook, function (event) { var _a; return (_a = _this.semanticAdapter) === null || _a === void 0 ? void 0 : _a.click(event); });
961
+ }
962
+ hooks = tslib_1.__assign(tslib_1.__assign({}, (mouseInteraction ? { mouseInteraction: mouseInteraction } : {})), ((interactionConfig === null || interactionConfig === void 0 ? void 0 : interactionConfig.enabled) ? { scroll: this.scrollHook } : {}));
946
963
  ugcFilterRules = (interactionConfig === null || interactionConfig === void 0 ? void 0 : interactionConfig.enabled) && interactionConfig.ugcFilterRules ? interactionConfig.ugcFilterRules : [];
947
964
  this.loggerProvider.log("Session Replay capture beginning for ".concat(sessionId, "."));
948
- _j.label = 3;
965
+ _p.label = 3;
949
966
  case 3:
950
- _j.trys.push([3, 5, , 6]);
951
- crossOriginIframesEnabled = !!((_g = config.crossOriginIframes) === null || _g === void 0 ? void 0 : _g.enabled);
952
- coordinateChildren = ((_h = config.crossOriginIframes) === null || _h === void 0 ? void 0 : _h.coordinateChildren) !== false;
967
+ _p.trys.push([3, 5, , 6]);
968
+ crossOriginIframesEnabled = !!((_k = config.crossOriginIframes) === null || _k === void 0 ? void 0 : _k.enabled);
969
+ coordinateChildren = ((_l = config.crossOriginIframes) === null || _l === void 0 ? void 0 : _l.coordinateChildren) !== false;
953
970
  childMode = crossOriginIframesEnabled && (0, cross_origin_iframes_1.isInIframe)();
954
971
  if (childMode && coordinateChildren) {
955
972
  // Child mode: don't self-start; wait for a start signal from the parent.
@@ -986,16 +1003,24 @@ var SessionReplay = /** @class */ (function () {
986
1003
  this.startChildRecordingOnSetup = false;
987
1004
  return [4 /*yield*/, this.getRecordingPlugins(loggingConfig)];
988
1005
  case 4:
989
- plugins = _j.sent();
1006
+ plugins = _p.sent();
990
1007
  if (this.shouldAbandonRecordStart(generation)) {
991
1008
  return [2 /*return*/];
992
1009
  }
1010
+ this.prepareSemanticCapture(config, sessionId);
993
1011
  this.recordCancelCallback = recordFunction(tslib_1.__assign(tslib_1.__assign({}, this.buildRRWebRecordOptions(config, hooks, function (event) {
994
- if (_this.shouldOptOut() || !_this.recordingEnabled) {
1012
+ var _a, _b, _c, _d;
1013
+ // The terminal state contains no page or user data and must land before rrweb stops.
1014
+ var semanticStop = ((_b = (_a = _this.config) === null || _a === void 0 ? void 0 : _a.semanticCapture) === null || _b === void 0 ? void 0 : _b.enabled) &&
1015
+ _this.semanticAdapter &&
1016
+ event.type === rrweb_types_1.EventType.Custom &&
1017
+ event.data.tag === 'amp-semantic/recording' &&
1018
+ ((_c = event.data.payload) === null || _c === void 0 ? void 0 : _c.state) === 'stop';
1019
+ if ((_this.shouldOptOut() || !_this.recordingEnabled) && !semanticStop) {
995
1020
  _this.loggerProvider.log(_this.shouldOptOut()
996
1021
  ? "Opting session ".concat(sessionId, " out of recording due to optOut config.")
997
1022
  : "Session Replay capture stopping for ".concat(sessionId, "."));
998
- _this.stopRecordingEvents();
1023
+ _this.stopRecordingEvents(_this.shouldOptOut() ? 'opt_out' : 'customer_stop');
999
1024
  _this.sendEvents();
1000
1025
  return;
1001
1026
  }
@@ -1011,7 +1036,10 @@ var SessionReplay = /** @class */ (function () {
1011
1036
  // Buffer the event so it can be flushed once the compressor is initialized.
1012
1037
  _this.pendingEmitEvents.push({ event: event, sessionId: sessionId });
1013
1038
  }
1039
+ (_d = _this.semanticAdapter) === null || _d === void 0 ? void 0 : _d.event(event);
1014
1040
  }, 'Error while capturing replay: ')), { plugins: plugins, recordCrossOriginIframes: crossOriginIframesEnabled }));
1041
+ if (this.recordCancelCallback)
1042
+ (_m = this.semanticAdapter) === null || _m === void 0 ? void 0 : _m.recordingReady();
1015
1043
  if (crossOriginIframesEnabled && !childMode && coordinateChildren) {
1016
1044
  if (!this.crossOriginIframeCoordinator) {
1017
1045
  this.crossOriginIframeCoordinator = new cross_origin_iframes_1.CrossOriginIframeCoordinator();
@@ -1024,7 +1052,8 @@ var SessionReplay = /** @class */ (function () {
1024
1052
  }
1025
1053
  return [3 /*break*/, 6];
1026
1054
  case 5:
1027
- error_5 = _j.sent();
1055
+ error_5 = _p.sent();
1056
+ (_o = this.semanticAdapter) === null || _o === void 0 ? void 0 : _o.stop('error');
1028
1057
  this.loggerProvider.warn('Failed to initialize session replay:', error_5);
1029
1058
  return [3 /*break*/, 6];
1030
1059
  case 6: return [2 /*return*/];
@@ -1032,6 +1061,52 @@ var SessionReplay = /** @class */ (function () {
1032
1061
  });
1033
1062
  });
1034
1063
  };
1064
+ SessionReplay.prototype.prepareSemanticCapture = function (config, sessionId) {
1065
+ var _this = this;
1066
+ var _a, _b, _c, _d;
1067
+ var scope = (0, analytics_core_1.getGlobalScope)();
1068
+ if (!(scope === null || scope === void 0 ? void 0 : scope.document))
1069
+ return;
1070
+ if (!((_a = config.semanticCapture) === null || _a === void 0 ? void 0 : _a.enabled)) {
1071
+ (_b = this.semanticAdapter) === null || _b === void 0 ? void 0 : _b.stop('targeting');
1072
+ (_c = this.semanticAdapter) === null || _c === void 0 ? void 0 : _c.prepare({ enabled: false }, sessionId);
1073
+ return;
1074
+ }
1075
+ if (!this.semanticAdapter) {
1076
+ this.semanticAdapter = new semantic_1.ReplaySemanticAdapter({
1077
+ document: scope.document,
1078
+ window: scope,
1079
+ sdk: "@amplitude/session-replay-browser@".concat(version_1.VERSION),
1080
+ externalClicks: ((_d = this.recordFunction) === null || _d === void 0 ? void 0 : _d.supportsNativeMouseInteraction) === true,
1081
+ // rrweb does not report auxiliary clicks through its mouseInteraction hook.
1082
+ externalAuxClicks: false,
1083
+ getNodeId: function (node) { var _a, _b, _c, _d; return (_d = (_c = (_a = _this.recordFunction) === null || _a === void 0 ? void 0 : (_b = _a.mirror).getId) === null || _c === void 0 ? void 0 : _c.call(_b, node)) !== null && _d !== void 0 ? _d : -1; },
1084
+ getNode: function (id) { var _a, _b; return (_b = (_a = _this.recordFunction) === null || _a === void 0 ? void 0 : _a.mirror.getNode(id)) !== null && _b !== void 0 ? _b : null; },
1085
+ getPrivacy: function () { var _a, _b; return (_b = (_a = _this.config) === null || _a === void 0 ? void 0 : _a.privacyConfig) !== null && _b !== void 0 ? _b : {}; },
1086
+ getUrl: function () { return scope.location.href; },
1087
+ getIdentity: function () { return (0, semantic_identity_1.getSemanticIdentity)(scope); },
1088
+ getAnalyticsContext: function () { var _a, _b; return (_b = (_a = _this.config) === null || _a === void 0 ? void 0 : _a.semanticAnalyticsContext) !== null && _b !== void 0 ? _b : { present: false, autocapture: [] }; },
1089
+ inlineStylesheet: config.shouldInlineStylesheet,
1090
+ getSelector: function (element) {
1091
+ var _a, _b;
1092
+ try {
1093
+ var options = tslib_1.__assign(tslib_1.__assign({}, (_b = (_a = _this.config) === null || _a === void 0 ? void 0 : _a.performanceConfig) === null || _b === void 0 ? void 0 : _b.interaction), { timeoutMs: 1 });
1094
+ return _this.clickHandler ? _this.clickHandler.getSelector(element, options) : (0, finder_1.finder)(element, options);
1095
+ }
1096
+ catch (_c) {
1097
+ return null;
1098
+ }
1099
+ },
1100
+ emit: function (event) {
1101
+ if (_this.recordCancelCallback && _this.recordFunction) {
1102
+ _this.recordFunction.addCustomEvent("amp-semantic/".concat(event.name), event.payload);
1103
+ }
1104
+ },
1105
+ onError: function (error) { return _this.loggerProvider.debug('Semantic capture error:', error); },
1106
+ });
1107
+ }
1108
+ this.semanticAdapter.prepare(config.semanticCapture, sessionId);
1109
+ };
1035
1110
  SessionReplay.prototype.buildRRWebRecordOptions = function (config, hooks, emit, errorLogPrefix) {
1036
1111
  var _this = this;
1037
1112
  var privacyConfig = config.privacyConfig;
@@ -1116,7 +1191,7 @@ var SessionReplay = /** @class */ (function () {
1116
1191
  this.recordingEnabled = false;
1117
1192
  this.startChildRecordingOnSetup = false;
1118
1193
  this.recordingGeneration++;
1119
- this.stopRecordingEvents();
1194
+ this.stopRecordingEvents('customer_stop');
1120
1195
  this.sendEvents();
1121
1196
  };
1122
1197
  SessionReplay.prototype.flush = function (useRetry) {
@@ -1142,7 +1217,7 @@ var SessionReplay = /** @class */ (function () {
1142
1217
  (_b = this.crossOriginParentSignalCleanup) === null || _b === void 0 ? void 0 : _b.call(this);
1143
1218
  this.crossOriginParentSignalCleanup = null;
1144
1219
  this.teardownEventListeners(true);
1145
- this.stopRecordingEvents();
1220
+ this.stopRecordingEvents(this.semanticAdapter && this.shouldOptOut() ? 'opt_out' : 'customer_stop');
1146
1221
  this.sendEvents();
1147
1222
  };
1148
1223
  SessionReplay.prototype.mapSDKType = function (sdkType) {