Skip to content

Commit ccf96a5

Browse files
AmirMohammad CheraghaliAmirMohammad Cheraghali
authored andcommitted
Fix video export artifacts and sync playback
1 parent bb7532d commit ccf96a5

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/components/MolStarProteinViewer.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ export const MolStarProteinViewer = forwardRef<ProteinViewerRef, ProteinViewerPr
4141
];
4242

4343
try {
44+
// HACK: Force preserveDrawingBuffer: true for WebGL context to ensure video recording works (prevents tearing/flickering)
45+
const originalGetContext = HTMLCanvasElement.prototype.getContext;
46+
// @ts-ignore
47+
HTMLCanvasElement.prototype.getContext = function (type: string, attributes?: any) {
48+
if (type === 'webgl' || type === 'webgl2') {
49+
attributes = { ...(attributes || {}), preserveDrawingBuffer: true, alpha: false }; // Also force alpha: false for solid background
50+
}
51+
return originalGetContext.call(this, type, attributes);
52+
};
53+
4454
pluginRef.current = await createPluginUI({
4555
target: containerRef.current!,
4656
spec,
@@ -49,6 +59,10 @@ export const MolStarProteinViewer = forwardRef<ProteinViewerRef, ProteinViewerPr
4959
}
5060
});
5161

62+
// Restore original getContext
63+
HTMLCanvasElement.prototype.getContext = originalGetContext;
64+
65+
5266
// Subscribe to Layout Changes to adjust UI overlay
5367
pluginRef.current.layout.events.updated.subscribe(() => {
5468
const isExpanded = !!pluginRef.current?.layout.state.isExpanded;

0 commit comments

Comments
 (0)