Skip to content

Commit

Permalink
feat: Register errorHandler inside of CanvasManager (#161)
Browse files Browse the repository at this point in the history
Needed as we (Sentry), codesplit CanvasManager. Also fixes uncaught
exceptions from `createImageBitmap`

---------

Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
  • Loading branch information
billyvg and Lms24 authored Jan 31, 2024
1 parent 04b3de5 commit c79619f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ function record<T = eventWithTime>(
unblockSelector,
sampling: sampling['canvas'],
dataURLOptions,
errorHandler,
},
);

Expand Down
11 changes: 9 additions & 2 deletions packages/rrweb/src/record/observers/canvas/canvas-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c79619f

Please sign in to comment.