Open
Conversation
Adds support for configuring WebGL context attributes on web platform,
particularly useful for enabling preserveDrawingBuffer for canvas capture
scenarios like screenshots or image exports.
- Add webglContextAttributes prop to CanvasProps and SkiaBaseViewProps
- Implement context attribute conversion (boolean to 0/1) in SkiaBaseWebView
- Pass attributes to CanvasKit.MakeWebGLCanvasSurface
- Web-only feature, ignored on native platforms
Example usage:
<Canvas
webglContextAttributes={{
preserveDrawingBuffer: true,
alpha: true,
antialias: true
}}
>
{/* Canvas content */}
</Canvas>
-update our context attribute types to be specific -respect linting, no nested ternaries
wcandillon
requested changes
Sep 5, 2025
Contributor
wcandillon
left a comment
There was a problem hiding this comment.
I like it a lot.
Let's use WebGLOptions type directly from canvaskit (and not even do the boolean conversion).
Contributor
|
and there is the CLA to be signed of course :) |
-don't cast to bool
Author
|
@wcandillon adjusted to use WebGLOptions directly with no casting -- going to check in with our legal team to see if they will require me to sign corporate CLA or if I can go individual |
Contributor
|
@gabenovig I have an exciting refactoring at #3349 if you want I can add the change there myself (that would take care of the CLA issue). The downside is that you wouldn't get commit authorship on this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add webglContextAttributes prop for Canvas (web platform)
This PR adds support for configuring WebGL context attributes on the web platform, enabling features like
preserveDrawingBufferwhich is essential for canvas capture/screenshot functionality.Motivation
Currently, it's not possible to capture/screenshot canvas content on web because the WebGL context is created without
preserveDrawingBuffer: true. This PR allows developers to configure WebGL context attributes to enable this and other WebGL-specific features.Changes
webglContextAttributesprop toCanvasPropsandSkiaBaseViewProps.web.tsfiles)Implementation Details
The implementation converts boolean values to numbers as required by CanvasKit's WebGLOptions interface:
Usage
Testing
Visual Example
You can view a quick demo of this feature (not included in the PR) at this link
Platform Impact
Checklist
Other notes
If you'd like some extra context on why I ran into this problem and what I am trying to accomplish you can contact me gabe@novig.co, first time contributing to open source so please let me know if I am missing anything important in the contribution guidelines here. Great package that has made our work life and native apps render graphs fast and awesome! While porting our existing application to web we encountered this webGL edge case (react native for web)