Paint event inspector
One canvas draws eleven elements. Each time the canvas gets a paint event, the elements named in
event.changedElements flash. The label on each element is its count and its rate over the last second, and the strip
under it is its last four seconds. Type in the field, press the button, and start the video to see which changes raise an event.
Show the code count changedElements, draw a flash and a strip per element
- The markup. Eleven drawable children of one canvas.
- The animations, in CSS. Two of them are on the drawable element itself and one is on a descendant.
- Counting. One listener for
painton the canvas. - One frame. Draw every element, then its flash, count and strip.
- Drawing the flash, the strip and the count.
How it works
- The inspector is one
paintlistener on the canvas. For every element inevent.changedElementsit adds one to a count and stores the time. - The canvas is redrawn on every animation frame while it is on screen, because the strips move. Each frame draws all eleven elements with
drawElementImage()and then the overlay. Drawing doesn't raise a paint event. - The colour is the rate over the last second: grey for none, green for up to 3, amber for up to 20, red above that.
- "transform on the element" and "opacity on the element" animate the drawable element itself. The picture of an element is its own box before its transform and opacity are applied, so the animation isn't in the picture: the two tiles don't move or fade here, and no event names them.
- The video loads when you press "Play the video" or tap it, so that the page doesn't take a video decoder on load.
Live checks
Each check builds a small canvas of its own in a corner of the window and counts events for about half a second. The picture above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157, headless with software rendering, on 2026-11-21. The rates are from a 60 Hz frame clock. The rows above say what your browser does.
- Every frame: a
background-coloranimation, a<marquee>, and a transform animation on a descendant of the drawable element (120 events in 2 s each). The event for the descendant names its drawable ancestor. - Per video frame: a playing 30 fps clip was named 59 times in 2 s.
- 8 times a second: a
<progress>with no value. 2 times a second: the caret of a focused text field. - Never after the first picture: a transform or opacity animation on the drawable element itself, and an element that doesn't change. Each is named once, when its first picture is ready.
- A listener added late misses that first mention. With the listener added 300 ms after the element was put in the canvas, the event raised by
requestPaint()listed no elements. A page can't usechangedElementsalone to decide what to draw first. - Paint events don't wait for a draw. With a listener that draws nothing, the events kept arriving at the same rate.
- Cost to keep in mind: one animated element raises a paint event on every frame for the whole canvas. A page that uploads textures in its paint handler should upload only the elements in
changedElements. - Not verified here: the rates on a phone, where the frame clock can be 90 or 120 Hz and video is decoded by hardware. Open this page on the phone and read the labels. Hover doesn't exist on a touch screen, so the button is named only when pressed or focused.