Skip to content

Commit 9763d68

Browse files
committed
remove debug logging in canvas worker (#109)
Recent snapshot improvements introduced debug logging that is noisy. This change defaults to no canvas web-worker logging but allows using the `debug` H.init setting to enable it.
1 parent 3463256 commit 9763d68

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

packages/rrweb/src/record/observers/canvas/canvas-manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class CanvasManager {
302302
dw: canvas.width,
303303
dh: canvas.height,
304304
dataURLOptions: this.options.dataURLOptions,
305+
logDebug: !!this.logger,
305306
},
306307
[bitmap],
307308
);
@@ -468,6 +469,7 @@ export class CanvasManager {
468469
dw: outputWidth,
469470
dh: outputHeight,
470471
dataURLOptions: options.dataURLOptions,
472+
logDebug: !!this.logger,
471473
},
472474
[bitmap],
473475
);

packages/rrweb/src/record/workers/image-bitmap-data-url-worker.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ async function getTransparentBlobFor(
4343
}
4444
}
4545

46-
// `as any` because: https://github.com/Microsoft/TypeScript/issues/20595
4746
const worker: ImageBitmapDataURLResponseWorker = self;
47+
let logDebug: boolean = false;
48+
49+
const debug = (...args: any[]) => {
50+
if (logDebug) {
51+
console.debug(...args);
52+
}
53+
};
4854

4955
// eslint-disable-next-line @typescript-eslint/no-misused-promises
5056
worker.onmessage = async function (e) {
57+
logDebug = !!e.data.logDebug;
5158
if ('OffscreenCanvas' in globalThis) {
5259
const { id, bitmap, width, height, dx, dy, dw, dh, dataURLOptions } =
5360
e.data;
@@ -71,7 +78,7 @@ worker.onmessage = async function (e) {
7178
// on first try we should check if canvas is transparent,
7279
// no need to save it's contents in that case
7380
if (!lastBlobMap.has(id) && (await transparentBase64) === base64) {
74-
console.debug('[highlight-worker] canvas bitmap is transparent', {
81+
debug('[highlight-worker] canvas bitmap is transparent', {
7582
id,
7683
base64,
7784
});
@@ -81,13 +88,13 @@ worker.onmessage = async function (e) {
8188

8289
// unchanged
8390
if (lastBlobMap.get(id) === base64) {
84-
console.debug('[highlight-worker] canvas bitmap is unchanged', {
91+
debug('[highlight-worker] canvas bitmap is unchanged', {
8592
id,
8693
base64,
8794
});
8895
return worker.postMessage({ id, status: 'unchanged' });
8996
}
90-
console.debug('[highlight-worker] canvas bitmap processed', {
97+
debug('[highlight-worker] canvas bitmap processed', {
9198
id,
9299
base64,
93100
});
@@ -104,7 +111,7 @@ worker.onmessage = async function (e) {
104111
});
105112
lastBlobMap.set(id, base64);
106113
} else {
107-
console.debug('[highlight-worker] no offscreencanvas support', {
114+
debug('[highlight-worker] no offscreencanvas support', {
108115
id: e.data.id,
109116
});
110117
return worker.postMessage({ id: e.data.id, status: 'unsupported' });

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ export type ImageBitmapDataURLWorkerParams = {
568568
dy: number;
569569
dw: number;
570570
dh: number;
571+
logDebug?: boolean;
571572
};
572573

573574
export type ImageBitmapDataURLWorkerResponse =

0 commit comments

Comments
 (0)