From 8df3133af5dacbb0b477c080c43948fa4b6df932 Mon Sep 17 00:00:00 2001 From: Christopher Arredondo Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] fix: Validate if WebGLRenderingContext exists before capturing it (#1777) * Update webgl.ts --------- Co-authored-by: Paul D'Ambra Co-authored-by: Justin Halsall --- .changeset/healthy-glasses-shout.md | 5 +++++ .../src/record/observers/canvas/webgl.ts | 22 ++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 .changeset/healthy-glasses-shout.md diff --git a/.changeset/healthy-glasses-shout.md b/.changeset/healthy-glasses-shout.md new file mode 100644 index 00000000..43a475d0 --- /dev/null +++ b/.changeset/healthy-glasses-shout.md @@ -0,0 +1,5 @@ +--- +"@rrweb/record": patch +--- + +Validate if WebGLRenderingContext exists before capturing it diff --git a/packages/rrweb/src/record/observers/canvas/webgl.ts b/packages/rrweb/src/record/observers/canvas/webgl.ts index 3c51323b..3a2bb362 100644 --- a/packages/rrweb/src/record/observers/canvas/webgl.ts +++ b/packages/rrweb/src/record/observers/canvas/webgl.ts @@ -95,16 +95,18 @@ export default function initCanvasWebGLMutationObserver( ): listenerHandler { const handlers: listenerHandler[] = []; - handlers.push( - ...patchGLPrototype( - win.WebGLRenderingContext.prototype, - CanvasContext.WebGL, - cb, - blockClass, - blockSelector, - win, - ), - ); + if (typeof win.WebGLRenderingContext !== 'undefined') { + handlers.push( + ...patchGLPrototype( + win.WebGLRenderingContext.prototype, + CanvasContext.WebGL, + cb, + blockClass, + blockSelector, + win, + ), + ); + } if (typeof win.WebGL2RenderingContext !== 'undefined') { handlers.push(