Skip to content

fix: Validate if WebGLRenderingContext exists before capturing it#1777

Merged
Juice10 merged 10 commits intorrweb-io:masterfrom
arredgroup:patch-1
Feb 6, 2026
Merged

fix: Validate if WebGLRenderingContext exists before capturing it#1777
Juice10 merged 10 commits intorrweb-io:masterfrom
arredgroup:patch-1

Conversation

@arredgroup
Copy link
Contributor

@arredgroup arredgroup commented Jan 30, 2026

Remove handlers.push because if WebGL2RenderingContext is undefined will fail is duplicated logic with post validation

Edit: Validate if WebGLRenderingContext exists before trying to capture it

Remove handlers.push because if WebGL2RenderingContext is undefined will fail
@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

🦋 Changeset detected

Latest commit: f1c6ba0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@rrweb/record Patch
rrweb Patch
rrweb-snapshot Patch
rrdom Patch
rrdom-nodejs Patch
rrweb-player Patch
@rrweb/all Patch
@rrweb/replay Patch
@rrweb/types Patch
@rrweb/packer Patch
@rrweb/utils Patch
@rrweb/web-extension Patch
rrvideo Patch
@rrweb/rrweb-plugin-console-record Patch
@rrweb/rrweb-plugin-console-replay Patch
@rrweb/rrweb-plugin-sequential-id-record Patch
@rrweb/rrweb-plugin-sequential-id-replay Patch
@rrweb/rrweb-plugin-canvas-webrtc-record Patch
@rrweb/rrweb-plugin-canvas-webrtc-replay Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

): listenerHandler {
const handlers: listenerHandler[] = [];

handlers.push(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe i'm being silly, but this block isn't a straight duplicate of the block in the conditional below

could you share the errors you were seeing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I received: Undefined is not a object in WebGLRenderingContext.prototype

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i suppose the problem here is we're treating all the different RenderingContexts as definitely available when they're not

so each of these handler pushes should be validating presence?

surprising it wasn't there... do you know what browser this was or what stacktrace the error had

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!, this happen in iOS (webview and safari) the stacktrace mentions Undefined is not a object in WebGLRenderingContext.prototype

Copy link
Member

@Juice10 Juice10 Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this isn't a duplicate of the code below (although hard to see because there is only one char difference).

This has to do with WebGL One (aka WebGL without a number), the code below with WebGL Two (aka WebGL2). Some older browser didn't support webgl2 so I added an explicit check for it. But I assumed all browsers rrweb supports, also support WebGL 1. So I didn't add a check for it. We could do exactly as the if statement does below where we check if its available before we try to patch it, that's no problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not showing updated code for me 🙈

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, no... i see
you've put it in the wrong block

@arredgroup arredgroup changed the title [FIX] Remove undefined error when WebGL2RenderingContext not exists fix: Remove undefined error when WebGL2RenderingContext not exists Feb 3, 2026
Co-authored-by: Paul D'Ambra <paul.dambra@gmail.com>
Copy link
Contributor Author

@arredgroup arredgroup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right

@arredgroup arredgroup requested a review from pauldambra February 3, 2026 17:28
Copy link
Contributor

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks ok to me now
i gues it needs a changeset

i don't have edit rights but the PR title / description need updating too :)

Copy link
Member

@Juice10 Juice10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close, als Paul says alls we have to do is fix formatting and update title/description of the PR and add a changeset

Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com>
@Juice10 Juice10 changed the title fix: Remove undefined error when WebGL2RenderingContext not exists fix: Validate if WebGLRenderingContext exists before capturing it Feb 6, 2026
@Juice10 Juice10 merged commit 3b8daa6 into rrweb-io:master Feb 6, 2026
6 checks passed
pauldambra added a commit to PostHog/posthog-rrweb that referenced this pull request Mar 24, 2026
## Summary

Adopts upstream rrweb PR rrweb-io/rrweb#1777

Some browsers (notably iOS Safari/WebView) don't support WebGL 1, causing a crash when accessing `WebGLRenderingContext.prototype` unconditionally. This adds the same `typeof` guard already used for `WebGL2RenderingContext`.

## Changes
- `packages/rrweb/src/record/observers/canvas/webgl.ts` — wrap `WebGLRenderingContext.prototype` access in `typeof` check

## Test plan
- [ ] CI passes
- [ ] No regression in WebGL canvas recording tests

Related issue: #147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants