Skip to content

Commit 1023035

Browse files
filter out unnsupported versions for canvas APIs
1 parent be1a22c commit 1023035

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

packages/browser-rum/src/domain/record/trackers/trackCanvas.spec.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ describe('trackCanvas2DMutations', () => {
2020
it('marks the canvas dirty after drawing operations', () => {
2121
tracker = trackCanvas2DMutations(markCanvasDirtySpy)
2222
const imageData = context.createImageData(1, 1)
23-
const drawingOperations = [
24-
() => context.clearRect(0, 0, 1, 1),
25-
() => context.fillRect(0, 0, 1, 1),
26-
() => context.strokeRect(0, 0, 1, 1),
27-
() => context.fill(),
28-
() => context.stroke(),
29-
() => context.fillText('foo', 0, 0),
30-
() => context.strokeText('foo', 0, 0),
31-
() => context.drawImage(canvas, 0, 0),
32-
() => context.putImageData(imageData, 0, 0),
33-
() => context.drawFocusIfNeeded(canvas),
34-
() => context.reset(),
23+
const drawingOperations: Array<{ method: string; draw: () => void }> = [
24+
{ method: 'clearRect', draw: () => context.clearRect(0, 0, 1, 1) },
25+
{ method: 'fillRect', draw: () => context.fillRect(0, 0, 1, 1) },
26+
{ method: 'strokeRect', draw: () => context.strokeRect(0, 0, 1, 1) },
27+
{ method: 'fill', draw: () => context.fill() },
28+
{ method: 'stroke', draw: () => context.stroke() },
29+
{ method: 'fillText', draw: () => context.fillText('foo', 0, 0) },
30+
{ method: 'strokeText', draw: () => context.strokeText('foo', 0, 0) },
31+
{ method: 'drawImage', draw: () => context.drawImage(canvas, 0, 0) },
32+
{ method: 'putImageData', draw: () => context.putImageData(imageData, 0, 0) },
33+
{ method: 'drawFocusIfNeeded', draw: () => context.drawFocusIfNeeded(canvas) },
34+
{ method: 'reset', draw: () => context.reset() },
3535
]
3636

37-
drawingOperations.forEach((draw) => {
38-
markCanvasDirtySpy.calls.reset()
39-
draw()
40-
expect(markCanvasDirtySpy).toHaveBeenCalledOnceWith(canvas)
41-
})
37+
// Skip unsuported APIs per browser version.
38+
drawingOperations
39+
.filter(
40+
({ method }) =>
41+
typeof CanvasRenderingContext2D.prototype[method as keyof CanvasRenderingContext2D] === 'function'
42+
)
43+
.forEach(({ draw }) => {
44+
markCanvasDirtySpy.calls.reset()
45+
draw()
46+
expect(markCanvasDirtySpy).toHaveBeenCalledOnceWith(canvas)
47+
})
4248
})
4349

4450
it('does not mark the canvas dirty for non-drawing operations', () => {

0 commit comments

Comments
 (0)