@cloudcare/browser-rum 3.3.24 → 3.3.26

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 (209) hide show
  1. package/README.md +33 -0
  2. package/README.zh.md +30 -0
  3. package/bundle/dataflux-rum.js +1 -1
  4. package/cjs/boot/buildEnv.js +1 -1
  5. package/cjs/boot/disabledRumPublicApi.js +5 -0
  6. package/cjs/boot/disabledRumPublicApi.js.map +1 -1
  7. package/cjs/boot/initCallbacks.js +25 -0
  8. package/cjs/boot/initCallbacks.js.map +1 -0
  9. package/cjs/boot/perStartRum.js +99 -50
  10. package/cjs/boot/perStartRum.js.map +1 -1
  11. package/cjs/boot/recorderApi.js +36 -1
  12. package/cjs/boot/recorderApi.js.map +1 -1
  13. package/cjs/boot/rum.js +8 -9
  14. package/cjs/boot/rum.js.map +1 -1
  15. package/cjs/boot/rumPublicApi.js +6 -7
  16. package/cjs/boot/rumPublicApi.js.map +1 -1
  17. package/cjs/boot/startRecording.js +2 -0
  18. package/cjs/boot/startRecording.js.map +1 -1
  19. package/cjs/domain/configuration.js +15 -2
  20. package/cjs/domain/configuration.js.map +1 -1
  21. package/cjs/domain/contexts/urlContexts.js +32 -21
  22. package/cjs/domain/contexts/urlContexts.js.map +1 -1
  23. package/cjs/domain/contexts/viewContexts.js +1 -1
  24. package/cjs/domain/contexts/viewContexts.js.map +1 -1
  25. package/cjs/domain/deflate/deflateWorker.js +39 -27
  26. package/cjs/domain/deflate/deflateWorker.js.map +1 -1
  27. package/cjs/domain/privacy.js +79 -107
  28. package/cjs/domain/privacy.js.map +1 -1
  29. package/cjs/domain/replay/record/canvasCommandCapture.js +87 -179
  30. package/cjs/domain/replay/record/canvasCommandCapture.js.map +1 -1
  31. package/cjs/domain/replay/record/canvasCommandObserver.js +10 -6
  32. package/cjs/domain/replay/record/canvasCommandObserver.js.map +1 -1
  33. package/cjs/domain/replay/record/canvasCommandObserverStub.js +24 -0
  34. package/cjs/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  35. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js +3 -2
  36. package/cjs/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  37. package/cjs/domain/replay/record/canvasContext.js +15 -0
  38. package/cjs/domain/replay/record/canvasContext.js.map +1 -1
  39. package/cjs/domain/replay/record/canvasEncodeWorker.js +1 -1
  40. package/cjs/domain/replay/record/canvasObserver.js +3 -0
  41. package/cjs/domain/replay/record/canvasObserver.js.map +1 -1
  42. package/cjs/domain/replay/record/canvasWebGLPluginHost.js +5 -1
  43. package/cjs/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  44. package/cjs/domain/replay/record/mutationObserver.js +3 -12
  45. package/cjs/domain/replay/record/mutationObserver.js.map +1 -1
  46. package/cjs/domain/replay/record/observers.js +3 -7
  47. package/cjs/domain/replay/record/observers.js.map +1 -1
  48. package/cjs/domain/replay/record/record.js +15 -2
  49. package/cjs/domain/replay/record/record.js.map +1 -1
  50. package/cjs/domain/replay/record/serializationUtils.js +8 -23
  51. package/cjs/domain/replay/record/serializationUtils.js.map +1 -1
  52. package/cjs/domain/replay/record/serialize.js +19 -33
  53. package/cjs/domain/replay/record/serialize.js.map +1 -1
  54. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js +21 -6
  55. package/cjs/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  56. package/cjs/domain/replay/segmentCollection/segmentCollection.js +91 -143
  57. package/cjs/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  58. package/cjs/domain/replayCanvasSupported.js +8 -0
  59. package/cjs/domain/replayCanvasSupported.js.map +1 -0
  60. package/cjs/domain/requestCollection.js +38 -39
  61. package/cjs/domain/requestCollection.js.map +1 -1
  62. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  63. package/cjs/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  64. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js +143 -0
  65. package/cjs/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  66. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  67. package/cjs/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  68. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js +91 -66
  69. package/cjs/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  70. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js +11 -9
  71. package/cjs/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  72. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js +35 -50
  73. package/cjs/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  74. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +7 -1
  75. package/cjs/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  76. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  77. package/cjs/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  78. package/cjs/domain/rumEventsCollection/view/trackViews.js +3 -0
  79. package/cjs/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  80. package/cjs/domain/rumEventsCollection/view/viewCollection.js +1 -1
  81. package/cjs/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  82. package/cjs/domain/tracing/skywalkingTracer.js +4 -50
  83. package/cjs/domain/tracing/skywalkingTracer.js.map +1 -1
  84. package/cjs/domain/tracing/tracer.js +26 -3
  85. package/cjs/domain/tracing/tracer.js.map +1 -1
  86. package/esm/boot/buildEnv.js +1 -1
  87. package/esm/boot/disabledRumPublicApi.js +1 -1
  88. package/esm/boot/disabledRumPublicApi.js.map +1 -1
  89. package/esm/boot/initCallbacks.js +2 -0
  90. package/esm/boot/initCallbacks.js.map +1 -0
  91. package/esm/boot/perStartRum.js +1 -1
  92. package/esm/boot/perStartRum.js.map +1 -1
  93. package/esm/boot/recorderApi.js +1 -1
  94. package/esm/boot/recorderApi.js.map +1 -1
  95. package/esm/boot/rum.js +1 -1
  96. package/esm/boot/rum.js.map +1 -1
  97. package/esm/boot/rumPublicApi.js +1 -1
  98. package/esm/boot/rumPublicApi.js.map +1 -1
  99. package/esm/boot/startRecording.js +1 -1
  100. package/esm/boot/startRecording.js.map +1 -1
  101. package/esm/domain/configuration.js +1 -1
  102. package/esm/domain/configuration.js.map +1 -1
  103. package/esm/domain/contexts/urlContexts.js +1 -1
  104. package/esm/domain/contexts/urlContexts.js.map +1 -1
  105. package/esm/domain/contexts/viewContexts.js +1 -1
  106. package/esm/domain/contexts/viewContexts.js.map +1 -1
  107. package/esm/domain/deflate/deflateWorker.js +1 -1
  108. package/esm/domain/deflate/deflateWorker.js.map +1 -1
  109. package/esm/domain/privacy.js +1 -1
  110. package/esm/domain/privacy.js.map +1 -1
  111. package/esm/domain/replay/record/canvasCommandCapture.js +1 -1
  112. package/esm/domain/replay/record/canvasCommandCapture.js.map +1 -1
  113. package/esm/domain/replay/record/canvasCommandObserver.js +1 -1
  114. package/esm/domain/replay/record/canvasCommandObserver.js.map +1 -1
  115. package/esm/domain/replay/record/canvasCommandObserverStub.js +2 -0
  116. package/esm/domain/replay/record/canvasCommandObserverStub.js.map +1 -0
  117. package/esm/domain/replay/record/canvasCommandSerializeArgs.js +1 -1
  118. package/esm/domain/replay/record/canvasCommandSerializeArgs.js.map +1 -1
  119. package/esm/domain/replay/record/canvasContext.js +1 -1
  120. package/esm/domain/replay/record/canvasContext.js.map +1 -1
  121. package/esm/domain/replay/record/canvasEncodeWorker.js +1 -1
  122. package/esm/domain/replay/record/canvasObserver.js +1 -1
  123. package/esm/domain/replay/record/canvasObserver.js.map +1 -1
  124. package/esm/domain/replay/record/canvasWebGLPluginHost.js +1 -1
  125. package/esm/domain/replay/record/canvasWebGLPluginHost.js.map +1 -1
  126. package/esm/domain/replay/record/mutationObserver.js +1 -1
  127. package/esm/domain/replay/record/mutationObserver.js.map +1 -1
  128. package/esm/domain/replay/record/observers.js +1 -1
  129. package/esm/domain/replay/record/observers.js.map +1 -1
  130. package/esm/domain/replay/record/record.js +1 -1
  131. package/esm/domain/replay/record/record.js.map +1 -1
  132. package/esm/domain/replay/record/serializationUtils.js +1 -1
  133. package/esm/domain/replay/record/serializationUtils.js.map +1 -1
  134. package/esm/domain/replay/record/serialize.js +1 -1
  135. package/esm/domain/replay/record/serialize.js.map +1 -1
  136. package/esm/domain/replay/segmentCollection/buildReplayPayload.js +1 -1
  137. package/esm/domain/replay/segmentCollection/buildReplayPayload.js.map +1 -1
  138. package/esm/domain/replay/segmentCollection/segmentCollection.js +1 -1
  139. package/esm/domain/replay/segmentCollection/segmentCollection.js.map +1 -1
  140. package/esm/domain/replayCanvasSupported.js +2 -0
  141. package/esm/domain/replayCanvasSupported.js.map +1 -0
  142. package/esm/domain/requestCollection.js +1 -1
  143. package/esm/domain/requestCollection.js.map +1 -1
  144. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js +1 -1
  145. package/esm/domain/rumEventsCollection/actions/listenActionEvents.js.map +1 -1
  146. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js +2 -0
  147. package/esm/domain/rumEventsCollection/resource/fetchTimingRegistry.js.map +1 -0
  148. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +1 -1
  149. package/esm/domain/rumEventsCollection/resource/matchRequestResourceEntry.js.map +1 -1
  150. package/esm/domain/rumEventsCollection/resource/resourceCollection.js +1 -1
  151. package/esm/domain/rumEventsCollection/resource/resourceCollection.js.map +1 -1
  152. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js +1 -1
  153. package/esm/domain/rumEventsCollection/resource/resourceTrackerManager.js.map +1 -1
  154. package/esm/domain/rumEventsCollection/resource/resourceUtils.js +1 -1
  155. package/esm/domain/rumEventsCollection/resource/resourceUtils.js.map +1 -1
  156. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +1 -1
  157. package/esm/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js.map +1 -1
  158. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  159. package/esm/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js.map +1 -1
  160. package/esm/domain/rumEventsCollection/view/trackViews.js +1 -1
  161. package/esm/domain/rumEventsCollection/view/trackViews.js.map +1 -1
  162. package/esm/domain/rumEventsCollection/view/viewCollection.js +1 -1
  163. package/esm/domain/rumEventsCollection/view/viewCollection.js.map +1 -1
  164. package/esm/domain/tracing/skywalkingTracer.js +1 -1
  165. package/esm/domain/tracing/skywalkingTracer.js.map +1 -1
  166. package/esm/domain/tracing/tracer.js +1 -1
  167. package/esm/domain/tracing/tracer.js.map +1 -1
  168. package/package.json +7 -7
  169. package/src/boot/disabledRumPublicApi.js +5 -0
  170. package/src/boot/initCallbacks.js +16 -0
  171. package/src/boot/perStartRum.js +102 -59
  172. package/src/boot/recorderApi.js +51 -2
  173. package/src/boot/rum.js +12 -18
  174. package/src/boot/rumPublicApi.js +6 -8
  175. package/src/boot/startRecording.js +2 -0
  176. package/src/domain/configuration.js +13 -2
  177. package/src/domain/contexts/urlContexts.js +34 -27
  178. package/src/domain/contexts/viewContexts.js +2 -2
  179. package/src/domain/deflate/deflateWorker.js +35 -21
  180. package/src/domain/privacy.js +93 -157
  181. package/src/domain/replay/record/canvasCommandCapture.js +102 -239
  182. package/src/domain/replay/record/canvasCommandObserver.js +11 -18
  183. package/src/domain/replay/record/canvasCommandObserverStub.js +11 -0
  184. package/src/domain/replay/record/canvasCommandSerializeArgs.js +2 -2
  185. package/src/domain/replay/record/canvasContext.js +18 -0
  186. package/src/domain/replay/record/canvasObserver.js +5 -1
  187. package/src/domain/replay/record/canvasWebGLPluginHost.js +4 -1
  188. package/src/domain/replay/record/mutationObserver.js +6 -22
  189. package/src/domain/replay/record/observers.js +4 -8
  190. package/src/domain/replay/record/record.js +20 -5
  191. package/src/domain/replay/record/serializationUtils.js +10 -33
  192. package/src/domain/replay/record/serialize.js +30 -38
  193. package/src/domain/replay/segmentCollection/buildReplayPayload.js +24 -14
  194. package/src/domain/replay/segmentCollection/segmentCollection.js +97 -227
  195. package/src/domain/replayCanvasSupported.js +1 -0
  196. package/src/domain/requestCollection.js +39 -51
  197. package/src/domain/rumEventsCollection/actions/listenActionEvents.js +8 -2
  198. package/src/domain/rumEventsCollection/resource/fetchTimingRegistry.js +138 -0
  199. package/src/domain/rumEventsCollection/resource/matchRequestResourceEntry.js +2 -2
  200. package/src/domain/rumEventsCollection/resource/resourceCollection.js +103 -88
  201. package/src/domain/rumEventsCollection/resource/resourceTrackerManager.js +10 -10
  202. package/src/domain/rumEventsCollection/resource/resourceUtils.js +41 -69
  203. package/src/domain/rumEventsCollection/resource/retrieveInitialDocumentResourceTiming.js +8 -2
  204. package/src/domain/rumEventsCollection/view/trackCumulativeLayoutShift.js +1 -1
  205. package/src/domain/rumEventsCollection/view/trackViews.js +3 -0
  206. package/src/domain/rumEventsCollection/view/viewCollection.js +2 -3
  207. package/src/domain/tracing/skywalkingTracer.js +14 -91
  208. package/src/domain/tracing/tracer.js +28 -4
  209. package/types/index.d.ts +9 -0
@@ -5,13 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.MAX_UNPUBLISHED_CANVAS_COMMAND_RETENTION_MS = exports.MAX_STRONG_CANVAS_CONTEXT_RESTORE_RECORDS = exports.MAX_PENDING_CANVAS_COMMAND_CONTEXTS = exports.MAX_PENDING_CANVAS_COMMAND_BYTES = exports.MAX_CANVAS_OPAQUE_OBJECT_RESTORE_RECORDS = exports.MAX_CANVAS_COMMAND_BATCH_BYTES = exports.MAX_CANVAS_COMMANDS_PER_BATCH = void 0;
7
7
  exports.createCanvas2DCommandRecorder = createCanvas2DCommandRecorder;
8
+ var _canvasContext = require("./canvasContext");
8
9
  var _browserCore = require("@cloudcare/browser-core");
9
10
  var _canvasCommandSerializeArgs = require("./canvasCommandSerializeArgs");
10
11
  var _canvasMutationRecord = require("./canvasMutationRecord");
11
12
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
13
  var CANVAS_2D_CAPTURED_METHODS = ['save', 'restore', 'translate', 'scale', 'rotate', 'transform', 'setTransform', 'resetTransform', 'reset', 'createLinearGradient', 'createRadialGradient', 'createPattern', 'createConicGradient', 'clearRect', 'fillRect', 'strokeRect', 'rect', 'beginPath', 'moveTo', 'lineTo', 'bezierCurveTo', 'quadraticCurveTo', 'arcTo', 'closePath', 'arc', 'ellipse', 'roundRect', 'clip', 'fill', 'stroke', 'fillText', 'strokeText', 'setLineDash', 'putImageData', 'drawImage'];
13
14
  var CANVAS_2D_CAPTURED_PROPERTIES = ['fillStyle', 'strokeStyle', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'lineDashOffset', 'font', 'globalAlpha', 'globalCompositeOperation', 'imageSmoothingEnabled', 'imageSmoothingQuality', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY', 'textAlign', 'textBaseline', 'direction', 'fontKerning', 'fontStretch', 'fontVariantCaps', 'letterSpacing', 'textRendering', 'wordSpacing', 'filter'];
14
- var CANVAS_2D_NON_MUTATING_METHODS = {
15
+
16
+ // Known API members are handled separately from unknown canvas mutations.
17
+ var knownCanvasMembers = {
15
18
  createImageData: true,
16
19
  getContextAttributes: true,
17
20
  getImageData: true,
@@ -22,13 +25,8 @@ var CANVAS_2D_NON_MUTATING_METHODS = {
22
25
  isPointInStroke: true,
23
26
  measureText: true
24
27
  };
25
- var CANVAS_2D_CAPTURED_METHOD_NAMES = {};
26
- var CANVAS_2D_CAPTURED_PROPERTY_NAMES = {};
27
- CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
28
- CANVAS_2D_CAPTURED_METHOD_NAMES[methodName] = true;
29
- });
30
- CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
31
- CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] = true;
28
+ CANVAS_2D_CAPTURED_METHODS.concat(CANVAS_2D_CAPTURED_PROPERTIES).forEach(function (name) {
29
+ knownCanvasMembers[name] = true;
32
30
  });
33
31
  var UNSUPPORTED_REPLAY_OBJECT_NAMES = {
34
32
  CanvasGradient: true,
@@ -164,9 +162,6 @@ function getTypedArrayElementApproxBytes(value) {
164
162
  }
165
163
  return 25;
166
164
  }
167
- function isSerializedTypedArray(value) {
168
- return value instanceof Float32Array || value instanceof Float64Array || value instanceof Int32Array || value instanceof Uint32Array || value instanceof Uint8Array || value instanceof Uint16Array || value instanceof Int16Array || value instanceof Int8Array || value instanceof Uint8ClampedArray;
169
- }
170
165
  function addTypedArrayApproxBytes(state, value) {
171
166
  var elementCount = value.length;
172
167
  var perElementBytes = getTypedArrayElementApproxBytes(value);
@@ -265,7 +260,7 @@ function estimateCanvasCommand(property, args, setter, limit) {
265
260
  state.fallbackReason = getFallbackReasonForConstructorName(constructorName);
266
261
  break;
267
262
  }
268
- if (isSerializedTypedArray(value)) {
263
+ if ((0, _canvasCommandSerializeArgs.isSerializedTypedArray)(value)) {
269
264
  addTypedArrayApproxBytes(state, value);
270
265
  continue;
271
266
  }
@@ -336,7 +331,8 @@ function isUnsupportedDrawImageSource(value) {
336
331
  }
337
332
  function createCanvas2DCommandRecorder(options) {
338
333
  options = options || {};
339
- var emit = options.emit || function () {};
334
+ var configuration = options.configuration || {};
335
+ var emit = options.emit || _browserCore.noop;
340
336
  var now = false ? options.now || Date.now : Date.now;
341
337
  var requestAnimationFrameImpl = false && options.requestAnimationFrameImpl || function (callback) {
342
338
  return window.requestAnimationFrame(callback);
@@ -359,8 +355,6 @@ function createCanvas2DCommandRecorder(options) {
359
355
  var snapshotFallbackPatchTargets = new WeakSet();
360
356
  var pendingCommandsByContext = new _browserCore.SDKMap();
361
357
  var pendingCommandApproxBytes = 0;
362
- var fallbackModeContexts = new WeakSet();
363
- var persistentFallbackModeContexts = new WeakSet();
364
358
  var fallbackReasonByContext = new WeakMap();
365
359
  var persistentFallbackReasonByContext = new WeakMap();
366
360
  var expiredUnpublishedContexts = new WeakSet();
@@ -378,16 +372,16 @@ function createCanvas2DCommandRecorder(options) {
378
372
  var stopped = false;
379
373
  var paused = false;
380
374
  var objectRefRegistry = false && options.objectRefRegistry || (0, _canvasCommandSerializeArgs.createCanvasCommandObjectRefRegistry)();
381
- var onCommandOverflow = false ? options.onCommandOverflow || function () {} : undefined;
375
+ var onCommandOverflow = false ? options.onCommandOverflow || _browserCore.noop : undefined;
382
376
  var getCanvasId = options.getCanvasId || function (context) {
383
377
  return context && context.canvas && context.canvas.__sn && context.canvas.__sn.id;
384
378
  };
385
379
  var getCanvasType = options.getCanvasType || function () {
386
380
  return '2D';
387
381
  };
388
- var requestSnapshotFallback = options.requestSnapshotFallback || function () {};
389
- var onContextDiscovered = options.onContextDiscovered || function () {};
390
- var onContextMutation = options.onContextMutation || function () {};
382
+ var requestSnapshotFallback = options.requestSnapshotFallback || _browserCore.noop;
383
+ var onContextDiscovered = options.onContextDiscovered || _browserCore.noop;
384
+ var onContextMutation = options.onContextMutation || _browserCore.noop;
391
385
  var shouldRecordContext = options.shouldRecordContext || function () {
392
386
  return true;
393
387
  };
@@ -424,7 +418,7 @@ function createCanvas2DCommandRecorder(options) {
424
418
  return batch;
425
419
  }
426
420
  function isSnapshotFallbackContext(context) {
427
- return fallbackModeContexts.has(context) || persistentFallbackModeContexts.has(context);
421
+ return fallbackReasonByContext.has(context) || persistentFallbackReasonByContext.has(context);
428
422
  }
429
423
  function getSnapshotFallbackReason(context) {
430
424
  return persistentFallbackReasonByContext.get(context) || fallbackReasonByContext.get(context);
@@ -451,7 +445,6 @@ function createCanvas2DCommandRecorder(options) {
451
445
  }
452
446
  function expireUnpublishedBatch(context) {
453
447
  deletePendingBatch(context);
454
- persistentFallbackModeContexts.add(context);
455
448
  expiredUnpublishedContexts.add(context);
456
449
  if (!persistentFallbackReasonByContext.has(context)) {
457
450
  persistentFallbackReasonByContext.set(context, 'canvas_publication_timeout');
@@ -620,11 +613,20 @@ function createCanvas2DCommandRecorder(options) {
620
613
  }
621
614
  scheduleFlush();
622
615
  }
616
+ function discardPrivateCommands(context) {
617
+ if (!(0, _canvasContext.isCanvasPrivate)(context.canvas, configuration)) return false;
618
+ // Private draws change the live bitmap. Resume from pixels when allowed.
619
+ if (!persistentFallbackReasonByContext.has(context) || pendingCommandsByContext.has(context)) {
620
+ markPersistentSnapshotFallback(context, 'canvas_state_reset');
621
+ }
622
+ return true;
623
+ }
623
624
  function flushPendingContext(context, flushedAt) {
624
625
  var batch = pendingCommandsByContext.get(context);
625
626
  if (!batch) {
626
627
  return;
627
628
  }
629
+ if (discardPrivateCommands(context)) return;
628
630
  if (isSnapshotFallbackContext(context)) {
629
631
  if (batch.fallbackDirty && !batch.fallbackSnapshotRequested) {
630
632
  requestSnapshotFallback(context, getSnapshotFallbackReason(context) || 'unsupported_canvas_object');
@@ -717,6 +719,7 @@ function createCanvas2DCommandRecorder(options) {
717
719
  if (!trackedContextSet.has(context)) {
718
720
  return false;
719
721
  }
722
+ if (discardPrivateCommands(context)) return false;
720
723
  if (captureGenerationByContext.get(context) !== captureGeneration) {
721
724
  captureGenerationByContext.set(context, captureGeneration);
722
725
  // reset() accompanies a new replay/full-snapshot canvas baseline, but
@@ -726,6 +729,13 @@ function createCanvas2DCommandRecorder(options) {
726
729
  }
727
730
  return true;
728
731
  }
732
+ function clearContext(context) {
733
+ trackedContextSet["delete"](context);
734
+ deletePendingBatch(context);
735
+ expiredUnpublishedContexts["delete"](context);
736
+ fallbackReasonByContext["delete"](context);
737
+ persistentFallbackReasonByContext["delete"](context);
738
+ }
729
739
  function registerTrackedContext(context, restoreFns) {
730
740
  if (!context || trackedContextSet.has(context)) {
731
741
  return false;
@@ -738,13 +748,7 @@ function createCanvas2DCommandRecorder(options) {
738
748
  trackedContexts.push({
739
749
  context: context,
740
750
  restore: function restore() {
741
- trackedContextSet["delete"](context);
742
- deletePendingBatch(context);
743
- expiredUnpublishedContexts["delete"](context);
744
- fallbackModeContexts["delete"](context);
745
- persistentFallbackModeContexts["delete"](context);
746
- fallbackReasonByContext["delete"](context);
747
- persistentFallbackReasonByContext["delete"](context);
751
+ clearContext(context);
748
752
  while (restoreFns.length) {
749
753
  restoreFns.pop()();
750
754
  }
@@ -760,7 +764,7 @@ function createCanvas2DCommandRecorder(options) {
760
764
  return false;
761
765
  }
762
766
  if (shouldRecordContext(context) === false) {
763
- rejectedContextSet.add(context);
767
+ rejectContext(context);
764
768
  return false;
765
769
  }
766
770
  if (!registerTrackedContext(context, [])) {
@@ -791,19 +795,13 @@ function createCanvas2DCommandRecorder(options) {
791
795
  if (!context) {
792
796
  return;
793
797
  }
798
+ // A hidden region can become visible while the same context stays alive.
799
+ if (discardPrivateCommands(context)) return;
794
800
  rejectedContextSet.add(context);
795
- trackedContextSet["delete"](context);
796
- deletePendingBatch(context);
797
- expiredUnpublishedContexts["delete"](context);
798
- fallbackModeContexts["delete"](context);
799
- persistentFallbackModeContexts["delete"](context);
800
- fallbackReasonByContext["delete"](context);
801
- persistentFallbackReasonByContext["delete"](context);
801
+ clearContext(context);
802
802
  }
803
803
  function enableSnapshotFallbackForContext(context, reason, isGlobalOverflow, persistent) {
804
- var fallbackContexts = persistent ? persistentFallbackModeContexts : fallbackModeContexts;
805
804
  var fallbackReasons = persistent ? persistentFallbackReasonByContext : fallbackReasonByContext;
806
- fallbackContexts.add(context);
807
805
  if (!fallbackReasons.has(context)) {
808
806
  fallbackReasons.set(context, reason || 'unsupported_canvas_object');
809
807
  }
@@ -905,6 +903,34 @@ function createCanvas2DCommandRecorder(options) {
905
903
  }
906
904
  }
907
905
  }
906
+ function recordMutation(context, name, argsOrValue, setter, alwaysSnapshotFallback) {
907
+ notifyContextMutation(context);
908
+ try {
909
+ if (isSnapshotFallbackContext(context)) {
910
+ markSnapshotFallbackDirty(context);
911
+ return false;
912
+ }
913
+ if (alwaysSnapshotFallback) {
914
+ enableSnapshotFallbackForContext(context, setter ? 'unsupported_canvas_property' : 'unsupported_canvas_method', false, true);
915
+ return false;
916
+ }
917
+ } catch (_) {
918
+ return false;
919
+ }
920
+ try {
921
+ var reason = !setter && name === 'drawImage' && isUnsupportedDrawImageSource(argsOrValue[0]);
922
+ if (reason) {
923
+ enableSnapshotFallbackForContext(context, reason);
924
+ } else {
925
+ captureCommand(context, name, setter ? [argsOrValue] : argsOrValue, setter);
926
+ }
927
+ } catch (_) {
928
+ try {
929
+ enableSnapshotFallbackForContext(context, 'command_serialization_error');
930
+ } catch (_) {}
931
+ }
932
+ return true;
933
+ }
908
934
  function patchMethodOnTarget(target, methodName, restoreFns, alwaysSnapshotFallback) {
909
935
  if (typeof target[methodName] !== 'function') {
910
936
  return false;
@@ -914,40 +940,7 @@ function createCanvas2DCommandRecorder(options) {
914
940
  maybeTrackContext(this);
915
941
  var shouldCapture = shouldCaptureContext(this);
916
942
  var result = originalMethod.apply(this, arguments);
917
- if (shouldCapture) {
918
- notifyContextMutation(this);
919
- }
920
- if (shouldCapture && alwaysSnapshotFallback) {
921
- try {
922
- if (isSnapshotFallbackContext(this)) {
923
- markSnapshotFallbackDirty(this);
924
- } else {
925
- enableSnapshotFallbackForContext(this, 'unsupported_canvas_method', false, true);
926
- }
927
- } catch (_) {}
928
- return result;
929
- }
930
- if (shouldCapture && isSnapshotFallbackContext(this)) {
931
- try {
932
- markSnapshotFallbackDirty(this);
933
- } catch (_) {}
934
- return result;
935
- }
936
- if (shouldCapture) {
937
- try {
938
- var drawImageFallbackReason = methodName === 'drawImage' ? isUnsupportedDrawImageSource(arguments[0]) : undefined;
939
- if (drawImageFallbackReason) {
940
- enableSnapshotFallbackForContext(this, drawImageFallbackReason);
941
- } else {
942
- captureCommand(this, methodName, arguments, false);
943
- }
944
- } catch (_) {
945
- try {
946
- enableSnapshotFallbackForContext(this, 'command_serialization_error');
947
- } catch (_) {}
948
- }
949
- }
950
- if (shouldCapture && (methodName === 'createLinearGradient' || methodName === 'createRadialGradient' || methodName === 'createConicGradient')) {
943
+ if (shouldCapture && recordMutation(this, methodName, arguments, false, alwaysSnapshotFallback) && (methodName === 'createLinearGradient' || methodName === 'createRadialGradient' || methodName === 'createConicGradient')) {
951
944
  patchGradientObjectMethods(result, this);
952
945
  }
953
946
  return result;
@@ -985,32 +978,8 @@ function createCanvas2DCommandRecorder(options) {
985
978
  if (originalDescriptor && originalDescriptor.set) {
986
979
  originalDescriptor.set.call(this, value);
987
980
  }
988
- var shouldCapture = shouldCaptureContext(this);
989
- if (shouldCapture) {
990
- notifyContextMutation(this);
991
- if (alwaysSnapshotFallback) {
992
- try {
993
- if (isSnapshotFallbackContext(this)) {
994
- markSnapshotFallbackDirty(this);
995
- } else {
996
- enableSnapshotFallbackForContext(this, 'unsupported_canvas_property', false, true);
997
- }
998
- } catch (_) {}
999
- return;
1000
- }
1001
- if (isSnapshotFallbackContext(this)) {
1002
- try {
1003
- markSnapshotFallbackDirty(this);
1004
- } catch (_) {}
1005
- return;
1006
- }
1007
- try {
1008
- captureCommand(this, propertyName, [value], true);
1009
- } catch (_) {
1010
- try {
1011
- enableSnapshotFallbackForContext(this, 'command_serialization_error');
1012
- } catch (_) {}
1013
- }
981
+ if (shouldCaptureContext(this)) {
982
+ recordMutation(this, propertyName, value, true, alwaysSnapshotFallback);
1014
983
  }
1015
984
  };
1016
985
  try {
@@ -1045,7 +1014,7 @@ function createCanvas2DCommandRecorder(options) {
1045
1014
  return;
1046
1015
  }
1047
1016
  propertyNames.forEach(function (propertyName) {
1048
- if (propertyName === 'constructor' || CANVAS_2D_CAPTURED_METHOD_NAMES[propertyName] || CANVAS_2D_CAPTURED_PROPERTY_NAMES[propertyName] || CANVAS_2D_NON_MUTATING_METHODS[propertyName]) {
1017
+ if (propertyName === 'constructor' || knownCanvasMembers[propertyName]) {
1049
1018
  return;
1050
1019
  }
1051
1020
  var descriptor;
@@ -1066,42 +1035,6 @@ function createCanvas2DCommandRecorder(options) {
1066
1035
  }
1067
1036
  });
1068
1037
  }
1069
- function patchPrototype(context) {
1070
- var prototype = Object.getPrototypeOf(context);
1071
- if (!prototype || prototype === Object.prototype) {
1072
- return false;
1073
- }
1074
- var existingRecord = patchedPrototypeRecords.find(function (record) {
1075
- return record.prototype === prototype;
1076
- });
1077
- if (existingRecord) {
1078
- return true;
1079
- }
1080
- if (patchedPrototypeRecords.length >= MAX_PATCHED_CANVAS_PROTOTYPE_RECORDS) {
1081
- return false;
1082
- }
1083
- var restoreFns = [];
1084
- CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
1085
- if (typeof prototype[methodName] === 'function' && !patchMethodOnTarget(prototype, methodName, restoreFns)) {
1086
- snapshotFallbackPatchTargets.add(prototype);
1087
- }
1088
- });
1089
- CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
1090
- if (getPropertyDescriptor(prototype, propertyName) && !patchPropertyOnTarget(prototype, propertyName, restoreFns)) {
1091
- snapshotFallbackPatchTargets.add(prototype);
1092
- }
1093
- });
1094
- patchUnknownMutationsOnTarget(prototype, restoreFns);
1095
- patchedPrototypeRecords.push({
1096
- prototype: prototype,
1097
- restore: function restore() {
1098
- while (restoreFns.length) {
1099
- restoreFns.pop()();
1100
- }
1101
- }
1102
- });
1103
- return true;
1104
- }
1105
1038
  function patchSharedPrototype(prototype) {
1106
1039
  if (!prototype || prototype === Object.prototype) {
1107
1040
  return false;
@@ -1116,17 +1049,7 @@ function createCanvas2DCommandRecorder(options) {
1116
1049
  return false;
1117
1050
  }
1118
1051
  var restoreFns = [];
1119
- CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
1120
- if (typeof prototype[methodName] === 'function' && !patchMethodOnTarget(prototype, methodName, restoreFns)) {
1121
- snapshotFallbackPatchTargets.add(prototype);
1122
- }
1123
- });
1124
- CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
1125
- if (getPropertyDescriptor(prototype, propertyName) && !patchPropertyOnTarget(prototype, propertyName, restoreFns)) {
1126
- snapshotFallbackPatchTargets.add(prototype);
1127
- }
1128
- });
1129
- patchUnknownMutationsOnTarget(prototype, restoreFns);
1052
+ patchContextTarget(prototype, restoreFns, true);
1130
1053
  patchedPrototypeRecords.push({
1131
1054
  prototype: prototype,
1132
1055
  restore: function restore() {
@@ -1137,49 +1060,43 @@ function createCanvas2DCommandRecorder(options) {
1137
1060
  });
1138
1061
  return true;
1139
1062
  }
1140
- function patchContextInstance(context, restoreFns) {
1063
+ function patchContextTarget(target, restoreFns, isPrototype) {
1141
1064
  CANVAS_2D_CAPTURED_METHODS.forEach(function (methodName) {
1142
- if (typeof context[methodName] === 'function' && !patchMethodOnTarget(context, methodName, restoreFns)) {
1143
- snapshotFallbackPatchTargets.add(context);
1065
+ if (typeof target[methodName] === 'function' && !patchMethodOnTarget(target, methodName, restoreFns)) {
1066
+ snapshotFallbackPatchTargets.add(target);
1144
1067
  }
1145
1068
  });
1146
1069
  CANVAS_2D_CAPTURED_PROPERTIES.forEach(function (propertyName) {
1147
- if (!patchPropertyOnTarget(context, propertyName, restoreFns)) {
1148
- snapshotFallbackPatchTargets.add(context);
1070
+ if ((!isPrototype || getPropertyDescriptor(target, propertyName)) && !patchPropertyOnTarget(target, propertyName, restoreFns)) {
1071
+ snapshotFallbackPatchTargets.add(target);
1149
1072
  }
1150
1073
  });
1151
- patchUnknownMutationsOnTarget(context, restoreFns);
1074
+ patchUnknownMutationsOnTarget(target, restoreFns);
1152
1075
  }
1153
1076
  function patchContext(context) {
1154
1077
  if (stopped || !context || trackedContextSet.has(context)) {
1155
- return function () {};
1078
+ return _browserCore.noop;
1156
1079
  }
1157
1080
  var restoreFns = [];
1158
1081
  var prototype = Object.getPrototypeOf(context);
1159
1082
  if (prototype && prototype !== Object.prototype) {
1160
- if (!patchPrototype(context)) {
1161
- return function () {};
1083
+ if (!patchSharedPrototype(prototype)) {
1084
+ return _browserCore.noop;
1162
1085
  }
1163
1086
  } else {
1164
- patchContextInstance(context, restoreFns);
1087
+ patchContextTarget(context, restoreFns, false);
1165
1088
  }
1166
1089
  if (!registerTrackedContext(context, restoreFns)) {
1167
1090
  while (restoreFns.length) {
1168
1091
  restoreFns.pop()();
1169
1092
  }
1170
- return function () {};
1093
+ return _browserCore.noop;
1171
1094
  }
1172
1095
  if (snapshotFallbackPatchTargets.has(context) || prototype && snapshotFallbackPatchTargets.has(prototype)) {
1173
1096
  enableSnapshotFallbackForContext(context, 'unpatchable_canvas_api', false, true);
1174
1097
  }
1175
1098
  return function () {
1176
- trackedContextSet["delete"](context);
1177
- deletePendingBatch(context);
1178
- expiredUnpublishedContexts["delete"](context);
1179
- fallbackModeContexts["delete"](context);
1180
- persistentFallbackModeContexts["delete"](context);
1181
- fallbackReasonByContext["delete"](context);
1182
- persistentFallbackReasonByContext["delete"](context);
1099
+ clearContext(context);
1183
1100
  var trackedIndex = trackedContexts.findIndex(function (tracked) {
1184
1101
  return tracked.context === context;
1185
1102
  });
@@ -1195,8 +1112,6 @@ function createCanvas2DCommandRecorder(options) {
1195
1112
  scheduledFlushId = undefined;
1196
1113
  }
1197
1114
  clearPendingBatches();
1198
- fallbackModeContexts = new WeakSet();
1199
- persistentFallbackModeContexts = new WeakSet();
1200
1115
  fallbackReasonByContext = new WeakMap();
1201
1116
  persistentFallbackReasonByContext = new WeakMap();
1202
1117
  expiredUnpublishedContexts = new WeakSet();
@@ -1213,32 +1128,26 @@ function createCanvas2DCommandRecorder(options) {
1213
1128
  captureGenerationByContext = new WeakMap();
1214
1129
  objectRefRegistry.reset();
1215
1130
  }
1216
- function pause() {
1217
- paused = true;
1131
+ function resetPendingCapture() {
1218
1132
  if (scheduledFlushId !== undefined) {
1219
1133
  cancelAnimationFrameImpl(scheduledFlushId);
1220
1134
  scheduledFlushId = undefined;
1221
1135
  }
1222
1136
  clearPendingBatches();
1223
- fallbackModeContexts = new WeakSet();
1224
1137
  fallbackReasonByContext = new WeakMap();
1225
1138
  rejectedContextSet = new WeakSet();
1226
1139
  objectRefRegistry.reset();
1227
1140
  }
1141
+ function pause() {
1142
+ paused = true;
1143
+ resetPendingCapture();
1144
+ }
1228
1145
  function resume() {
1229
1146
  paused = false;
1230
1147
  }
1231
1148
  function reset() {
1232
1149
  captureGeneration += 1;
1233
- if (scheduledFlushId !== undefined) {
1234
- cancelAnimationFrameImpl(scheduledFlushId);
1235
- scheduledFlushId = undefined;
1236
- }
1237
- clearPendingBatches();
1238
- fallbackModeContexts = new WeakSet();
1239
- fallbackReasonByContext = new WeakMap();
1240
- rejectedContextSet = new WeakSet();
1241
- objectRefRegistry.reset();
1150
+ resetPendingCapture();
1242
1151
  }
1243
1152
  function forceSnapshotFallback(context, reason) {
1244
1153
  if (stopped || !trackedContextSet.has(context)) {
@@ -1255,7 +1164,6 @@ function createCanvas2DCommandRecorder(options) {
1255
1164
  return;
1256
1165
  }
1257
1166
  expiredUnpublishedContexts["delete"](context);
1258
- persistentFallbackModeContexts.add(context);
1259
1167
  if (!persistentFallbackReasonByContext.has(context)) {
1260
1168
  persistentFallbackReasonByContext.set(context, reason || 'persistent_snapshot_fallback');
1261
1169
  }