@glimt/record 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/record.cjs CHANGED
@@ -367,8 +367,6 @@ const COPY_CANVAS_ON_VOLUME_GREATER_THAN = 25e4;
367
367
  function getReadableCanvasContext(canvas, cachedContext) {
368
368
  if (canvas.width * canvas.height < COPY_CANVAS_ON_VOLUME_GREATER_THAN)
369
369
  return cachedContext ?? canvas.getContext("2d");
370
- console.log("cloning canvas for is2DCanvasBlank");
371
- const start = performance.now();
372
370
  const offscreen = document.createElement("canvas");
373
371
  offscreen.width = canvas.width;
374
372
  offscreen.height = canvas.height;
@@ -376,11 +374,6 @@ function getReadableCanvasContext(canvas, cachedContext) {
376
374
  if (ctx) {
377
375
  ctx.drawImage(canvas, 0, 0);
378
376
  }
379
- console.log(
380
- "cloned canvas for is2DCanvasBlank took",
381
- performance.now() - start,
382
- "ms"
383
- );
384
377
  return offscreen.getContext("2d", { willReadFrequently: true });
385
378
  }
386
379
  function is2DCanvasBlank(canvas, cachedContext) {
@@ -905,6 +898,13 @@ function getRootId(doc, mirror2) {
905
898
  const docId = mirror2.getId(doc);
906
899
  return docId === 1 ? void 0 : docId;
907
900
  }
901
+ const runIdleCallback = (cb) => {
902
+ if ("requestIdleCallback" in window) {
903
+ window.requestIdleCallback(cb);
904
+ } else {
905
+ setTimeout(cb, 100);
906
+ }
907
+ };
908
908
  function serializeTextNode(n2, options) {
909
909
  const { needsMask, maskTextFn, rootId, cssCaptured } = options;
910
910
  const parent = index$1.parentNode(n2);
@@ -1026,7 +1026,7 @@ function serializeElementNode(n2, options) {
1026
1026
  dataURLOptions.quality
1027
1027
  );
1028
1028
  attributes.rr_dataURL = canvasDataURL;
1029
- requestIdleCallback(() => {
1029
+ runIdleCallback(() => {
1030
1030
  try {
1031
1031
  const blankCanvas = doc.createElement("canvas");
1032
1032
  blankCanvas.width = n2.width;
@@ -1036,13 +1036,9 @@ function serializeElementNode(n2, options) {
1036
1036
  dataURLOptions.quality
1037
1037
  );
1038
1038
  if (canvasDataURL === blankCanvasDataURL) {
1039
- console.log(
1040
- "deleting dataURL because it's the same as blank canvas"
1041
- );
1042
1039
  delete attributes.rr_dataURL;
1043
1040
  }
1044
1041
  } catch (e2) {
1045
- console.log("did get context canvas error", e2);
1046
1042
  }
1047
1043
  });
1048
1044
  }
@@ -9427,38 +9423,86 @@ class MutationBuffer {
9427
9423
  __publicField(this, "canvasManager");
9428
9424
  __publicField(this, "processedNodeManager");
9429
9425
  __publicField(this, "unattachedDoc");
9430
- __publicField(this, "tempPerfStore", {});
9431
- __publicField(this, "processMutations", (mutations) => {
9426
+ __publicField(this, "stormBatches", []);
9427
+ __publicField(this, "stormInfo");
9428
+ __publicField(this, "stormSettings", {
9429
+ batchSize: 300,
9430
+ timeout: 50,
9431
+ mutationLimit: 1500
9432
+ });
9433
+ __publicField(this, "handleStormMutations", (muts) => {
9434
+ const time = Date.now();
9435
+ if (this.stormInfo == null) {
9436
+ console.log("detected probable mutation storm start");
9437
+ this.stormInfo = {
9438
+ startedAt: time,
9439
+ totalMutations: 0,
9440
+ timeout: setTimeout(this.handleStormFinish, this.stormSettings.timeout),
9441
+ stormExceededLimit: false
9442
+ };
9443
+ }
9444
+ this.stormInfo.totalMutations += muts.length;
9445
+ console.log("current storm mutations", this.stormInfo.totalMutations);
9446
+ if (this.stormInfo.totalMutations >= this.stormSettings.mutationLimit) {
9447
+ this.stormInfo.stormExceededLimit = true;
9448
+ this.stormBatches = [];
9449
+ } else {
9450
+ this.stormBatches.push({
9451
+ ts: time,
9452
+ mutations: muts
9453
+ });
9454
+ }
9455
+ if (muts.length < this.stormSettings.batchSize) {
9456
+ clearTimeout(this.stormInfo.timeout);
9457
+ this.handleStormFinish();
9458
+ }
9459
+ });
9460
+ __publicField(this, "handleStormFinish", () => {
9461
+ if (!this.stormInfo) return;
9462
+ const { stormExceededLimit } = this.stormInfo;
9463
+ console.log(
9464
+ "mutation storm finished",
9465
+ "totalMutations:",
9466
+ this.stormInfo.totalMutations,
9467
+ "stormExceededLimit:",
9468
+ stormExceededLimit
9469
+ );
9470
+ clearTimeout(this.stormInfo.timeout);
9471
+ this.stormInfo = null;
9472
+ if (!stormExceededLimit) {
9473
+ let muts = [];
9474
+ for (const batch of this.stormBatches) {
9475
+ muts.push(...batch.mutations);
9476
+ }
9477
+ this.stormBatches = [];
9478
+ this.processInternalMutations(muts, true);
9479
+ } else {
9480
+ this.stormBatches = [];
9481
+ takeFullSnapshot();
9482
+ }
9483
+ });
9484
+ __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
9485
+ if (!overrideStorm && (this.stormInfo != null || muts.length >= this.stormSettings.batchSize)) {
9486
+ this.handleStormMutations(muts);
9487
+ return;
9488
+ }
9432
9489
  const start = performance.now();
9433
- let uniqueTypes = [];
9434
- for (const mut of mutations) {
9435
- const mutStart = performance.now();
9490
+ for (const mut of muts) {
9436
9491
  this.processMutation(mut);
9437
- const took = performance.now() - mutStart;
9438
- if (!uniqueTypes.includes(mut.type)) uniqueTypes.push(mut.type);
9439
- if (!(mut.type in this.tempPerfStore)) {
9440
- this.tempPerfStore[mut.type] = {
9441
- avg: 0,
9442
- times: []
9443
- };
9444
- }
9445
- this.tempPerfStore[mut.type].times.push(took);
9446
- if (this.tempPerfStore[mut.type].times.length > 1e3) {
9447
- this.tempPerfStore[mut.type].times.shift();
9448
- }
9449
- this.tempPerfStore[mut.type].avg = this.tempPerfStore[mut.type].times.reduce((a2, b) => a2 + b, 0) / this.tempPerfStore[mut.type].times.length;
9450
9492
  }
9451
9493
  console.log(
9452
- mutations.length,
9494
+ muts.length,
9453
9495
  "mutations processed in",
9454
9496
  performance.now() - start,
9455
9497
  "ms",
9456
- "types:",
9457
- uniqueTypes
9498
+ "overrideStorm",
9499
+ overrideStorm
9458
9500
  );
9459
- window.temp_perf_store = this.tempPerfStore;
9460
9501
  this.emit();
9461
9502
  });
9503
+ __publicField(this, "processMutations", (mutations) => {
9504
+ this.processInternalMutations(mutations);
9505
+ });
9462
9506
  __publicField(this, "emit", () => {
9463
9507
  if (this.frozen || this.locked) {
9464
9508
  return;
@@ -9851,25 +9895,30 @@ class MutationBuffer {
9851
9895
  for (let i2 = 0; i2 < m.addedNodes.length; i2++) {
9852
9896
  this.genAdds(m.addedNodes[i2], m.target);
9853
9897
  }
9898
+ const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9899
+ if (isBlocked(m.target, this.blockClass, this.blockSelector, false))
9900
+ return;
9901
+ const addedSetHas = this.addedSet.has(m.target);
9902
+ const ancestorRemoved = isAncestorRemoved(m.target, this.mirror);
9903
+ const isShadow = isShadowRoot(m.target) && isNativeShadowDom(m.target) ? true : void 0;
9854
9904
  for (let i2 = 0; i2 < m.removedNodes.length; i2++) {
9855
9905
  const n2 = m.removedNodes[i2];
9856
9906
  const nodeId = this.mirror.getId(n2);
9857
- const parentId = isShadowRoot(m.target) ? this.mirror.getId(index.host(m.target)) : this.mirror.getId(m.target);
9858
- if (isBlocked(m.target, this.blockClass, this.blockSelector, false) || isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
9907
+ if (isIgnored(n2, this.mirror, this.slimDOMOptions) || !isSerialized(n2, this.mirror)) {
9859
9908
  return;
9860
9909
  }
9861
9910
  if (this.addedSet.has(n2)) {
9862
9911
  deepDelete(this.addedSet, n2);
9863
9912
  this.droppedSet.add(n2);
9864
- } else if (this.addedSet.has(m.target) && nodeId === -1) ;
9865
- else if (isAncestorRemoved(m.target, this.mirror)) ;
9913
+ } else if (addedSetHas && nodeId === -1) ;
9914
+ else if (ancestorRemoved) ;
9866
9915
  else if (this.movedSet.has(n2) && this.movedMap[moveKey(nodeId, parentId)]) {
9867
9916
  deepDelete(this.movedSet, n2);
9868
9917
  } else {
9869
9918
  this.removes.push({
9870
9919
  parentId,
9871
9920
  id: nodeId,
9872
- isShadow: isShadowRoot(m.target) && isNativeShadowDom(m.target) ? true : void 0
9921
+ isShadow
9873
9922
  });
9874
9923
  processRemoves(n2, this.removesSubTreeCache);
9875
9924
  }