Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/rrweb/src/record/observers/canvas/canvas-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export class CanvasManager {
dw: element.width,
dh: element.height,
dataURLOptions: this.options.dataURLOptions,
logDebug: !!this.logger,
},
[bitmap],
);
Expand Down Expand Up @@ -454,6 +455,7 @@ export class CanvasManager {
dw: outputWidth,
dh: outputHeight,
dataURLOptions: options.dataURLOptions,
logDebug: !!this.logger,
},
[bitmap],
);
Expand Down
17 changes: 12 additions & 5 deletions packages/rrweb/src/record/workers/image-bitmap-data-url-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ async function getTransparentBlobFor(
}
}

// `as any` because: https://github.com/Microsoft/TypeScript/issues/20595
const worker: ImageBitmapDataURLResponseWorker = self;
let logDebug: boolean = false;

const debug = (...args: any[]) => {
if (logDebug) {
console.debug(...args);
}
};

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

// unchanged
if (lastBlobMap.get(id) === base64) {
console.debug('[highlight-worker] canvas bitmap is unchanged', {
debug('[highlight-worker] canvas bitmap is unchanged', {
id,
base64,
});
return worker.postMessage({ id, status: 'unchanged' });
}
console.debug('[highlight-worker] canvas bitmap processed', {
debug('[highlight-worker] canvas bitmap processed', {
id,
base64,
});
Expand All @@ -104,7 +111,7 @@ worker.onmessage = async function (e) {
});
lastBlobMap.set(id, base64);
} else {
console.debug('[highlight-worker] no offscreencanvas support', {
debug('[highlight-worker] no offscreencanvas support', {
id: e.data.id,
});
return worker.postMessage({ id: e.data.id, status: 'unsupported' });
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ export type ImageBitmapDataURLWorkerParams = {
dy: number;
dw: number;
dh: number;
logDebug?: boolean;
};

export type ImageBitmapDataURLWorkerResponse =
Expand Down