Hit region viewer
The canvas draws four elements, then asks the browser which element it would hit at every 8 px and tints each square with that element's colour. The outlines are where the canvas drew each element. Choose a case under the picture, and tap the picture to see what a tap hits.
tint: hit here. Outline: drawn here
hit, not shown
shown, not hit
Show the code record each draw, scan elementFromPoint() over a grid, compare
- The markup. Four drawable children.
- Where each element was drawn. A wrapper round
drawElementImage()reads the transform at each call. - Where the browser hits each element.
elementFromPoint()at the centre of each square, a few rows per frame. - Comparing the two.
- The cases. Each is a short drawing function.
- One frame. Draw the case, scan some rows, draw the map over the picture.
- The last case. Two points asked on every frame.
- Drawing the map.
How it works
- The page wraps
drawElementImage(). At each call it readsctx.getTransform()and stores the four corners the element is drawn to. Those are the outlines. - The hit regions aren't read from an API, because none reports them as shapes. The page calls
document.elementFromPoint()at the centre of each 8 px square of the canvas, 6 rows per frame, and stores which child of the canvas the answer belongs to. The white line is the row being scanned. A full pass takes about 10 frames. - Chromium remembers the answers to the last two points it was asked, and a new draw doesn't clear them. A change to the document does. The scan asks about 2,500 other points before it returns to a square, so it never reads a remembered answer. The last case asks the same two points on every frame to show the memory. The counts are drawn in the canvas and not written into the page, because writing them would change the document.
- Squares outside the window, or under another part of the page such as the menu bar, can't be asked. They're left without a tint.
- A tap on the picture is reported from two sources: the
clickevent's target, andelementFromPoint()at the same point.
Live checks
Each check builds a small canvas of its own in a corner of the window. The picture above isn't touched.
| Result | Experiment | Detail |
|---|
Findings
From Chromium 157, headless, on 2026-11-21. The rows above say what your browser does.
- The hit region is the box of the last draw, with its transform. A turned and scaled draw gives a turned and scaled region. The scan and the recorded corners agree except in squares on the edge.
- One element has one region. Of two draws of the same element, only the second takes taps. The first is a picture.
- A clip doesn't clip the region. The card clipped to a circle is hit in the corners of its box, where nothing of it is shown.
updateElementGeometry()has acanvasClipoption for this (see /portal/). This page doesn't use it. globalAlpha = 0still places the element. The button takes taps where nothing is drawn. /layout-debug/ uses this on purpose to measure layout.- Copied pixels aren't hit.
drawImage()of a part of the canvas shows the link a second time, and a tap on the copy reaches the canvas. - Where two elements overlap, the later draw is hit. The order in the document and
z-indexdon't matter. - An element that is no longer drawn keeps its region. The link's region stays where it was last drawn, and it takes taps there.
- A remembered answer outlives a new draw.
elementFromPoint()returns the old element at a point it was asked before the element moved. This is the Chromium bug recorded forupdateElementGeometry()in FINDINGS.md. This page adds three measurements. It happens for plain 2D draws too. Only the last two points asked are remembered: after two other points are asked, the answer is new.elementsFromPoint()doesn't use the memory. A change to an attribute or to text clears it, and time alone (200 ms, several frames) does not. - How long the memory lasts differs between pages, and the reason isn't known. In a page with one canvas and nothing else, the old answer was still returned 240 frames after the element moved. On this page, in the last case, it was returned for 14 to 20 frames after each jump (about 42 of 360 frames in 6 seconds) and then corrected itself with no change to the document that a MutationObserver could see.
- A real click wasn't affected in one test. A script moved the mouse to a remembered point, moved the element away without a document change, and pressed. The click went to the canvas, which is the new answer. This was one run in headless Chromium 157 with a mouse.
- Not verified here: a finger on a phone. Touch adjustment (the browser choosing a nearby target for a fat finger) may move a tap near an edge onto an element that
elementFromPoint()doesn't report. Tap near the edges of the button and compare the two lines in the status text.