@kalayanasundaram123/rrweb 2.0.3 → 2.0.4
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/rrweb.cjs +66 -3
- package/dist/rrweb.cjs.map +1 -1
- package/dist/rrweb.js +66 -3
- package/dist/rrweb.js.map +1 -1
- package/dist/rrweb.umd.cjs +64 -3
- package/dist/rrweb.umd.cjs.map +2 -2
- package/dist/rrweb.umd.min.cjs +34 -15
- package/dist/rrweb.umd.min.cjs.map +3 -3
- package/package.json +1 -1
- package/umd/rrweb.js +64 -3
- package/umd/rrweb.min.js +34 -15
package/package.json
CHANGED
package/umd/rrweb.js
CHANGED
|
@@ -13972,6 +13972,26 @@ function fnv1aHash(buffer) {
|
|
|
13972
13972
|
function canSnapshotCanvas() {
|
|
13973
13973
|
return typeof OffscreenCanvas !== "undefined";
|
|
13974
13974
|
}
|
|
13975
|
+
const FPS_WORKER_SOURCE = `
|
|
13976
|
+
var _C='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
13977
|
+
function _enc(ab){var b=new Uint8Array(ab),i,n=b.length,o='';for(i=0;i<n;i+=3){o+=_C[b[i]>>2];o+=_C[(b[i]&3)<<4|b[i+1]>>4];o+=_C[(b[i+1]&15)<<2|b[i+2]>>6];o+=_C[b[i+2]&63];}if(n%3===2){o=o.substring(0,o.length-1)+'=';}else if(n%3===1){o=o.substring(0,o.length-2)+'==';}return o;}
|
|
13978
|
+
function _fp(ab){var v=new Uint8Array(ab),h=0x811c9dc5;for(var i=0;i<v.length;i++){h^=v[i];h=(h*0x01000193)|0;}return (h>>>0).toString(16);}
|
|
13979
|
+
var _last=new Map(),_cv=null,_ctx=null;
|
|
13980
|
+
self.onmessage=async function(e){
|
|
13981
|
+
var d=e.data,id=d.id,bm=d.bitmap,w=d.width,h=d.height,opt=d.dataURLOptions;
|
|
13982
|
+
try{
|
|
13983
|
+
if(!('OffscreenCanvas' in self)){bm.close();return self.postMessage({id:id});}
|
|
13984
|
+
if(!_cv||_cv.width!==w||_cv.height!==h){_cv=new OffscreenCanvas(w,h);_ctx=_cv.getContext('2d');}
|
|
13985
|
+
_ctx.clearRect(0,0,w,h);_ctx.drawImage(bm,0,0);bm.close();
|
|
13986
|
+
var blob=await _cv.convertToBlob(opt);
|
|
13987
|
+
var buf=await blob.arrayBuffer();
|
|
13988
|
+
var fp=_fp(buf);
|
|
13989
|
+
if(_last.get(id)===fp)return self.postMessage({id:id});
|
|
13990
|
+
_last.set(id,fp);
|
|
13991
|
+
self.postMessage({id:id,type:blob.type,base64:_enc(buf),width:w,height:h});
|
|
13992
|
+
}catch(err){try{bm.close();}catch(_){}self.postMessage({id:id});}
|
|
13993
|
+
};
|
|
13994
|
+
`;
|
|
13975
13995
|
class CanvasManager {
|
|
13976
13996
|
constructor(options) {
|
|
13977
13997
|
__publicField(this, "pendingCanvasMutations", /* @__PURE__ */ new Map());
|
|
@@ -13989,6 +14009,7 @@ class CanvasManager {
|
|
|
13989
14009
|
__publicField(this, "lastFingerprintMap", /* @__PURE__ */ new Map());
|
|
13990
14010
|
__publicField(this, "snapshotCanvas", null);
|
|
13991
14011
|
__publicField(this, "snapshotCtx", null);
|
|
14012
|
+
__publicField(this, "worker", null);
|
|
13992
14013
|
__publicField(this, "lastSnapshotTime", 0);
|
|
13993
14014
|
__publicField(this, "processMutation", (target, mutation) => {
|
|
13994
14015
|
const newFrame = this.rafStamps.invokeId && this.rafStamps.latestId !== this.rafStamps.invokeId;
|
|
@@ -14010,10 +14031,12 @@ class CanvasManager {
|
|
|
14010
14031
|
this.startPendingCanvasMutationFlusher();
|
|
14011
14032
|
}
|
|
14012
14033
|
if (recordCanvas && typeof sampling === "number" && canSnapshotCanvas()) {
|
|
14034
|
+
this.worker = this.initFPSWorker();
|
|
14013
14035
|
this.initCanvasFPSObserver();
|
|
14014
14036
|
}
|
|
14015
14037
|
}
|
|
14016
14038
|
reset() {
|
|
14039
|
+
var _a2;
|
|
14017
14040
|
this.pendingCanvasMutations.clear();
|
|
14018
14041
|
this.restoreHandlers.forEach((handler) => {
|
|
14019
14042
|
try {
|
|
@@ -14029,6 +14052,8 @@ class CanvasManager {
|
|
|
14029
14052
|
this.lastFingerprintMap = /* @__PURE__ */ new Map();
|
|
14030
14053
|
this.snapshotCanvas = null;
|
|
14031
14054
|
this.snapshotCtx = null;
|
|
14055
|
+
(_a2 = this.worker) == null ? void 0 : _a2.terminate();
|
|
14056
|
+
this.worker = null;
|
|
14032
14057
|
}
|
|
14033
14058
|
freeze() {
|
|
14034
14059
|
this.frozen = true;
|
|
@@ -14042,6 +14067,29 @@ class CanvasManager {
|
|
|
14042
14067
|
unlock() {
|
|
14043
14068
|
this.locked = false;
|
|
14044
14069
|
}
|
|
14070
|
+
initFPSWorker() {
|
|
14071
|
+
try {
|
|
14072
|
+
const worker = new Worker(
|
|
14073
|
+
"data:application/javascript;charset=utf-8," + encodeURIComponent(FPS_WORKER_SOURCE)
|
|
14074
|
+
);
|
|
14075
|
+
worker.onmessage = (e2) => {
|
|
14076
|
+
const data = e2.data;
|
|
14077
|
+
const { id } = data;
|
|
14078
|
+
this.snapshotInProgressMap.set(id, false);
|
|
14079
|
+
if (data.base64 === void 0) return;
|
|
14080
|
+
this.emitCanvasSnapshot(
|
|
14081
|
+
id,
|
|
14082
|
+
data.base64,
|
|
14083
|
+
data.type || "image/png",
|
|
14084
|
+
data.width || 0,
|
|
14085
|
+
data.height || 0
|
|
14086
|
+
);
|
|
14087
|
+
};
|
|
14088
|
+
return worker;
|
|
14089
|
+
} catch (e2) {
|
|
14090
|
+
return null;
|
|
14091
|
+
}
|
|
14092
|
+
}
|
|
14045
14093
|
/**
|
|
14046
14094
|
* Begin observing canvas activity inside `win` — the top window, or the
|
|
14047
14095
|
* `contentWindow` of a same-origin iframe. De-duplicated, so it is safe to
|
|
@@ -14248,9 +14296,22 @@ class CanvasManager {
|
|
|
14248
14296
|
}
|
|
14249
14297
|
const width = canvas.width;
|
|
14250
14298
|
const height = canvas.height;
|
|
14251
|
-
createImageBitmap(canvas).then(
|
|
14252
|
-
(
|
|
14253
|
-
|
|
14299
|
+
createImageBitmap(canvas).then((bitmap) => {
|
|
14300
|
+
if (this.worker) {
|
|
14301
|
+
this.worker.postMessage(
|
|
14302
|
+
{ id, bitmap, width, height, dataURLOptions },
|
|
14303
|
+
[bitmap]
|
|
14304
|
+
);
|
|
14305
|
+
} else {
|
|
14306
|
+
void this.snapshotImageBitmap(
|
|
14307
|
+
id,
|
|
14308
|
+
bitmap,
|
|
14309
|
+
width,
|
|
14310
|
+
height,
|
|
14311
|
+
dataURLOptions
|
|
14312
|
+
);
|
|
14313
|
+
}
|
|
14314
|
+
}).catch(() => {
|
|
14254
14315
|
this.snapshotInProgressMap.set(id, false);
|
|
14255
14316
|
});
|
|
14256
14317
|
});
|