diff --git a/src/core/text-rendering/renderers/CanvasTextRenderer.ts b/src/core/text-rendering/renderers/CanvasTextRenderer.ts index de59b4d6..b6c15979 100644 --- a/src/core/text-rendering/renderers/CanvasTextRenderer.ts +++ b/src/core/text-rendering/renderers/CanvasTextRenderer.ts @@ -98,16 +98,17 @@ export class CanvasTextRenderer extends TextRenderer { this.canvas = document.createElement('canvas'); } // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion - let context = this.canvas.getContext('2d') as - | OffscreenCanvasRenderingContext2D - | CanvasRenderingContext2D - | null; + let context = this.canvas.getContext('2d', { + willReadFrequently: true, + }) as OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null; if (!context) { // A browser may appear to support OffscreenCanvas but not actually support the Canvas '2d' context // Here we try getting the context again after falling back to an HTMLCanvasElement. // See: https://github.com/lightning-js/renderer/issues/26#issuecomment-1750438486 this.canvas = document.createElement('canvas'); - context = this.canvas.getContext('2d'); + context = this.canvas.getContext('2d', { + willReadFrequently: true, + }); } assertTruthy(context); this.context = context;