Article 79SY3 HTML-in-Canvas ships and could make the web a lot more creative...and a lot stupider

HTML-in-Canvas ships and could make the web a lot more creative...and a lot stupider

by
Joab Jackson
from www.theregister.com - Articles on (#79SY3)
Story Image

After two years of experimentation, the Chrome team shipped the HTML-in-Canvas API with Chrome 157. With it comes a new vision of how Web pages could be designed, for better or worse, allowing richer, more interactive elements but also more opportunities for annoying ads.

Previously, when creating visually demanding web apps, you had to choose between standard HTML elements and raw canvas contexts," enthused one Google DevRel in a tutorial. HTML-in-Canvas eliminates these trade-offs."

The Web API has been submitted for inclusion in the WHATWG HTML Living Standard, the ever-updating standard formerly known as HTML5 - for all the technologies that officially make up HTML (including Canvas itself).

A Web API for the browser's rendering engine

Originally developed by Apple and standardized in 2014, the canvas tag is an HTML element that offers a space to render fluid graphics via JavaScript drawing commands. It creates a dedicated grid on screen, within which JavaScript can use a set of Canvas methods to draw lines, curves, text, gradients, and images. Or, the user's GPU, via WebGL or WebGPU, can use the canvas to render 3D images and other custom effects.

The downside of Canvas is that the regular HTML controls didn't work inside the canvas itself. Formatting any text had to be done by hand. Interactivity was out, as were accessibility aids.

Primarily developed by the Google Chromium team, HTML-in-Canvas allows JavaScript to place HTML commands within the canvas element, thanks to an attribute option within Canvas. If the canvas tag includes a content attribute of "drawable," the browser's rendering engine prepares the HTML content inside the box so JavaScript can render it.

While fully supported by Chrome and Chrome Android beginning with release 157, none of the other major browsers support the API yet (Microsoft Edge 157 - which is made of Chromium - unofficially appears to support at least some HTML-in-Canvas actions as well).

The Web's about to get lit

Google posted a few possibilities of what can be done with HTML-in-Canvas.

Developers can wrap HTML controls onto a 3D object. In one example, the user can turn the pages of a virtual book and even copy text out of the book itself. A video, complete with a set of controls, can be wrapped into an odd-sized canvas. The spec seems to work particularly well with JavaScript plug-ins, allowing coders to create entire 3D environments with Three.js, or to create charts with D3.js.

Enthusiasts are already hacking against the spec with mad abandon.

Developer Wes Bos put a notes app in the canvas, then used it as target practice by overlaying the app with some Duck Hunt-styled game code.

HTML-in-Canvas opens up the door to a lot of stupid use cases ... but also a lot of really creative, interesting things where you can apply stylistic effects to HTML," Bos explained on X.

A trippy demo from html-in-canvas.dev shows a dragon slithering through the opening chapter of an online book, with the text smoothly reflowing in its wake. Try to shoo the beast off with your cursor and it will burn the virtual text with its fiery breath.

The source code reveals that Margin Dragon" was rendered in 881 lines of vanilla HTML, CSS, and JavaScript code.

Another demo on the sample site is a mouse-driven elastic displacement effect," in which a radial bulge" and drop shadow follow the cursor across the canvas.

Of course, such stylistic enchantments will not always be used for whimsy. Inevitably, unscrupulous marketers will discover powerful new ways to annoy us about all the virtues of late-stage capitalism.

The world is not ready for HTML-in-Canvas," a punter wrote on X.

Here be dragons

As per norm, HTML-in-Canvas has plenty of bugs (and it hasn't even gone cross-platform yet). In some cases, the CSS doesn't get painted on where it should, and timing with the reactive frameworks could be better synchronized.

And there is a lot for the lowly web maintainer to learn.

The core developers resolved the issue of canvas copying sensitive cross-origin data where it oughtn't (as per CORS), but the API does not indicate when it declines to copy the data, leaving the community to file bug reports of what appear to be silent failures.

Likewise, developers must learn to properly document on-screen bounding boxes to keep accessibility tools like screen readers and click targets operating properly in 3D environments. (R)

External Content
Source RSS or Atom Feed
Feed Location http://www.theregister.co.uk/headlines.atom
Feed Title www.theregister.com - Articles
Feed Link https://www.theregister.com/
Reply 0 comments