From ec4913f38998089a21f0dde080600cbb4ccc341a Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Wed, 31 Jan 2024 12:35:29 -0330 Subject: [PATCH] feat: Register `errorHandler` inside of CanvasManager (#161) Needed as we (Sentry), codesplit CanvasManager. Also fixes uncaught exceptions from `createImageBitmap` --------- Co-authored-by: Lukas Stracke --- packages/rrweb/src/record/index.ts | 1 + .../src/record/observers/canvas/canvas-manager.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/rrweb/src/record/index.ts b/packages/rrweb/src/record/index.ts index b572d578aa..ca7cec2702 100644 --- a/packages/rrweb/src/record/index.ts +++ b/packages/rrweb/src/record/index.ts @@ -347,6 +347,7 @@ function record( unblockSelector, sampling: sampling['canvas'], dataURLOptions, + errorHandler, }, ); diff --git a/packages/rrweb/src/record/observers/canvas/canvas-manager.ts b/packages/rrweb/src/record/observers/canvas/canvas-manager.ts index 1dacf6d0f0..d5f45d8044 100644 --- a/packages/rrweb/src/record/observers/canvas/canvas-manager.ts +++ b/packages/rrweb/src/record/observers/canvas/canvas-manager.ts @@ -20,7 +20,8 @@ import initCanvas2DMutationObserver from './2d'; import initCanvasContextObserver from './canvas'; import initCanvasWebGLMutationObserver from './webgl'; import { getImageBitmapDataUrlWorkerURL } from '@sentry-internal/rrweb-worker'; -import { callbackWrapper } from '../../error-handler'; +import { callbackWrapper, registerErrorHandler } from '../../error-handler'; +import type { ErrorHandler } from '../../../types'; export type RafStamps = { latestId: number; invokeId: number | null }; @@ -47,8 +48,9 @@ export interface CanvasManagerConstructorOptions { blockSelector: string | null; unblockSelector: string | null; mirror: Mirror; - sampling?: 'all' | number; dataURLOptions: DataURLOptions; + errorHandler?: ErrorHandler; + sampling?: 'all' | number; } export class CanvasManagerNoop implements CanvasManagerInterface { @@ -113,11 +115,16 @@ export class CanvasManager implements CanvasManagerInterface { unblockSelector, recordCanvas, dataURLOptions, + errorHandler, } = options; this.mutationCb = options.mutationCb; this.mirror = options.mirror; this.options = options; + if (errorHandler) { + registerErrorHandler(errorHandler); + } + if (options.enableManualSnapshot) { return; }