What a canvas may not see

Some content is protected by the browser: permission buttons, the colour of visited links, spelling markers, autofill suggestions, frames and images from other origins. I put each one in a <canvas content="drawable"> and the page measures three things: whether it is in the picture, whether script can read its pixels, and whether it still works. The table shows results recorded in the test browser. Press the button to measure this browser. Four cases need a person, and they're under "Try it by hand".

Not run yet.
ContentIn the pictureScript can read itStill worksDetail
Show the code the fixture and the measurements
  1. The fixture: a 300 by 200 canvas with one drawable child. ink() counts the pixels inside one element's box that aren't transparent.
  2. Permission elements. Draw the element at three places, read isValid and invalidReason, then compare with the same element outside a canvas.
  3. Content from another origin. Count its pixels, then call getImageData() and toDataURL() to see whether the canvas is tainted.
  4. The same frame as a WebGL texture. texElementSubImage2D(), then readPixels() through a framebuffer.
  5. The visited link. A link to this page, with different :link and :visited colours.
  6. All the cases.

Try it by hand

The white panel is one canvas. Everything in it is a real element drawn with drawElementImage() at its own position, with no transform. The dashed box under it holds the same permission elements and the same link outside any canvas. The readout updates each time the canvas repaints.

  1. Tap each permission button in the canvas, then the same button in the dashed box. A prompt from the browser means the button works.
  2. Tap the link in the dashed box once. It opens this page again, which puts the page in your history. Then compare the colour of the two links.
  3. Type a misspelt word in the first field and leave the field.
  4. Tap the name field and move through the autofill suggestions without choosing one, then choose one.

Permission elements

A visited link

This page

Spelling

Autofill

This page (outside the canvas)

Waiting for the first paint.
Show the code the canvas you can touch
  1. Markup: the elements are children of the canvas.
  2. Draw the panel at its own position on each paint event. The canvas keeps one backing pixel per device pixel.
  3. Read the picture back after each paint and count pixels in the colours the page chose for :visited, ::spelling-error and the autofill background.

How it works

A drawable canvas lays out its children and paints them into a picture that drawElementImage() copies into the canvas. The page can then read the canvas with getImageData(), or pass the element through a shader. That would expose anything the browser paints but doesn't tell script about, so the browser has to do one of three things with protected content: leave it out of the picture, paint a neutral version of it, or paint it and stop it working. Each row above shows which.

Findings