HTML5 Doctor » Bruce Lawson http://html5doctor.com helping you implement HTML5 today Wed, 02 Mar 2016 08:08:54 +0000 en-US hourly 1 The Web Manifest specification https://stevefaulkner.github.io/html5doctored/web-manifest-specification/ https://stevefaulkner.github.io/html5doctored/web-manifest-specification/#comments Tue, 29 Jul 2014 09:51:22 +0000 http://html5doctor.com/?p=5515

Related Posts:

]]>
By Marcos Cáceres and Bruce Lawson.

Update 26 September 2014 The initial work for Manifest in Chromium M39 is done, and Marcos (more or less) finished coding the processor a few months ago. “I’m hoping to see it in fxos 2.2“, he said from the pool of his gorgeous Malibu home.)

Update 11 November 2014 Web Application Manifest is in Chrome 38.

Update 9 April 2015 Updated implementation status to note App Install banners in Chrome, Opera Android implementation underway. Also show how to link to the manifest (thanks @mathias!) and remove some scary “this may all change” warnings.

Update 18 August 2015 François Beaufort pointed out that “According to the spec https://w3c.github.io/manifest/#h-density-member, the density should actually be a number (not a string)” – amended accordingly.

Update 7 December 2015 Link to my blogpost declaring Progressive Web Apps “ready for primetime”; remove stuff about service_worker manifest member, as it’s gone now because it was useless

Manifest? Eh? What? Why?

Many of us who work on the web are actively working to narrow “the gap” between native applications and web applications. (Disclosure: your humble authors, Marcos Caceres and Bruce Lawson work for browser vendors – Mozilla and Opera respectively – and therefore have mortgage-related reasons to convince you this stuff is a good idea.)

But what is that gap? Just a few years ago, that gap was largely technological. If you wanted access to a device’s GPS, you had to write a native app. Nowadays, the situation is improving somewhat: we can now access devices sensors like GPS, camera, and orientation sensors – though we still have a long way to go. Thanks to recent advances in the web platform we now have a platform that can compete with native applications on a more equal footing.

Nowadays, the primary gaps between native and web is not so much technological. It’s user experience. Users simply love installing apps, which live snugly on the homescreen (or the desktop) waiting to be tickled into life with the tap of a finger or the click of a mouse.

Furthermore, native apps work offline by default, and integrate with the facilities provided by the underlying operating system: consider being able to see installed applications in the task switcher. Or being able to control an app’s privacy settings in the same place as apps installed from an app store. In browser land, we are still fumbling around trying to find opened tabs and having to type long and boring URLs to get anything done.

What we need is a method of “installing” web apps so they are indistinguishable from any other app installed on a user’s device. But at the same time, we don’t want to lose the powerful features that are central to the web platform: linkability, view source, and the ability to host our own stuff.

What is “installation”?

At its most basic, “installation” of a web app means “bookmarking” the web application to the homescreen or adding it to an application launcher. There are some pretty obvious things that you, as a developer, would need to provide to the browser so that it can treat your website as an app: the name, icons, etc. There are then more advanced features that you would need, like being able to indicate the preferred orientation and if you want your app to be fullscreen.

The Manifest specification aims to give you a standardised way to do this using JSON. In the HTML page to be “installed”, simply link to a manifest file, thus:

<link rel="manifest" href="/manifest.json">

But what’s in this mysterious manifest file? Glad you asked!

Application name

The application needs a real name or set of names (which is usually not the same as the title element of a document). For this you use the name and the short_name properties.

{
name: “My totally awesome photo app”
short_name: “Photos”
}

The short_name serves as the name for the application when displayed in contexts with constrained space (e.g., under an icon on the homescreen of a phone). The name can then be a bit longer, fully capturing the name of the application. This also provides an alternative way for users to search your app on their phone. So, typing ‘awesome’ or ‘photo’ would find the application on a user’s device.

If you omit the name, the browser just falls back to using <meta name=”application-name”>, and failing that, the <title> element.

Icons

There needs to be an icon associated with a web app, rather than the browser’s icon. To handle this, the manifest has an icons property. This takes a list of icons and their sizes, format, and target screen density. Having these optional properties makes icon selection really powerful, because it provides a responsive image solution for icons – which can help avoid unnecessary downloads and helps to make sure your icons always look great across a range of devices and screen densities.

{
   "icons": [{
        "src": "icon/lowres",
        "sizes": "64x64",
        "type": "image/webp"
      }, {
        "src": "icon/hd_small",
        "sizes": "64x64"
      }, {
        "src": "icon/hd_hi",
        "sizes": "128x128",
        "density": 2
      }]
}

If you omit the icons, the browser just falls back to looking for <link rel=”icon”>, the favicon.ico or, failing that, may even use a screenshot of your website.

Display modes and orientation

Apps need to be able to control how they are to be displayed when they starts-up. If it’s a game, it might need to be in full-screen and possibly in landscape mode. In order to do this, the manifest format provides you with two properties.

{
 "display": "fullscreen",
 "orientation": "landscape"
}

For the display modes, the options that you have are:

  • fullscreen: take over the whole screen.
  • standalone: opens the app with a status bar.
  • minimal-ui: like on iOS, the app is fullscreen, but certain actions can cause the navigation bar and back/forward buttons to reappear.
  • browser: opens your app with normal browser toolbars and buttons.

The nice thing with orientation is that it serves as the “default orientation” for the scope of the application. So, as you navigate from one page to another, your app stays in the correct orientation. You can override the default orientation using the Screen Lock API.

Start URL

Sometimes you want to make sure that when the user starts up an app, they always go to a particular page first. The start_url property gives you a way of indicating this.

{
 start_url: “/start_screen.html”
}

“Scope” of the app

Native applications have clear “boundaries”: as a user, you know when you open a native application that it won’t suddenly open a different application without you noticing. When switching from one native application to another is often pretty clear that you’ve switched applications. These visual cues are often provided by the underlying operating system (think of bringing up the task manager and picking a different application – or pressing “command/alt-tab” on your desktop machine).

The web is very different: it’s a huge hypertextual system where web applications can span multiple domains: you can seamlessly jump from “gmail.com” to “docs.google.com” and as a user have no idea that you’ve jumped form one “origin” to another. In fact, the whole idea that there are boundaries to an application is totally foreign on the Web as, in reality, a web application is just a series of HTML documents (think, “a series of tubes”… no, don’t think that!).

On the web, the only reason we know that we’ve left the scope of one application and entered into another application is because the web designers have been kind enough to make their websites look uniquely different. In case where they haven’t, a lot of users have also been tricked by sites masquerading as another site (the ol’ “phishing attack”).

The manifest format assist with this problem by allowing you to specify a “URL scope” for your application. This scope sets a boundary for an app. It can either be a domain or a directory within that domain.

{
    “scope”: “/myapp”
}

How can I detect if the user “installed” my app?

As a developer, you really should not have to worry about this – the browser will take care of it for you. Firstly, bugging users to install your app is annoying. We’ve all seen this happen in iOS with sites asking users to “add my app to the homescreen”.

Instead, the approach that we take with the manifest is that “installing” is a progressive enhancement. Focus on creating the optimum experience based on what “display mode” the application is in. You will be able to detect and style this with CSS.

@media all and (display-mode: standalone){ ...}

You can use JavaScript matchMedia to test that media query in JavaScript.

Addendum June 2015: In Chromium, you can detect whether a user accepted or dismissed an install banner.

What’s wrong with <meta> tags?

During the specification discussions, it was hotly debated whether to use <meta> tags in HTML rather than make a new format. After all, the Chrome implementation of Add to Homescreen uses <meta> tags, and this has been the natural home for proprietary flimflam since the web began.

The reasons for including a separate file are

  • it saves loading every page of an installable app/site with tons of header info
  • once downloaded, the file sits in the browsers’s HTTP cache.
  • Marcos loves JSON because he’s totally rad

Who is implementing this

The manifest, and Progressive Web Apps are implemented in Chrome and Opera for Android. Implementation is underway in Firefox. You can kinda-sorta do this is a non-standard way in Safari/iOS, too.

Progressive Web Apps are ready for primetime, I believe.

The Web Manifest specification originally appeared on HTML5 Doctor on July 29, 2014.

]]>
https://stevefaulkner.github.io/html5doctored/web-manifest-specification/feed/ 6
Responsive images – end of year report https://stevefaulkner.github.io/html5doctored/responsive-images-end-of-year-report/ https://stevefaulkner.github.io/html5doctored/responsive-images-end-of-year-report/#comments Tue, 12 Nov 2013 17:12:26 +0000 http://html5doctor.com/?p=5352

Related Posts:

]]>
It’s nearly two years since I suggested a <picture> element as a strawman proposal as a way to solve the problem of responsive images, so let’s have a look at how we’re doing.

In September there was a big meetup at Mozilla’s Paris office organised by Mozilla’s Marvellous Mr Marcos who’s been very active in the Responsive Images Community Group and did the hard work of actually turning the <picture> strawman into a spec. Such is the combined allure of Marcos and Paris that a rep from Apple showed up – kudos to Edward O’Connor.

The outcome of the meeting was that <picture> isn’t a viable option. Browser makers don’t like the fact that it’s a new element that does the same as <img> (or what <img> should do if we were speccing it today), and that it depends on multiple nested children. I’d based this on the HTML5 <video> and <source> pattern, but Ian Hickson already said “we learnt with <video> and <source> that having multiple elements for selecting a resource is a huge design pitfall”.

The Paris meetup’s most immediate outcome was agreement that srcset + DPR-switching is the right initial step forward (i.e., the 2x, 3x, etc. syntax). (See Marcos’ full write-up for more fun.)

srcset was specified as part of the WHATWG specification and a draft extension to HTML5, based on Edward O’Connor’s imgset in CSS that’s already implemented in WebKit. It’s fair to say that the syntax hasn’t been received with enthusiasm by developers, as it is ugly and unintuitive. But for the simple case of sending a large image to high-dpi displays and not to 1x dpi displays, it’s simple:

<img src="normal.png" srcset="retina.png 2x" alt="otter vomiting">

Browsers with two or more device pixels per CSS pixels (“retina”) get the 2x image; other browsers, including those that don’t understand srcset get normal.png as specified in the traditional src attribute. Hurrah!

This limited version of srcset is already implemented in WebKit nightly, but not shipping, and was about to be implemented in Gecko and Blink when a proposal from Tab Atkins and John Mellor of Google called src-N made a fashionably late entrance.

It’s not the easiest syntax in the world, either, but src-N does address the three main usecases:

  • devicePixelRatio based resolution switching
  • viewport-size based resolution switching
  • art direction

The simplest incarnation – serving high-dpi images only to browsers that can deal with them is

<img src="normal.png" src-1="normal.png 1x picHigh.png 2x" alt="narwhal regurgitating">

An explainer email shows how verbose <picture> can be for a real sites, while a blog post from Tab Explaining The Last Clause of the src-n Grammar shows a more verbose example of src-N while comparing it with its srcset analogue which is, Tab says, “fucking terrible” – much longer and harder to maintain, requiring non-trivial maths.

All the proposals are verbose and tricky. I suspect that this is simply because it’s a really hard problem, but it is one that needs solving. Tim Kadlec’s posts on Why We Need Responsive Images quantify the bandwidth that we currently waste, and wasted bandwidth costs money and slows down the site for users which has a measurable and significant impact on your sales.

Since src-N has been proposed, both Blink and Gecko have decided not to implement srcset which is currently not yet shipping in WebKit. A representative of Apple called src-N‘s use of multiple attribute “a grotesque perversion of the HTML language“, which implies they’re not eager to implement it. (We’ll ignore the irony that the company which gave us a meta tag in HTML to control presentation is accusing others of perverting HTML).

Meanwhile, the src-N explainer says “Ideally, browsers that have already implemented the basic srcset syntax would remove that as soon as possible before sites start to depend on it”, but goes on to note “it would be possible for such browsers to integrate srcset, just like src acts as a fallback”.

Adam Barth, a Blink rep, writes “I’d rather ship something that’s useful today and iterate to improve it in the future than not ship anything for a long time”, which is fair enough – but Henri Sivonen of Mozilla counters “I think srcset should be taken out of the spec ASAP before WebKit ships it and we get stuck with something that doesn’t allow iteration”. The bone of contention – is srcset subsequently extensible?

Given that src-N addresses more usecases than WebKit’s proposed dpi-switching srcset and the similarity of syntax, I wish WebKit would simply alias their nightly code and ship the minimal dpi-switching src-N given above (so src-1 instead of srcset) and argue about discuss extending it later.

But no. So, once again, impasse. Our doctors’ report: must try harder.

Added 13 November 2013: It’s been pointed out to me that srcset is also implemented in Blink, behind the “experimental features” flag. Demo. The point, however, is that it’s not shipping anywhere so no websites rely in it, and it’s not in Firefox or IE.

Added 2 January 2014: Given the impasse described above, the proposed <picture> element has been revived again and new <picture> specification is under development that combines the best features of all proposals. The most important difference from “old” <picture> is that the <source> elements control the src of the <img> element; thus, <img> is an integral part of the construct rather than simply fallback (and thus is unlikely to be omitted by authors, so “old” browsers won’t be left out.)

Responsive images – end of year report originally appeared on HTML5 Doctor on November 12, 2013.

]]>
https://stevefaulkner.github.io/html5doctored/responsive-images-end-of-year-report/feed/ 76
Interview with Steve Faulkner: HTML5 editor and new doctor https://stevefaulkner.github.io/html5doctored/interview-steve-faulkner-html5-editor-new-doctor/ https://stevefaulkner.github.io/html5doctored/interview-steve-faulkner-html5-editor-new-doctor/#comments Tue, 19 Mar 2013 13:59:06 +0000 http://html5doctor.com/?p=5039

Related Posts:

]]>
Steve Faulkner – invariably prefixed by the honorific “The Mighty” by those who know him – is Australian living in London with his wife and two kids. He works for The Paciello Group, a well-known web accessibility consultancy, and is a co-editor of the HTML5 spec at W3C Today, we’re pleased to announce that he’s joining the HTML5 Doctor team, with special focus on accessibility and didgeridoo.

Bruce grills him mercilessly; some questions were contributed over Twitter and co-interrogators are acknowledged below.


The Mighty Steve Faulkner, and a UFO
What’s your connection with HTML5?
I’ve been participating in the HTML Working Group since 2007 after reading a post by Roger Johansson. I have recently taken on the roles of HTML accessibility task force chair and co-editor of the HTML specification. I also edit Using ARIA in HTML, HTML5: Techniques for Providing Useful Text Alternatives and HTML to Platform Accessibility APIs Implementation Guide I also blog on accessibility and web standards.

Some people call you “the accessibility guy”. What do you call yourself?
I have lots of ways to self identify these days. The most important is being a dad to Clara and Eloisa.

What’s your day job?
I work as an accessibility engineer/director/consultant/curmudgeon at The Paciello Group. On a typical day I may be writing code, testing a site or application, reviewing the work of colleagues, talking with clients, (tor)mentoring colleagues (can’t wait until Patrick Lauke starts), working on the free testing tools we develop, editing the HTML spec or one of the other specs I edit, writing a blog post, filing bug reports on browsers or AT and as I work from home I try to squeeze in a kip (nap), while keeping an ear open for my boss Charlie pinging me on skype.

How did you get into the world of accessibility?
When I went back to Australia in 2001 after a 2 year stint as a HTML code cutter in London, I applied for a job at vision australia which combined my technical and social work interests (in a previous life I studied psychology at Sydney Uni and then worked with people with disabilities).

The job at vision australia was (I thought) as developer on their web site, but on the first day my then boss Brian Hardy threw a copy of WCAG 1.0 at me and said “read this”, and it started from there.

What’s the difference between W3C HTML5 and WHATWG HTML Living Standard?
The W3C has  HTML5 CR (Candidate Recommendation) which is a snapshot (also read Robin’s interview for more detail) and HTML 5.1 which is akin to the WHATWG spec in that it is up to date and includes new/unstable feature proposals. HTML 5.1 takes up most commits from the WHATWG spec unless there is disagreement in the HTML WG about a change.

HTML 5.1 is also modularised, meaning some features are developed as extension specifications within the “HTML5 family of specifications” This is the case for features such as HTML Canvas 2d context and some controversial new features (the <picture> element and srcset attribute being examples).

Once one or both new feature proposals get implemented they may well be moved into the core HTML spec. Another example is the <main> element. It started life as an an extension spec, but was pretty quickly integrated into HTML 5.1 as implementations occurred. It should be noted that the <main> element should be included in the HTML5 CR spec before it becomes irrevocably frozen, as it already meets the criteria of two interoperable implementations. It should also be noted that the text of HTML5 CR is not yet untouchable. It is still updated with bug fixes and I have a queue of changes to feature definitions, currently in HTML 5.1, to commit. More details about how the HTML recommendation process works can be found in: Plan 2014.

Which mailing list should I be subscribed to for W3C HTML? (Steve Fenton)
I recommend you join the HTML WG – anybody can. When you join, you are subscribed to a number of lists; the two to watch and contribute to are Public-HTML for technical discussion and Public-HTML-admin for process/admin stuff related to technical discussion.

How do you get a new element/ feature added to HTML? (Dr Rich Clark)
Lots of hard work, research, data gathering, use cases, discussion, haggling, etc. To get a feature added to HTML that involves implementation in browsers (i.e. vast majority) you need to get implementers to interested.

What I did for the <main> element was talk to as many implementers (both general browser implementers and accessibility implementers), developers, authors and users as I could and got advice and input from them. I went where the various people hung out; on IRC, mailing lists, twitter, blogs, conferences – anywhere.

Robin Berjon has written a useful HowTo on extension specifications which is a route you can use at the W3C (I used it for <main>). The WHATWG also provide info on how to do it via their process.

What drives you to push proposals through in the face of stiff opposition? (Steve Fenton)
A passion for pain mostly :-) also a desire to improve the web.

Do you plan to work on getting your changes upstreamed to the WHATWG spec? Do you coordinate with the upstream? (Henri Sivonen)
The way it currently works is that the WHATWG spec is a (major) source for the HTML 5.1 spec. We cherry-pick commits to the WHATWG spec to add to the HTML spec. Uncontroversial changes such as bug fixes, editorial tweaks, new features proposals that the HTML WG members have no issue with, get added on a weekly basis. We also do our own commits to the spec, for example I make improvements to the authoring advice and requirements and accessibility implementation stuff after discussions on the HTML list or in response to bug reports.

Co-ordination is a thorny issue the WHATWG is an important contributor to HTML and I have have reached out, but with limited success so far. Its safe to say that like HTML, the relationship between the WHATWG and the W3C is a work in progress.

I think the most important thing is that the HTML 5.1 spec reflects implementations and that includes advice and requirements on how authors should use HTML as implemented, to maximise the benefit to users.

Are you worried about WHATWG/ W3C specs diverging?
I used to worry a lot more about this. Implementation stuff is not diverging, authoring advice and requirements and advice are diverging as improvements are made to HTML 5.1. Ideally the WHATWG spec and the HTML 5.1 spec would not contain contrary advice, but I don’t think the threat of divergence, should stop us from making improvements to HTML that benefit authors and users. Its better to have the improvements out there for people to make use of rather than have two specs that agree, both of which contain advice fictions based not on implementation reality but on future possibilities.

Rephrasing from Isn’t it bad that the specs have forked?:

“The plan is to just do a better job with the HTML 5.1 spec, such that it becomes the logical and obvious choice for anyone wanting to figure out which spec they should use.”

What are the skills of a good editor?
Unsure about that, I don’t know. What I try to do is get as much feedback on stuff as possible, so I go out to where people are and badger them. I realise that I don’t know it all and therefore want to engage others to contribute their knowledge and am myself only an editor in a team contributing to the development of HTML. I also realise that HTML is a vast and complex specification and limit my editing to those areas that I feel knowledgeable and confident enough to contribute to (luckily I am part of a team).

Is the spec readable/ useful enough for authors?
I think the spec needs work to make the authoring advice contained in it more useful, usable and accurate. I am working on it. I have already committed changes to HTML 5.1 in response to feedback from authors, developers and users. I read a lot of articles and blogs picking up issues with the spec and discuss stuff with authors/developers who use the spec and book authors such as you who use it as source material. But really, it’s the users of the spec that decide if it’s readable/ useful enough, so I seek out and appreciate any feedback from them.

Why hasn’t the HTML5 outlining model really been implemented? (Marc Drummond)
My understanding is that the outline algorithm as currently defined is not intended to be implemented in browsers. Meanwhile it has sort of been implemented by the JAWS screen reader, but in a borked way. It is a proposed feature that  implementers in general have not shown an interest in. for this reason it is a feature at risk in the HTML5 CR specification and will likely be dropped before it becomes a Recommendation, it will probably live on in HTML 5.1 as a proposed feature and we will see how it goes.

<hgroup>: rubbish or not?
Good question! I think it’s a feature in search of a use case. The only use case cited for it is to mask subheadings from the unimplemented outline algorithm (see above). I don’t think it’s a good enough reason to add a new element to HTML. Also, its accessibility mappings are defined such that any content in it becomes one big heading. But it is there, so we have some choices: make it more useful by changing how it is defined and fixing the accessibility mappings, obsolete it and replace it with something that is more useful, obsolete it and replace it with advice on how to mark up subheadings using current features, or just leave as is…

Do you agree with Luke Stevens that the new structural elements miss the mark and we should just use <div>s with ARIA roles instead?
No. I think that there is improvement needed in how the elements are defined and how they are explained, but do not think that using divs and roles is the way forward. Some people imbue HTML structural features with magical properties that in reality are not present. What I try to do is look at how such features are used and work in practice, for users that actually consume the semantics and, where needed, modify the feature definitions to benefit users.

I asked Hixie why most of his fights are with accessibility practitioners. He said didn’t know. Have you got any ideas?
Hixie has strong opinions about how HTML should be defined; other people disagree with him. Conflict ensues at times. I believe the new development process for HTML at the W3C takes a lot of heat out of these disagreements providing a constructive environment for contributions from a wide range of stakeholders to the further development of the language of the web.

Now you’re an HTML5 doctor, what (apart from fame, glory and the adultation of beautiful people) do you hope to get from it and contribute?
Once I get over the shock and honour of being bestowed with a HTML5Doctorate, I hope to contribute by writing articles on the bits of HTML/ARIA I know best. I would also very much like to get as much input/feedback as possible from the good readers of HTML5Doctor and seek their collaboration in improving HTML 5.1.

The all-important grooming question: Blue Stratos or Old Spice?
I used to be a Blue Stratos kinda guy, but have switched to the far superior male fragrance Hai Karate after your recommendation.

Interview with Steve Faulkner: HTML5 editor and new doctor originally appeared on HTML5 Doctor on March 19, 2013.

]]>
https://stevefaulkner.github.io/html5doctored/interview-steve-faulkner-html5-editor-new-doctor/feed/ 6
Interview with Ian Hickson, HTML editor https://stevefaulkner.github.io/html5doctored/interview-with-ian-hickson-html-editor/ https://stevefaulkner.github.io/html5doctored/interview-with-ian-hickson-html-editor/#comments Tue, 08 Jan 2013 13:58:20 +0000 http://html5doctor.com/?p=4868 interview with Robin Berjon, editor of HTML5 at W3C, over the weekend I interviewed Ian Hickson, editor of HTML "The Living Standard" at WHATWG and, arguably, the most influential individual working on the Web today. Hickson, known as "Hixie", works for Google and previously worked for Opera (my employer) and Netscape.]]> Japanese translation, thanks Junichi Niino.

Hot on the heels of our interview with Robin Berjon, editor of HTML5 at W3C, over the weekend I interviewed Ian Hickson, editor of HTML “The Living Standard” at WHATWG and, arguably, the most influential individual working on the Web today. Hickson, known as “Hixie”, works for Google and previously worked for Opera (my employer) and Netscape.

Some of questions were suggested by web developers over Twitter, where indicated.

Ian Hickson
If you could wipe out any web technologies from existence, which would you choose? (from @webr3)

HTML, JavaScript, DOM, anything I’ve ever invented, SVG, XML, JSON, CSS — basically anything that anyone uses! The Web technology stack is a complete mess. The problem is: what would you replace it with?

The Web’s technology stack is one of the only (maybe the only? I’m hard pressed to come up with another example) platform that is completely vendor-neutral and not centrally developed. Anyone can invent a new feature and if the market agrees, can get that feature to be a de facto part of the platform. XMLHttpRequest is a classic example. A browser cannot be a serious competitor on the Web without supporting it now, yet it was initially just made up and shipped by one vendor without any consultation with anyone. Even the features that are designed in public with wide review end up implemented and used before they’re “done”, and once they’re used they can’t be changed — which leads to APIs that make no sense, like pushState(), which has a required argument that is ignored.

The hardest part of this is that we can’t tell if something we’ve designed is any good without testing it in real world sites, and by the time it’s been properly tested, it’s too late to change it. pushState() happened like this (where we learnt that the second of the three arguments should be dropped only after there were already pages depending on using the first and third arguments), but there are even bigger examples: the CSS cascade and specificity mechanism, for example, which was a great idea but that doesn’t quite work at the end of the day, or even XML and specifically XML namespaces, which are widely recognised as a disaster but which whole layers of the Web platform depend on.

This isn’t helped by the way that certain parts of the platform that are now absolutely core central pillars, like JavaScript, essentially started as experiments; or the way that other features, like the offline application cache API, were designed with a very limited understanding of how authors would eventually use them. (Appcache works great if you want to do what it was designed for, but it turns out most people want to do something different enough that appcache feels horrible to them.)

In the end, the most horrible parts of the Web are also the most successful, because it’s the most successful parts that get extended by the most people, and so that have the least coordination in terms of their long-term evolution, which is how things end up being horrible.

HTML5 vs. the “living standard”: how do I know which elements will be around ten years from now, so I can safely use them in client work? (from @szafranek)

You know what will be around ten years from now by looking at what is implemented in two browsers today. If it’s implemented in two browsers today, I can almost guarantee it’ll still be around in ten years. If it’s not, all bets are off.

This has nothing to do with “living standard” vs. versioned specs, though. HTML4 has all kinds of features that aren’t in HTML anymore — for example, <object declare> and <a coords>.

Do you feel there’s enough innovation within the user agent market, since most are virtually equivalent in every way? (From @webr3)

I don’t really agree with the premise of the question. Browsers differ in many important ways. One of the reasons they might seem to be “virtually equivalent”, though, is that they often adopt features from each other. Another is that one of the key features they’ve all been trying for is “get out of the way and let the Web shine through”, which means you see less and less of the browser itself.

In the area of browser development that I’m most familiar with — namely the Web technology stack — there’s a lot of innovation going on. I get a lot of e-mails from browser vendors asking me to spec their new invention so that it has a spec and can be implemented by everyone else also. In fact, it’s gotten to the point where I have to track these requests to make sure I only spec those with multiple vendors on board. (I don’t want to end up with a spec where each section is only implemented by one browser. That would be a waste of everyone’s time.)

The browser space right now has more active competition than it ever has had in the past, especially on desktops. It’s a great time for users.

Why are you the one who always says “no”? Casing the <picture> and <main> elements here (from @helloanselm). Why so grumpy? (from @steve_fenton)

The short answer is, it’s my job!

There’s really two questions here. First, why do we in general say “no” so often? And second, why is it that it’s so often me that says it?

The first one is a combination of prioritisation and design.

First, let’s look at prioritisation. There are very limited resources available to add features to the Web. Every feature has a cost:

  • Implementation: someone has to write code for it in each browser
  • Testing: someone has to write the tests to check the feature is working
  • QA: someone has to regularly run the tests to make sure the feature doesn’t regress
  • Code maintenance: when browser vendors refactor code, they have to refactor more code if there are more features
  • Tutorials: people who write tutorials have to include the feature, or handle feedback asking for them to do so
  • Cognitive load: authors learning the platform have more documentation to wade through, even if they don’t care about the feature
  • Page maintenance: authors have to know how to maintain the feature if other people have used it in pages they now maintain
  • Spec writing: someone has to write the spec for the feature and ensure it’s maintained
  • Bug fixing: when bugs are found in the spec or implementations, they have to be maintained
  • Code size: each feature increases the size of browsers (both on-disk binaries and in-memory resident size)

(This list comes from our FAQ.)

We get an absolute torrent of feature requests, from authors, users, browser vendors, etc. So we have to prioritise:

  • Is the feature going to be implemented by more than one browser? If no browser has signed up, or if only one has signed up and no other browsers have shown any interest, then I add it to the page of notes I mentioned earlier, and move on.
  • Is the feature a game changer, or is it merely incremental? If the feature does no more than save a line of code every now and then, then its value probably doesn’t warrant its cost.
  • Is the feature compatible with the Web philosophy? If the request is for a way to force the user to read something the way the author wants, it’s likely to be a non-starter. If it’s something that enables the user to control the page better, that’s more likely to be a winner.
  • Is it more important than everything else? This is a great way to filter ideas: is your idea the most important thing we can do to improve the Web? There’s not always a direct tradeoff. The people who work on a browser’s JavaScript engine are often not the same people who work on a browser’s canvas API, for instance. But there’s always an opportunity cost — adding one feature means we won’t have the time or resources to add another.

So that’s the first part of the answer: we say “no” because we don’t have time to add everything. <main> is a great example of this. In my opinion, the value it adds is so minimal that it just isn’t worth the cost.

Next, let’s look at design. The way we usually approach ideas is that we describe the problem, then we come up with solutions to the problem and compare them by evaluating them against the problem. This is where most concrete proposals run into a “no”, because something else got the “yes” instead.

<picture> is an example of this. We described the problem (that took a few months of back and forth), and then once we had a problem description, I looked at the various proposals and synthesised a solution based on those that addressed the problems adequately while trying to avoid some common design pitfalls based on lessons we’d learnt from previous ideas. So for example with <picture>, we learnt with <video> and <source> that having multiple elements for selecting a resource is a huge design pitfall, so when designing a solution to the problem here, I avoided that (hence the srcset="" design based on CSS’s image-set() proposal).

So that’s the second part of the answer. We say “no” to some specific proposals because we’ve come up with other (better) solutions instead.

The second implicit question here was why do I say “no” so much, as opposed to other people. This is basically politics. It’s hard to say “no”, in part because of human nature, but also in part because when you say “no” in this kind of context you tend to invite argument. Most browser vendors don’t have time to have these arguments. I do. It’s my job, and I’ve gotten pretty good at saying “no” over the years. So a lot of the veteran browser engineers will just redirect people to me and expect me to say “no” for them. This lets them get on with their job of writing a browser, redirecting all the ire and arguments to me, whose job it is to field them. Or they’ll see an e-mail to the WHATWG list, think “oh my, that’s crazy”, but just stay silent because “Hixie will deal with it”.

In reality, I can’t really say either “yes” or “no”. What I say doesn’t mean anything: I don’t write any browsers. The browser vendors say “no” to me all the time by not implementing what I’ve specced. Just last week I revamped part of the spec (on context menus) because none of the browser vendors implemented it. One of the specs I spent years of my life on — XBL2 — has gone precisely nowhere because the browser vendors just don’t want to implement it. (My main mistake with XBL was trying to solve the whole problem at once, rather than doing it in incremental steps that implementors could more easily deal with.)

Similarly, there’s stuff that was never specced, indeed stuff that I’ve said “no” to myself, which the browser vendors nonetheless implemented. Again with the context menu example: Gecko implemented it by having an element called <menuitem>, which I argued forcefully was a bad design. They disagreed with my arguments and implemented it anyway, and so (eventually) I updated the spec to have <menuitem>. (This isn’t a criticism of Mozilla. It’s how these things are done. They did nothing wrong here.)

Do you feel there’s enough feedback from HTML authors, rather than vendors, getting through to specification editors/authors? (from @webr3)

I don’t know about “enough”. Is there ever “enough” feedback?

We do get a lot of feedback from Web developers, but it’s true that most of it has to be collected by seeking it out on forums, sites like Reddit, Twitter, Google+, people’s blogs, etc. I have some Google Alerts that lead me to a lot of places where people are complaining about HTML in one way or another, which I use as feedback. It’s almost certainly not enough. I wish we had more authors participating directly by either filing bugs or participating in the WHATWG list. People probably don’t realise how much feedback we get from developers, because they don’t see me reading the blogs and so on. Also, a lot of the feedback browser vendors send us is actually of the form “Web developers tell us that…” (though they often don’t say that explicitly).

The problem, to be honest, is that most authors don’t know what they want. Many years ago, Google actually paid for a usability study for one of the features I was speccing (microdata) and it was absolutely fascinating to see how people’s actual performance was so divergent from their impressions. We’d ask them questions like, “Which would be simpler, this or that?”, and then we’d actually test them by having them use the options, and there was just no relationship between what people said they wanted and what people were actually able to use.

Often when people send feedback (not just authors; pretty much anyone who hasn’t been in the process for a long time starts this way), they send feedback along the lines of “I want to add feature X” or “I want feature X to be extended in manner Y”. But when we drill down and ask them, “What problem are you trying to solve?”, or, “What’s your use case?” (same question but phrased differently), we often find that either (a) they actually don’t have a real problem and just thought that it would be a good idea, or (b) their solution wouldn’t actually solve their problem. Often we’re able to come up with much simpler solutions (or point to already existing solutions), which is quite satisfying.

Two and a half years ago, I asked you, “Would you like to be the HTML 6 editor?”. You replied, “I might want a change of pace when we’re done with HTML 5.” How come you decided not to take that holiday and continue editing HTML?

We’re not done yet. I still have 238 e-mails and 163 bugs remaining.

Do you have an exit strategy, or would you like to edit HTML for the forseeable future?

Well, I could stop any time, really. So long as I find it interesting and implementors respect my work, though, why stop? We have a severe lack of spec writers who are able to write good specs.

For styling form components, we were told to wait for XBL, then to wait for Web Components. Anne van Kesteren said, “After a decade of waiting for this, I think it might be time to start calling this vaporware.” Thoughts?

If anyone has a better proposal, I’m all ears.

You work for Google, which has a widely deployed browser, a mobile operating system, and massive web properties. Do your employers require you to align specifications to their business objectives or otherwise influence your specification decisions?

No, quite the opposite. When I started, I was given very explicit instructions to the effect that I should put the Web’s long-term interests ahead of any of Google’s short-term interests.

Having said that, of course, one of the reasons I wanted to work for Google is the unique perspective one can get from working here and from having access to the data Google has. There’s no question that that has influenced my decisions.

Do you have other duties apart from specification?

I basically work on the HTML spec full-time, but yes, I have some other duties internally.

Is the Web Platform becoming too complex (Web Components, shadow DOM, etc.)?

Too complex for what?

For the amateur with something to say, rather than professional coder? Or new entrants — e.g., Geri Coady’s Pastry Box article?

The platform has been too complex for any one person to fully understand for a long time already. Heck, there are parts of the Web platform that I haven’t even tried to grok — for example, WebGL or IndexDB — and parts that I continually find to be incredibly complicated despite my efforts at understanding them — like the Unicode bidirectional text algorithm or the subtler aspects of JavaScript’s prototype model. I’m pretty sure most authors don’t understand the precise details of margin collapsing in the presence of floats and divs with clear set, or the inline box model.

This isn’t surprising, though. If you define the “Windows” platform as everything from the NT kernel API to the Direct3D API and everything in between, I’m pretty sure you’d quickly come to the conclusion that nobody understood that whole platform either.

I don’t think this is a problem.

The WHATWG began because the W3C told you, “HTML was dead. If you want to do something like HTML5, you should go elsewhere.” Now that the W3C has come to its senses, is it time for the WHATWG to hang up its spurs and for its participants to work inside W3C to continue the development of the web platform?

We tried (2007–2012). It didn’t work out. In fact, we ended up spinning more specs out of the W3C! The WHATWG has about 12 specs spread amongst eight or so editors now.

In what sense didn’t it work out, and why?

We have different priorities, different visions, different approaches. I’m probably not the right person to give an objective answer, though.

You seem to have most of your spats with people who work in the field of accessibility. Why is that?

I don’t know. I wish I did.

You told me, “People with disabilities are just as important to me in my work on HTML5 as is anyone else”, but I guess they would say you don’t pay enough attention to the needs of disabled people (longdesc, table summary, re-writing rules for alt text). Presumably therefore you feel that disabled people are better served by removing these features. What do you base that assumption on?

The premise of the question is that there’s one accessibility community that speaks with one voice and has one opinion, and that they entirely represent the exact homogeneous desires of all disabled people. But none of that is true. There are multiple Web standards accessibility communities. People within those communities often don’t agree with each other. There are lots of disabled people with lots of different opinions and different needs. The accessibility communities don’t always represent all the disabled people’s needs. And so forth.

Taking the specific features you list:

  • longdesc="" is a solution in search of a problem, which virtually no author uses, and which those who do use almost entirely use incorrectly, and which therefore users have long ignored. Discouraging its continued use means authors are more likely to spend time on things that are more likely to improve accessibility. Mark Pilgrim, author of “Dive Into Accessibility”, wrote a post about this.
  • Table summaries: check out the HTML spec for <table>. The first paragraph says that <table> is for representing tabular data (incidentally discouraging the use of <table> for layout tables, which is good for accessibility). The second paragraph says what tabular data is (a grid). The third paragraph provides a link to the section that defines what the table model is. The fourth paragraph encourages authors to “provide information describing how to interpret complex tables” and links to an entire section describing how to give table summaries. That section has six different suggestions for how to do it.
  • Rules for alternative text for images: the section on <img> first says that <img> represents an image, then briefly says that how you give the URL for the image (it goes into more detail for that again later), and then the third sentence points at the section on alt="" — which consists of literally a dozen different subsections on how best to give alternative text for images in a wide variety of cases. When this was first written, it was probably by far the most detailed description for how to write alternative text ever published.

So we didn’t remove two of those three features. We expanded them dramatically. The one feature we removed was really a misfeature, and we have the data to back that up.

What’s been your biggest mistake? What are you most proud of?

I’m probably most proud of the HTML parser specification. Years ago it seemed like such a preposterously absurd task to take on that I said I would never do it. And it was huge (and we’re not quite done yet; there’s at least one major outstanding bug). But this, more than anything, has been the crowning achievement of the HTML spec. We went from a world where four browser engines had four completely different approaches with radically different behaviours in every edge case, to a world where the browsers agree so closely on their behaviour that we have an almost unheard of level of interoperability. There have been academic papers written about it. It’s completely changed how we write parser specifications, and I expect the knock-on effects on other specs will continue for years. It used to be that people said that specs should only define how to parse conforming content and should do so in a declarative fashion. But now saying that sounds hopelessly naive and old-fashioned.

My biggest mistake…there are so many to choose from! pushState() is my favourite mistake, for the sheer silliness of ending up with an API that has a useless argument and being forced to keep it because the feature was so desired that people used it on major sites before we were ready to call it done, preventing us from changing lest we break it. postMessage()‘s security model is so poorly designed that it’s had academic papers written about how dumb I was, so that’s a pretty big mistake. (It’s possible to use postMessage() safely. It’s just that the easiest thing to do is not the safe way, so people get it wrong all the time.) The appcache API is another big mistake. It’s the best example of not understanding the problem before designing a solution, and I’m still trying to fix that mess.

At the less-technical and more-political level, I think taking WebSockets to the IETF was a huge mistake. It ended up delaying the spec for literally a year without any resulting improvements, and they made a number of changes that IMHO reduce the protocol’s security. (Again, it’s possible to use it safely, it’s just not as easy as it was before the IETF got involved. Ironically, they broke the very things we learnt to do right after getting them wrong with postMessage().) We’re still waiting for things like compression and multiplexing, which we would probably have had a long time ago if we hadn’t gone to the IETF.

Also, when I designed the Web Storage API I made a horrible mistake by making the API synchronous and requiring consistency during a script’s execution, which essentially became the one place in the whole Web platform where, in theory, browsers are required to block cross-process. Since browsers don’t implement that, we instead have an API where there’s no consistency guarantee, which is rather scary.

Outside of the HTML spec, one of my biggest mistakes was not realising, back when I was first in the CSS working group, that specifications were not immutable. CSS2 had these vague rules about margin collapsing and about the inline box model which David Baron and I took as essentially immutable constraints around which we were to strictly define the margin collapsing model and the inline box model. We succeeded, in that now the spec has mostly well-defined models for both those things, but boy are they insanely complicated. What we should have done instead is just break the constraints and come up with something simpler, ideally something that more closely matched what browsers implemented at the time.

One of the side-effects of that kind of thinking (not directly my mistake, though I didn’t argue against it as far as I recall) is that we ended up with “Quirks Mode” and DOCTYPE switching. What we should have done is just made the specs match browsers and not bothered with all these modes.

I also made mistakes with the Acid tests, wherein I tested things that the specs required but which in retrospect it would have been better to ignore, which ended up encouraging browsers to implement things that we later realised it would have been better all around if we had skipped. Some of those we were able to mitigate, others not so much. Acid3 had some stuff around SVG fonts that we should have never had. Acid2 had some crazy stuff around SGML comments that we were thankfully later able to totally abandon.

I made a number of mistakes in the development of XBL2 (as mentioned earlier), but since the result of those mistakes was that it’s getting ignored, the only real long-term cost has been the opportunity cost and delay in getting a solution in that space.

I’m sure I’m forgetting some huge mistake I’ve made that everyone is yelling at me for. (I asked for suggestions for this question on IRC, and after we were done enumerating a bunch of mistakes, Anne asked, “That’s a long list. Why do we trust this guy again?” D’oh.)

Urban geek legend has it that you invented Web Sockets because you wanted to control your model trains through the browser and couldn’t. True or false?

Obviously there’s a lot of demand for something like Web Sockets, so it’s not like it was only because I want to control my trains that we worked on that, but it was definitely a key motivating factor for me. Without Web Sockets I was forced to use hanging GETs and all the other techniques people will be familiar with, which introduces precious milliseconds of latency that can be so destructive when you have two locomotives speeding towards each other. I’ve since used Web Sockets in pretty much every non-trivial development project I’ve done.

You specified microdata, which even you dislike, because RDFa was ugly and hard to write…

It’s not so much that I dislike microdata so much as I don’t think the problem microdata (and RDF, etc.) solves is an interesting problem that should be solved. Of course, enough people think it is a problem that should be solved that I approached it like all the other problems. It’s a good example of how the HTML spec is not just a reflection of my wishes.

…The WHATWG shot across RDFa’s bow worked. RDFa Lite now does everything microdata does, while also being compatible with Facebook’s Open Graph Protocol…

RDFa Lite doesn’t do everything microdata does. There’s a number of things that microdata does (or doesn’t do) that are absolutely key:

  • not have anything to do with RDF
  • not have any support for any prefixing mechanism
  • have integration with the drag-and-drop API

There are probably others, too, but I haven’t studied RDFa Lite carefully.

Why is “not have anything to do with RDF” key?

It’s where microdata and microformats get most of their simplicity compared to RDF-based technologies.

…To avoid fragmentation, are you going to withdraw microdata as a spec, add an RDFa API, and use RDFa Lite instead? If not, why not?

Well, at this point microdata is in wide use, so there’s no way to remove it even if we wanted to. But since RDFa still doesn’t solve the same problems, it hasn’t come up.

RDFa (or rather, RDF) and microdata have fundamentally different data models. RDF is a triple (quad, really) database. Microdata represents tree structures. Microdata has more in common with JSON than RDF.

What are your thoughts on angle brackets…

They’re pointy? I don’t know. Are angle brackets something people have thoughts on?

…and how does HTML stand up to JSON? (from @pal_nes)

Different solutions to different problems.

JSON’s missing one major feature that I wish it would get, which is defined error handling (even if it’s only XML-style “you must abandon the parse if it there is an error”). Right now, handling of broken JSON seems to vary from parser to parser.

Other than that, I like JSON and often use it. I think people get very attached to generic syntaxes, though. Sometimes the best syntax is just newline-separated strings in a plain text file. Sometimes it’s a nested tree like JSON. Other times it’s a nested annotated tree like XML. Sometimes it’s a binary bitmap. I think people shy away from defining their own syntaxes more than they should. Writing a parser is easy and is a very, very well studied part of computer science. Using something like JSON makes sense if what you want to serialise is a static JavaScript structure with no cross-references. If your data structure is something else, then using JSON doesn’t generally make more sense than using a dedicated format — either way, you’re going to have to get the data out and piece it back together into your own internal representation.

Also, often when people define generic syntaxes, they go a bit crazy. When you’re defining a dedicated format (or a vocabulary for a generic format, same thing really), you usually don’t have time to go crazy and define wild features, because your motivation is to solve your original problem and designing the language is a necessary evil, not the end goal.

Is it a problem if people have no markup in the <body> and generate the DOM with script?

It’s obviously a problem for users who have scripting disabled, but other than that, it’s just an authoring choice.

There are significant advantages to having a static description of markup. You can validate it, for example, to catch semantic errors (such as accidentally putting an <input> in a <select> instead of using <option>). HTML these days has several features to make it easier to do this while writing a Web app — e.g., hidden="", DOM cloning, etc.

But equally there are advantages to generating things from script. For one, if you want to generate several instances of something, right now the easiest way is to describe the structure in JavaScript calls with the data you want to substitute into your template being right there.

Personally, when I write Web apps (mostly games), I tend to use static HTML for the parts of the app that don’t change or that only appear once, and JavaScript calls to generate the parts that appear more than once. For example, one of the games I’m working on has a list of maps, and so the <ol> for the list is hard-coded in the HTML, but the <li>s are generated dynamically.

Talking of script, what do you think of DART?

I haven’t studied it (or the newer JS proposals, for that matter) enough to have an opinion. If it’s intended to replace JavaScript as the Web’s language, they have an uphill battle ahead of them, though. Replacing any part of the Web is extremely hard.

I wrote about the difficulty of replacing the whole Web last year. Replacing any part of the Web (as opposed to extending it) is similar in difficulty, though on a proportionally smaller scale.

How do you think the long-term development of devices and interaction models will impact the development of web standards? (from @wcagtest)

I don’t think it’ll affect the development at all. There’s no difference between new interaction models and any other new feature. The Web and Web standards themselves will obviously be impacted, but I have no idea how. I’m fascinated to find out how the Web will evolve in the face of projects like Google’s Glass or devices like the Pebble.

I am sad that the Web didn’t handle small screens — and later, touch UI — that well. I would’ve hoped that the Web’s media-independent nature would have made that work better. For small screens, honestly, I mostly blame Web designers for assuming big screens and not thinking flexibly. We’re seeing that change now. For touch, though, I wish we had done a better job of mapping the UI to the Web’s generic events. A touch gets mapped to a “click” event easily enough, but drag-and-drop never got mapped, pinch gestures didn’t get mapped to wheel events, etc. Mainly I think this is because the first truly successful touch browser set the standard, and it was developed mostly in secret with a small team many of whom, as I understand it, weren’t Web veterans.

Will native apps triumph over the Web on mobile devices?

Native platforms and the Web have very different characteristics. The Web is by design radically vendor-neutral, and (to a lesser extent in practice) device-neutral. This has huge benefits: nobody can single-handedly kill the Web, for example. If you write a Web page or application today, and then tomorrow your desktop operating system vendor or your mobile phone handset vendor goes bankrupt, you can just buy another device and your page still works. If you target a proprietary platform — e.g., Amiga or OS/2 — that then loses the support of its vendor, the result is that your application is no longer usable.

The cost of having a system immune from the whims of a single vendor is that by and large, innovation doesn’t happen in multi-vendor discussions. If you have a proprietary platform, it’s easy to add features to it: you just do it. No need to argue with anyone. On the Web, a feature can only be added if every major implementor agrees it’s worth adding, and that usually only happens once it’s been proven in a native platform. So native platforms have the edge when things are rapidly innovating.

This is why the mobile world today has so much focus on native apps. Every new generation brings radical new features, and the Web will always be behind on those. So the cutting edge is native.

You can see this on the desktop. Innovation on desktop operating systems has slowed down dramatically, and as a result the Web has been able to mature there. The result is that on desktop, Web apps are doing great (so great that it’s viable to create a desktop OS that does nothing but bring up a Web browser, in fact). Mobile is where desktop was a decade or two ago, in terms of innovation.

What’s the biggest danger to a free, open Web at the moment?

Patents.

What’s the very next thing on your to-do list?

The top thing on my bugs list is “Spec for document.open() doesn’t match reality when the parser is script-created”. That sounds like a hard one. Let’s see…top thing on my e-mail pile right now is…some even harder stuff do with the HTML parser and feedback from [Boris Zbarsky] about some very subtle aspects of the security implications of certain DOM APIs. Yikes. Maybe I’ll do lunch instead…

Interview with Ian Hickson, HTML editor originally appeared on HTML5 Doctor on January 8, 2013.

]]> https://stevefaulkner.github.io/html5doctored/interview-with-ian-hickson-html-editor/feed/ 26 Review: Pro HTML5 Accessibility by Joshue O Connor https://stevefaulkner.github.io/html5doctored/review-pro-html5-accessibility-by-joshue-o-connor/ https://stevefaulkner.github.io/html5doctored/review-pro-html5-accessibility-by-joshue-o-connor/#comments Tue, 11 Dec 2012 10:00:48 +0000 http://html5doctor.com/?p=4830

Related Posts:

]]>
Pro HTML5 Accessibility is an exhaustive book. Author Joshue O Connor is senior accessibility consultant with National Council for the Blind of Ireland’s Centre for Inclusive Technology and a stalwart of many W3C working groups.

Don’t be afraid of the title. The book doesn’t assume that you’re a professional accessibility expert – quite the opposite; the first 100 pages don’t really deal with HTML5 at all, but survey the landscape of disability, assitive technologies and W3C WAI-ARIA. The last chapters of the book usefully survey testing methodologies and tools which will be invaluable to the lone developer told “oh, and it must be accessible/ DDA-/508-compliant, too”.

Joshue does an admirable job of explaining how to use HTML5/ARIA to make sites accessible, and gives a thorough overview of how current browsers communicate new widgets (date pickers, sliders, video controls etc) to assistive technology now, rather than in some glorious unspecified future.

He writes engagingly, too: “Remember that the <div> and <span> elements are semantically neutral elements. They have no meaning, poor things, and are merely empty hooks—ciphers for you to do with what you will. They cheer up to no end when you give them meaning. Existential crisis averted!”

I also appreciated Joshue’s pragmatism: “Good semantics are really important, but real-world accessibility is very nuanced—particularly for new content and element types. However, bear in mind that an unencoded ampersand (which will throw a validation error) never resulted in an inaccessible webpage.”

However, I didn’t understand “Having some heading structure, rather than none, on a web document is far more important than merely ensuring the headings are ordered in the correct way.” Surely “merely ensuring the headings are ordered in the correct way” is exactly the same as “having some heading structure rather than none”?

Pro HTML5 Accessibility by Joshue O Connor

It’s also unclear to me why the author chose to markup buttons to control a video player as

 
<div id="back" tabindex="0">
<img src="player/back_button.png" role="button" alt="Jump Back" />
</div>

rather than simply use a <button> element which by default has a role of button and is focussable. But it doesn’t much matter; it gets the job done.

There are some errors which the technical editor should have picked up. Chapter 3 says “JavaScript has some event handlers that can be activated only by using the mouse, such as onClick”, which isn’t strictly true. The same chapter also says “IE 9 doesn’t support the <video> element”, which is just wrong: it does. A cursory code-test would have shown that chapter 5’s example <img scr="myserver/usful_andgroovy_image.png"> won’t work, as there is no scr attribute (it’s obviously a typo for src).

The most significant failing of the book isn’t the author’s fault: it’s the lack of love for presentation that I’ve found endemic in all Apress books lately. For example, the tables in chapter 5 could easily have been formatted for a more attractive presentation, but they look exactly as a basic Word document. Similarly, the multi-page bulleted lists could easily have been a single, multi-column page.

It looks as if Apress just doesn’t care about quality, which is incomprehensible from a publisher. In a publishing environment where ebooks have advantages such as portability, searchability, updateability in case of errors, dead-tree publishers need to work hard to ensure their products remain competitive. They need to play to the traditional strengths of print: beautiful layouts, colours, good design and high-quality paper. We see these in books from Five Simple Steps, Smashing Magazine and A Book Apart. I’ve only seen a PDF of this book, but a previous physical Apress book I own has a paper quality redolent of 1970s East German toilet paper. Certainly Apress has expended no effort at all to lay out the pages for a pleasant read.

That rant aside, the content of this book will be invaluable to a developer new to the world of accessibility, trying to use modern web standards.

Review: Pro HTML5 Accessibility by Joshue O Connor originally appeared on HTML5 Doctor on December 11, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/review-pro-html5-accessibility-by-joshue-o-connor/feed/ 10
Interview with Robin Berjon, HTML5 editor https://stevefaulkner.github.io/html5doctored/interview-with-robin-berjon-html5-editor/ https://stevefaulkner.github.io/html5doctored/interview-with-robin-berjon-html5-editor/#comments Tue, 13 Nov 2012 14:05:26 +0000 http://html5doctor.com/?p=4788

Related Posts:

]]>
At the recent Apps World expo in London, Doctor Bruce spoke on a panel with Robin Berjon, recently appointed W3C HTML5 editor. He took the opportunity to ask Robin some questions on process, living standards and male grooming.

Bruce Lawson and Robin Berjon
Bruce and Robin

 

Tell us about yourself.
My name is Robin Berjon (@robinberjon, berjon.com) and I live in Paris with wife, daughter, and cat. I’ve been hacking Web and open source stuff since 1996. A little over ten years ago I started becoming involved in standards with the hope of helping make hacking with Web technology as cool as I thought it could be. I hadn’t realised that “as cool as it could be” would be notion prone to evolving so fast over time.

How long have you been editor of HTML5?
Since September, so a touch over two months by now.

But isn’t Hixie editor?
Hixie is the editor of the WHATWG HTML specification; I’m part of the W3C team of HTML editors. Essentially the same source document is used by everyone, but we produce different views on it. The WHATWG view is a single document containing features at varying levels of maturity; the W3C publishes that document as multiple separate specifications and currently focuses on a more stable subset of features.

It’s a big document — there’s room enough for a broad community to collectively figure out the future of HTML.

What does the job entail? Just tidying up and getting tests written? Isn’t that terribly boring?
Our goal is two-fold. First, we are on track to producing a stable snapshot of HTML5 by 2014. The first step in getting there is to produce a draft that is ready for intensive testing, which is the next step in the W3C process. In parallel, we will shortly start publishing drafts on the HTML.next track (also known as HTML 5.1) including a number of new features. This basically corresponds to switching to something that resembles software development best practices in which one can choose either to use a stable release or the nightly build.

Based on the stable snapshot, we will ramp up our testing effort in earnest. To some, testing is a tedious occupation but I beg to differ. With testing, you get to break stuff. And other people’s stuff, too! And those people then thank you for it. Remember all that time spent working around browser bugs? Well with specification testing you get to turn that around, find the bugs instead of avoid them, and then wait as the browser vendors fix them. It’s Web developer payback time!

And there’s a host of things to be done for HTML 5.1 such as fixing AppCache (with our friends from WebApps) or evaluating the various proposals for responsive images. There’s no point in waiting for a finished specification to start work on the next one, and one thing that I find particularly exciting is that a lot of the novel stuff is exciting tech that’s brought to us by the community.

It’s not all just mopping up, though, is it? You’re already looking at new features. For example, W3C is considering <picture> element; WHATWG isn’t. Is there a danger of differing specs for the same markup language?
I’m not really worried about differing specifications because there’s a reality test: what’s really implemented out there? If you have two specifications saying different things about the same feature, and that feature happens to be reasonably reliably implemented, then one of those specifications is wrong. And it’s pretty hard to stay relevant while being wrong.

I would actually like to see more variation in input rather than less. It can be rather daunting for a group of Web people who care a lot about one specific feature to start contributing to any standards group. A lot goes on there, there tends to be a fair bit of email, the mailing list’s culture can be hard to grasp even if it’s not downright aggressive. This puts a high bar on such contributions, high enough that it is too rarely turned into a reality.

At the same time, it is difficult for even seasoned Web hackers to draft specification text without input from browser vendors and experienced standardistas, which in turn can lead to frustration as carefully crafted and nurtured work is turned down.

So we need to figure out how to make this type of group working on a specific improvement work more easily, more often. We already have a lot of the technical infrastructure with Community Groups, but getting the human bits to work is always the hardest part. I think that the work going on in the Responsive Images Community Group is a truly great experiment (even if it means occasional drama) and that the experience they are building up will serve to guide a lot of subsequent groups working in a similar fashion.

I bring this up because successful open projects are those that can keep bringing in new contributors over time. The Web standards community as a whole needs to do a better job there — and we will! So no, I’m not worried about differing specs. So long as we can figure out how to get all the browsers on the same page one way or another, the more input the sexier.

I recall someone saying that 20,000 test cases will be needed? That’s a lot – how are you going to do it all?
It’s probably a fair bit more than 20,000 since we already have over 11,000 and aren’t anywhere near satisfied yet. But the exact number is not as important as the fact that the number will be big. In order to pull this off, it would be tremendously helpful to benefit from broad community involvement.

And as it happens, that’s precisely something that’s been ramping up. You’re of course familiar with Move The Web Forward, the grassroots movement that’s pushing for a better Web. A part of that is Test The Web Forward. It’s a series of events specifically dedicated to making the Web a better place for all through testing. There was a first event in San Francisco last summer, and we’ve just recently had one in Beijing this week, and another in Paris. The TestTWF folks are looking into more events in other locations, so if you’re interested in having one in your city make your voice heard.

What happens there is that we kick off with a few presentations to explain how testing works, and then we all get our hands dirty in a hackathon with ample help from testing experts. For developers it’s a
great way to learn more about Web technologies and to get involved in a project that gives back to the Web. Plus: payback!

I was at the Paris TestTWF a couple weeks ago, and I have to say that I’ve been overwhelmed with how good the participants were. The turn-out was great, and people there just showed up, asked great questions, and immediately started crunching on tests. It’s not as if I didn’t already know that the Web community rocks, but it’s still amazing to see just how much people care and how dedicated so many are to improving the Web.

The w3c has “chopped up” HTML into modular specs; WHATWG hasn’t. Why?
A lot of people, including spec reviewers, test writers, and implementers have told us that they find it easier to handle smaller specifications because they’re easier to swap into one’s brain, and because you can more easily have someone work on a well-defined area. I think that Tim Berners-Lee explained it well a few years ago.

Of course, a lot of the Web platform is intricately meshed together so that cutting things into smaller pieces can be difficult, and at times risks hiding vital information. This is particularly true of existing features; for new features we certainly intend to try hard to make things as modular as possible. That’s why we expect a lot of the new features developed in the HTML WG to be created as extension
specifications. This does not mean that they have lesser status that the “core” HTML specification, rather it becomes a logical, modular way of adding new functionality. It also makes it easier for third parties, such as smaller, more focused communities or even individuals with a good ideas, to provide very concrete input that can more readily be reviewed by the group. Great examples of this include the Responsive Images work or the <main> element.

At the end of the day a lot of it boils down to taste, or perhaps more importantly to how your work in relation to those specifications is organised. If you’re working on all of it at once, it may be simpler to keep it all in one place; but if you’re trying split work off in a larger team you might prefer some predefined boundaries between documents. At least that’s the impression I get from the input people provide whenever this topic crops up. As far as I’m concerned I find that the extension specification model is more conducive to community contributions and so it definitely has my preference.

Why do we need W3C snapshots and versions, instead of a “living standard”?
It’s a big Web out there and a lot of people are involved in it in different ways. Again, whether you prefer snapshots or the bleeding edge document likely depends on what you’re doing with it. If you’re continuously working on and with the spec, producing snapshots is a drag. At the other end of the spectrum if you’re burning the implementation into silicon and you need to interoperate with others who are doing the same, you want something that’s almost literally carved in stone. In between those extremes, the specifics of your situation as a user of the spec will make you fall on either side of the fence.

One of the notable costs of a document that changes continuously is that for any work you do with it you need to track it with equal continuity, which can be quite taxing. In order to enable more loosely coordinated work on improving the Web platform, producing snapshots (e.g. for test writing or implementing) can help a fair bit.

It’s important to notice that stability is important for legal reasons: companies like to know what their commitments are and what others have committed as well. W3C’s Royalty-Free patent policy helps ensure that these commitments make it possible for anyone to implement Web standards without paying royalties. Snapshots help us keep the Web free.

That’s why we’re working on making both possible in parallel. The setup we’ve progressively been putting together enables us to have a continuously updated document and snapshots taken from it at regular intervals. This just might be one of those cases in which we can actually make everyone happy.

You’ve put the HTML spec on github. Why?
We wanted to go with git anyway since its branching features are a great match for the approach we’re taking in which we have a stable branch that is used to produce snapshots and a more advanced branch into which new features go.

If you mix that with our desire to involve the community more in the standards process, then GitHub was the logical choice: that’s where our community is.

Do you communicate much with WHATWG? Some of them aren’t great fans of W3C.
Several of us hang out permanently on the #whatwg channel, and on the WHAT’s mailing lists. I can’t say that it has been anything other than friendly and pleasant.

Some people in the WHAT community have criticism of how the W3C operates. A lot of that criticism is constructive, and I am more than happy to relay it inside. W3C has a long history of doing the right thing with respect to opening up the standards process (e.g. with its RF policy or working in public). I’m confident that the consortium will continue in this vein, even if it can occasionally take time for some things to change.

And on the rare occasions when such criticism veers towards trolling, everyone’s experienced enough with online discussion not to bite.

Is it time for Hixie et al to disband WHATWG and return HTML to the W3C fold, now they’ve won?
You’d really have to ask them that!

The WHATWG has certainly done an astounding job of bringing HTML back to life and making it the biggest blip on anyone’s radar. I don’t think that that necessarily entails that it should close shop just yet, if ever. As I said, I believe we should ideally have more decentralised work on improvement, not less — even if it’s difficult.

Is it true that Tim Berners-Lee comes to you for tips on male grooming?
I can’t possibly disclose the list of those who come to me for advice, but it is certainly true that since my breakthrough feature in GQ France an increasing number of Web hackers have been asking how to approach the ruggedly handsome magnetism of these roguish good looks.

Thank you very much Robin. (Evidence of Robin’s “ruggedly handsome magnetism” may be seen in his TPAC dance-off.)

Interview with Robin Berjon, HTML5 editor originally appeared on HTML5 Doctor on November 13, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/interview-with-robin-berjon-html5-editor/feed/ 7
Review: The Truth About HTML5 For Web Designers https://stevefaulkner.github.io/html5doctored/review-the-truth-about-html5-for-web-designers/ https://stevefaulkner.github.io/html5doctored/review-the-truth-about-html5-for-web-designers/#comments Tue, 26 Jun 2012 12:52:36 +0000 http://html5doctor.com/?p=4671 The Truth About HTML5 For Web Designersis an ebook self-published by Australian developer Luke Stevens. I disagree with some of Stevens' conclusions, particularly in his discusssion of the new semantics, but it's solidly researched and lots of fun if you like hearing someone with strong opinions rant for a while (as I do). I enjoyed reading his book and, for the price, recommend that you have a look.

]]>
The Truth About HTML5 For Web Designers is an ebook self-published by Australian developer Luke Stevens.

TL;DR:

  • The website promises “This is the book for web designers, web developers, and front-end coders who want to get up to speed with HTML5 in 2012”. It isn’t.
  • It is a healthy antidote to all the bullshit out there claiming that HTML5 cures cancer and brings about world peace
  • At only $4.99, it’s very cheaply priced and you’ll probably learn something or, if not, you’ll have some useful antidote to the hype. So buy it!

cover image

Longer review

Stevens’ book is not a really a tutorial. If you know nothing about the subject, I doubt whether this book would teach you enough to start coding HTML5. But for those of us who’ve been following the development of the language, it’s a great commentary on the good, bad and the ugly of HTML5.

If such a thing interests you I heartily recommend that you buy it although, as with any polemic, there are parts of it I disagree with.

For example, Stevens writes “There was—and is—no unifying vision of “HTML5”.” Now this is inaccurate. The unifying vision of HTML5 was to extend the Web without breaking it; evolution rather then revolution, with a set of design principles:

  • Support Existing Content
  • Degrade Gracefully
  • Do not Reinvent the Wheel
  • Pave the Cowpaths
  • Evolution Not Revolution
  • Solve Real Problems
  • Priority of Constituencies
  • Secure By Design
  • Separation of Concerns
  • DOM Consistency
  • Well-defined Behavior
  • Avoid Needless Complexity
  • Handle Errors
  • Media Independence
  • Support World Languages
  • Accessibility

In his chapter on the structural elements, Stevens complains that the new markup elements are badly defined and hard to learn:

These are serious problems that hurt, rather than help, web standards. Markup should be lightweight, easy to learn, and easy to apply. It should not require mental gymnastics to try and work out what to use where.

Anything new is hard to learn. It’s not so long ago that we were still coming to grips with how to use HTML 4, and building up a canon of best practice as a community with efforts such as Dan Cederholm’s Simplequiz. The language has increased the number of elements by more than 30%, as well as gained many, many new APIs and become generally much more complex . People haven’t instantly understood all the new changes. I’m comfortable with that; change takes time to settle.

Stevens also suggests that the new elements are somehow tarnished because Hixie made them up before the Google research that analysed 1 billion web pages, and therefore suggests that aren’t useful. He quotes Hixie to back up his assertion:

Hixie: Me and other WHATWG contributors [added them], [in] 2004ish, because they were obvious elements to add after seeing how authors used HTML4. We later (late 2005 early 2006) did some objective research to find out what the top ten HTML classes were and it turned out that they basically exactly matched the elements we had added, which was convenient.

But, as Hixie says “they were obvious elements to add after seeing how authors used HTML4”. These weren’t just dreamed up out of nowhere – they were dreamed up out of real, but anecdotal, experience of what authors really did, which was then corroborated by objective research. This seems fine and reasonable to me, and doesn’t feel like the smoking gun that Stevens believes it is.

The author dislikes the names of the new structural elements (<header>, <aside> and <footer>) because, he says, they don’t closely match the way that designers would describe areas of the page: Header, Content, Sidebar and Footer. Those seem to me to be quite a good match, but Stevens doesn’t think so and prefers the ARIA roles banner, main, complementary and contentinfo, which to me feel more alien.

Stevens laments that multiple meanings of some elements:

In HTML4 a paragraph is a paragraph is a paragraph. In HTML5 an “article” is a forum post is a blog comment is a widget is a an actual article.

I disagree. We’ve all seen “paragraphs” that are not paragraphs at all, but merely sentence fragments – for example

<p>Products include:</p>
<ul>...</ul>

Is “Products include” really a paragraph? Of course not; it’s merely that <p> is the best-fitting element to use. And so it is with the multiple uses of <article> in the spec. At least there are suggestions in the spec that may encourage some kind of conventions amongst developers.

Stevens continues “If an element has such broad meaning, how can it be more ‘semantic’”?” This is not a new problem with HTML5. In the HTML 4 spec is the ridiculous suggestion in the spec that the <dl> element is appropriate for marking up conversations on the grounds (I guess) of its default visual rendering in browsers. I agree that we need to keep HTML lightweight, so it will never be possible to capture every subtlety of meaning with a limited set of elements, but I strongly feel that HTML5 elements are much more tightly defined than HTML 4.

Lastly, Stevens sees no practical value to the HTML5 document outlining algorithm:

So user agents (screen readers in particular) will have very little incentive to ever use HTML5 outlines—the main point of these elements—as a means of navigation, given they’ll be (and already are) an utter mess.

For the last eight months, the largest screen reader on the market, JAWS, has supported HTML5 outlines (albeit buggily) so presumably they do see an incentive to use it.

Conclusion

I disagree with some of Stevens’ conclusions, particularly in his discusssion of the new semantics, but it’s solidly researched and lots of fun if you like hearing someone with strong opinions rant for a while (as I do). I enjoyed reading his book and, for the price, recommend that you have a look.

Review: The Truth About HTML5 For Web Designers originally appeared on HTML5 Doctor on June 26, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/review-the-truth-about-html5-for-web-designers/feed/ 10
HTML5 adaptive images: end of round one https://stevefaulkner.github.io/html5doctored/html5-adaptive-images-end-of-round-one/ https://stevefaulkner.github.io/html5doctored/html5-adaptive-images-end-of-round-one/#comments Wed, 16 May 2012 10:36:45 +0000 http://html5doctor.com/?p=4645 After The Great Vendor Prefix Hullaballoo of April 2012 comes The Great Responsive Images Brouhaha of May 2012. We look at the main competing formats for adding adaptive images to HTML - the <picture> element, and the <img srcset=""> attribute.

]]>
This article is now superseded. A newer version of the <picture> element is being implemented in Blink, WebKit, Firefox. Read Responsive Images Done Right: A Guide To <picture> And srcset for more.

After The Great Vendor Prefix Hullaballoo of April 2012 comes The Great Responsive Images Brouhaha of May 2012.

Adaptive images are the next unsolved mystery of Responsive Web Design. Do you send large high-res images suitable for retina dispays, which are scaled down on smaller, lower res devices and which therefore waste bandwidth? Or do you send low-res images, whch look grotty when scaled up to large screens or high-res displays? Authors have had to rely on elaborate hacks to send different content images (that is <img> in HTML rather than CSS background images) to different types of devices.

By November 2011, I was so frustrated that no specification body was considering the problem that I proposed a strawman <picture> element that re-used the mechanism of HTML5 <video> with its media queries to swap in different source files:


<picture alt="angry pirate">
   <source src=hires.png media="min-width:800px">
   <source src=midres.png media="min-width:480px">
   <source src=lores.png>
      <!-- fallback for browsers without support -->
      <img src=midres.png alt="angry pirate">
</picture>

Around the same time, others independently came to the same idea and were advised to set up a W3C community group to discuss it which they did. However, in January, the HTML5 editor, Ian Hickson, had said

What’s the use case for doing it for images in <img> elements? Typically <img> elements are for content images, where you don’t usually want to adapt anything.

Those web authors in the W3C Resposive Images Community Group soldiered on in frustration that they were they being ignored because the problem itself wasn’t seen as a problem. Then this week, Edward O’Connor of Apple suggested another method, using a new srcset attribute on the <img> element. This complemented a similar suggestion of his from February for img-set in CSS that is already being added to WebKit:

<img src="foo-lores.jpg"
     srcset="foo-hires.jpg 2x, foo-superduperhires.jpg 6.5x"
     alt="decent alt text for foo.">

The numbers “2” and “6.5x” tell the browser the relative resolutions; foo-hires.jpg is 2x the resolution of foo-lores.jpg.

Only a few days later, a variant of Apple’s suggestion was added to the spec.

There are two major differences between <picture> and srcset. The most obvious is that srcset uses the <img> element, which is great because that’s the natural place for images, adaptive or not. (You can’t re-use the <video> + <source> pattern with <img> because it is an empty element so can’t have child elements. O’Connor’s solution uses attributes, which are fine.)

The other major difference is that it doesn’t use Media Queries. With Media Queries, the author is reponsible for thinking up every permuations of viewport size, orientation, dpi, colour depth, aspect ratio and the like, deciding how to cater for them (if at all), identifing the breakpoints and coding them up. This requires a lot of consideration by the author, and makes for verbose code; a page with 20 pictures, each with 5 Media Queries on 5 <source> elements quickly becomes a lot of code.

O’Connor wrote

Why provide a scale factor and not a media query? Well, media queries are claims about UA state, whereas here we’re asserting something about the relationship between the image assets. Also, User Agents should be free to use whichever asset they deem best suited to their current situation, taking into account not just “media-queriable things” like device resolution but also any scaling applied to the <img> with CSS, its width=”” and height=”” attributes, or even things like the current page zoom level.

I have a lot of sympathy with allowing the browser to make decisions about what it knows of the environment (network speed, latency, pixel density, orientation) to choose the best image for the job. The idea is that the author shouldn’t be expected to anticipate and cater for all those variables. What she can do is describe the things she knows about -the images, their size and pixel density- and the browser will make its choice.

That way, when we’re all living in space and looking a 3D holograms, the proximity to a black hole can be detected by the iDroid3000 device (black holes notoriously cause Web hologram negative timespace inversions) and the right image chosen; we don’t need to invent new media queries for event horizon proximity and retrospectively add it to our websites.

There are two problems with the srcset suggestion. The first is highly subjective, but many feel the same: as it exists in the current, first draft of the spec, the syntax is revolting:

<img src="face-600-200-at-1.jpeg" alt=""
srcset="face-600-200-at-1.jpeg 600w 200h 1x,
face-600-200-at-2.jpeg 600w 200h 2x,
face-icon.png 200w 200h">

Of course, this can be improved, and must be. This isn’t just about aesthetics. If the syntax is too weird, it will be used wrongly. As Dr Remy wrote, “Good to see authors have another microsyntax to learn. It’s not like they had any trouble with vendor-prefixes.”

The second problem is that authors don’t want to relinquish control. There are questions of art direction (see the section headed Do I care about art direction?), and many remain unconvinced that the Apple suggestion addresses that; proponents of srcset are convinced that it does address those use cases.

Debate continues, with a full and frank exchange of views. There are understandably hurt feelings, too, because some of those who laboured in the Community Group feel that their wishes and work have been ignored.

As one of those who proposed <picture>, I have a degree of attachment to it. That’s ego. (In fact, I’d be delighted if it were called the <yayBruce> element, but I’m resigned to the unfairness of life.) But I don’t really care which syntax makes the spec, as long as it addresses the majority of use cases and it is usable by authors. I’m just glad we’re discussing the adaptive image problem at all.

So, get involved. Read the discussions and say your piece. And once the dust has settled and the specification is looking stable, we Doctors will write up our diagnosis.

HTML5 adaptive images: end of round one originally appeared on HTML5 Doctor on May 16, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/html5-adaptive-images-end-of-round-one/feed/ 61
It's Curtains for Marital Strife Thanks to getUserMedia https://stevefaulkner.github.io/html5doctored/getusermedia/ https://stevefaulkner.github.io/html5doctored/getusermedia/#comments Tue, 07 Feb 2012 14:56:03 +0000 http://html5doctor.com/?p=4335 HTML5 (or now, the WebRTC spec) gives us getUserMedia, a way for JavaScript to access streams from a device's camera and microphone. Find out how to use it and normalise the syntax differences between Opera and Chrome with the gUMshield.

]]>
True story: I was tasked by the lovely Mrs Lawson to buy some curtains that match our carpet during the January sales. I dutifully did so — and had to return to the shop straight away because they didn’t match at all. Mrs Lawson accompanied me, and with a withering glance at her incompetent mate, immediately found some correctly hued fabric, and all was well.

But what’s a middle-aged colour-blind bloke to do? I had early in the curtain procurement process decided against cutting a hole in the carpet in order that I may take a sample with me. (All other mistakes aside, this was a correct decision.)

So, in order to ensure that I would never again repeat the mistake, I set out to make an app that would allow me to capture the colour of an image straight from my camera. Of course, it had to be a web app rather than a native app, because we’re web angels, not proprietary devils.

getUserMedia

getUserMedia is an API that gives a web page access to a user’s camera and microphone via JavaScript. It’s supported in Opera 12 and Opera Mobile 12 for Android, and WebKit in Chrome Canary builds (instructions).

Like many other APIs, it’s not part of the “real” HTML5 spec. It started life as the HTML5 <device> element, then got moved into the W3C as part of the webRTC specifications. But let’s not taxonomise when we could be having fun.

The first thing we need to do when using super-cool new UIs is detect whether it’s supported:

 if (navigator.getUserMedia) {
  // do something cool
} else {
  // fallback code
}
Basic usage of getUserMedia

For this article, our “do something cool” will be to grab the dominant colour of the current input stream from the camera. As a fallback, we have several options.

One option, if we’re using the default Android browser, is to show a form that automatically starts the camera when focussed:

<form enctype="multipart/form-data" method="post">
  <input type="file" accept="video/*;capture=camera" />
</form>
Fallback code for Android

There’s also the capture attribute, a proposed extension from the W3C Device API Media Capture API that tells a user agent where to get the input data. Android extends the accept attribute. See more in David Calhoun’s Device API article. Alternative capture arguments are camcorder (for video), microphone, and filesystem.

Browsers that don’t understand the still-draft Media Capture API will simply ignore the capture attrbute and prompt the user to browse to a file on their file system for uploading.

Users on iOS are out of luck, as their devices don’t allow access to the file system.

Differences Between the Media Capture API and getUserMedia

Robin Berjon, co-chair of the Device API (DAP) Working Group explains: The markup-only Media Capture API is a simpler, low-hanging-fruit version that can work easily for a lot of use cases. It also has a very simple security model (just a file upload).

In fact, it works exactly like <input type=file>, except that it knows to allow the user to grab a pic from the camera by default instead of hitting the filesystem. But just like with <input type=file>, once a picture has been taken (i.e., a file selected), you can access it and read from it using the File API, which means you can stuff it in an <img> or a <canvas> and do nasty things to it without annoying any faraway server.

But of course, if it’s part of a form and you submit it, it gets submitted just like a regular file upload.

The thing is, though, it’s always a snapshot. Even if you use it to take a video (which you can), the page only gets it after you’ve finished shooting. With getUserMedia (gUM), you get the live stream, which you can modify, record, or stream elsewhere. The gUM approach is more powerful but more complex, and it has more severe security issues.

getUserMedia API

Let’s assume (because we’re optimists) that your user has a getUserMedia-enabled device. The API is nice and simple, as all Web APIs should be.

navigator.getUserMedia accepts two required arguments and an optional third.

The first argument tells the device which media you require access to, and it’s passed as a JavaScript object. So, if you only require access to the microphone, the first argument would be {audio: true}; for video-chatting, you would use {audio: true, video: true}.

The device decides which camera to use: User agents are encouraged to default to using the user’s primary or system default camera and/or microphone (as appropriate) to generate the media stream.

A previous version of the specification allowed hints to user agents about which camera to use. The API could specify “user” (the front camera on a phone) or “environment” (the rear camera on a phone). Debate continues about whether to reinstate this (read the ongoing conversation). One argument against is that letting sites know what cameras a device has could help Dr Malice of Evil Corp. fingerprint users after luring them to his site (which I find to be overly-cautious). Harald Alvestrand poses a conundrum: conferencing units may have a room camera, a document camera and a lectern camera, neither of which is attached to the physical box; which one of these is front?

But let’s not worry at the moment. Devices with more than one camera generally have a mechanism that allow the user to choose which one is used, so this gives the user control. Note also that the spec says User agents may allow users to use any media source, including pre-recorded media files.

The second argument is the success callback, the function to be executed on success, assuming that the user allows access and the device supports your request.

There is an optional third argument. This is the failure callback, the function to be executed if something went wrong. It’s optional, but only optional in the sense that washing your hands before you eat is optional: if you don’t do it, you leave yourself open to all sorts of bugs and your mum will shout at you.

Of course, it’s important to do feature detection before making an API call to ensure that the browser and device are capable, but even if feature detection succeeds, there is still much that can cause failure. For example, the user could deny permission or turn off the camera via a hardware switch, or the device itself could disable the camera.

So here’s how we recommend you use the API:

navigator.getUserMedia({audio: true, video: true}, success, error);

function success(stream) { 
  // ... use 'stream' ... 
} 

function error(){ 
  // display fallback content 
}
Using the gUM API

To check whether it’s working correctly, we can attach the output of the camera’s stream to the input of an HTML5 video on the page, like this:

<video autoplay></video>
<script>
if (navigator.getUserMedia) {
  navigator.getUserMedia({audio: true, video: true}, success, error);
  function success(stream)
  { 
    // ... use 'stream' ...
    var video = document.getElementsByTagName('video')[];
    video.src = stream; 
  }
  // ...
</script>
Streaming captured video to an HTML5 <video> element

Differences Between Webkit and Opera

The two rendering engines that implement getUserMedia do so in two different ways. Hopefully, they’ll harmonise when the features reach the released browsers.

The differences:

  • WebKit uses a prefix — navigator.webkitGetUserMedia — while Opera doesn’t.
  • WebKit implements the options according to an old version of the spec, in which audio and video were passed as strings:
    navigator.webkitGetUserMedia("video, audio", /* ... */)
    whereas Opera implements the most recent version of the specification which uses JavaScript objects:
    navigator.getUserMedia({video: true, audio: true}, /* ... */)
    (Added June 2012: Chrome 20+ uses the ({video: true, audio: true} syntax.)
  • WebKit attaches the resulting stream like this:
    video.src = window.webkitURL.createObjectURL(stream);
    which is according to the current version of the spec. Opera uses:
    video.src = stream;
    and has proposed simplifying the spec (but discussion continues).

But this fragmentation, even though it’s only in experimental browser releases is, like, a total drag, man.

Introducing The gUM Shield

Fortunately, we’ve got your back. Two of the finest minds I know — actually, two of the finest Mikes, Doctor Mike Robinson and Opera’s Mike Taylor — have created a snippet of script that you can copy to shield you from these annoying differences. We’ve named this getUserMedia syntax normalisation script snippet The gUM Shield.

It assumes that there’s a variable called video to which you’ve assigned a reference to the <video> element you’ll stream to. Do this with some mechanism like:

video = document.getElementById('video');

Simply hit the ‘Hub, download it, plug it into your script, and check it out!

Note that it’s experimental. Who knows what’ll happen when Mozilla, Microsoft, and Apple implement it, but please, have a play. Fork it and improve it!

Doing Exciting Things with the Video Stream

So far, we’re only echoing the video stream. But, as you’ll know from Tab Atkins’ guest article video + canvas = magic, if we copy the video into a canvas, we can manipulate it:

var video = document.querySelector('video');
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');

ctx.drawImage(video, 0, 0, video.width, video.height,
  0, 0, canvas.width, canvas.height);
Canvas and video magic

A common mistake is assuming that this somehow establishes a “live connection” between the video stream and the canvas. It doesn’t. It only grabs the current frame. So you need to grab the current frame repeatedly in order to replicate a video. The magical number is 15 times a second (or every 67 milliseconds), but a slower frame rate would probably be okay for this demo:

setInterval(function () { 
  ctx.drawImage(video, 0, 0, video.width, video.height,
  0, 0, canvas.width, canvas.height);
},  67);
Live updating of <canvas> from a <video>

See the working demo.

What I want to do now is to grab the dominant colour from the canvas. I’m stealing a demo by Shwetank Dixit (who borrowed from Lokesh Dhakar‘s Color Thief demo). We won’t look at how it determines the dominant colour (because that’s nothing to do with getUserMedia).

Try this in Opera Labs and Chrome Canary!

Unfortunately, this works splendidly in Opera but it occasionally fails in Chrome, and we’re not sure why. (We’ve emailed the Chrome team to ask them.) Apart from the rather anti-climactic end to an article, you shouldn’t be dismayed by this. getUserMedia is only available in experimental builds that have plenty of work to be done before they hit production.

Back to our demo. Once you’ve got the dominant colour, you could prompt the user for a name for that colour (“carpet”, for example) and store that in local storage using its name as a key. Then, when you find a pair of curtains in the shop, you can find their dominant colour and easily compare it with that stored against “carpet” from earlier.

And you can return home, confident of delighting the love of your life with your chromatically appropriate choice of soft furnishings. That’s HTML5: enriching marriages since 2004.

woman says 'hey daddy-o, the curtains really razz my berries, ya dig?'. Man replies 'Baby, I totally dig. Early night?'. A thought bubble shows him thinking 'Thank you, getUserMedia'

Harshing Your Mellow

Things need refining before web apps with getUserMedia are on a par with native applications. At the moment, there is no way of controlling which camera is to be used (and no agreement that a developer should be able to). The camera’s flash mechanism isn’t programmatically controllable, which could harm the user experience. Most importantly are the privacy implications of web pages being able to access your camera. Opera has an experimental privacy UI, but Chrome has no UI yet.

More Demos

See Paul Neave’s HTML5 Webcam Toy and the links at the foot of my Opera Labs article.

Thanks

Thank for help and code are due to Robin Berjon, Shwetank Dixit, Daniel Davis, Lokesh Dhakar, Mike Taylor, Mike Robinson, and .

Addy Osmani’s Polyfill

Added 13 March 2012: Addy Osmani has published a getUserMedia polyfill called getUserMedia.js, which uses Flash if gUM isn’t available. It’s not ready for production yet, as IE is still being tested. Forkers may hit the ‘hub.

It's Curtains for Marital Strife Thanks to getUserMedia originally appeared on HTML5 Doctor on February 7, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/getusermedia/feed/ 28
HTML5: briefing notes for journalists and analysts https://stevefaulkner.github.io/html5doctored/html5-briefing-notes-journalists-analysts/ https://stevefaulkner.github.io/html5doctored/html5-briefing-notes-journalists-analysts/#comments Tue, 20 Sep 2011 06:54:13 +0000 http://html5doctor.com/?p=3547 Your friendly neighbourhood doctors are often contacted by journalists and analysts who have questions about HTML5, usually from a consumer of business perspective. This is great, as we spend many more hours every week mutely shaking our heads while reading the ill-informed columns from journalists or analysts who haven't contacted us.

]]>
Your friendly neighbourhood doctors are often contacted by journalists and analysts who have questions about HTML5, usually from a consumer or business perspective. This is great, as we spend many more hours every week mutely shaking our heads while reading the ill-informed columns from journalists or analysts who haven’t contacted us.

Here are the most common questions we’re asked, with non-technical answers. Journos – you’re welcome to use these answers (a citation would be nice but isn’t required).

We’ll add new questions and answers as they are asked.

What is HTML5?

Depends what you mean. There are 3 different uses of the phrase "HTML5":

The HTML5 specification

The most accurate meaning of HTML5 is the specification that is developed by two groups, the W3C and WHATWG, together. There are different versions of the core HTML5 specification.

It is a much-needed evolution of the language that web pages are written in, and is designed for writing Web applications (dynamic interactive web pages that do something). Its predecessor, HTML4, dating from the late 1990s, was written for Web Pages (static, hyperlinked documents of text, images, forms).

Key facts:

  • It’s designed to make web pages interoperable across browsers. These days, people use multiple browsers (For example, IE at work, Safari/ Opera on their phone, Opera/ Firefox at home) and it’s stupid and annoying if a website doesn’t work everywhere.
  • All the browser manufacturers – Opera, Mozilla (Firefox), Apple (Safari), Microsoft (Internet Explorer), Google (Chrome) – are working together, along with loads of other individuals and organisations: Netflix, Adobe, IBM, HP, BBC etc.
  • It’s designed to extend the capabilities of the current web, without breaking existing web pages
  • It competes with plugins like Microsoft Silverlight and Adobe Flash (which themselves were developed to plug the holes in fossilized HTML4 standard)

HTML5 and close friends

In addition to the core HTML5 specification, the WHATWG developed other specifications such as Web Workers, Web Sockets, Web Database. These add more features useful in applications, games and the like.

(Many of these have been part of the core spec at some point, but moved out for procedural/ organisational reasons. They are all grouped together in a specification called Web Applications 1.0).

New, Exciting Web Technologies

When most non-developers (and many less-informed developers) say “HTML5” they are referring to a whole slew of technologies: Core HTML5, its friends and others entirely unrelated technologies, such as Geolocation (the ability for your browser to “know” its location), Device Orientation, Touch Events, CSS3 animations (that can replace very simple Flash animations), SVG (a way of describing graphics that look crisp and unpixellated at any screensize) and, the new kid on the block, WebGL, a port of a popular 3D graphics library to the Web that allows 3D graphics and games in the browser.

Many of these are developed by the W3C; WebGL is developed by Khronos Group.

It’s also important to note that many so-called "HTML5" demos are nothing to do with HTML5 at all; many Google Doodles, for example, use DHTML – an HTML 4 technology from the turn of the millennium.

Why has HTML5 been invented?

HTML 4 was creaking at the seams for the new breed of applications. Some things were impossible and needed plugins like Adobe Flash or Microsoft Silverlight; other things required elaborate hacks on undocumented features, which wasn’t a robust foundation for websites that make money for their owners.

How many HTML5-compliant browsers are there?

It depends on your definition. Because HTML5 extends HTML4, by definition all browsers have some HTML5 features.

If, on the other hand, you want to know which browsers include all Core HTML5 features, none of them do. They are all implementing pieces of the specification (which is 700+ pages long) but none implement all.

Disregarding all the hype, the modern versions of the browsers are all around the same level of implementation (although different browsers implement different features at different times, depending on the needs of their customers).

Who’s driving HTML5?

It began in Opera, in 2004, edited by Ian Hickson. Gradually all the other browser manufacturers joined. Hickson left Opera and joined Google, where he continues to edit the spec.

It’s fairest to say that browser manufacturers collaboratively drive the spec, with the W3C and many other organisations and individuals. Ultimately, it’s driven by the needs of Web developers.

Who’s using HTML5?

Lots of people – not just tech companies: Boston Globe Newspaper; Nationwide Building Society, Yell.com and hundreds more. HTML5gallery.com showcases many HTML5 sites.

When will HTML5 be ready?

Perhaps 2012. Perhaps 2022. It doesn’t matter; what matters is that a lot of it is implemented in browsers now, so it can be used now.

Saying that we can’t use HTML5 because it isn’t finished is like saying we can’t speak English because it isn’t finished.

Is HTML5 incompatible with Internet Explorer?

Nope. IE9 has good support. Support for some APIs can be patched into older browsers with a technique called polyfilling with JavaScript, or with plugins like Flash and Silverlight. Support for <canvas> can be faked in IE<9. It’s generally the slow JavaScript engines in older browsers that cause problems. Video content can use a Flash fallback in older versions of all browsers.

It’s worth noting that many of the features in HTML5 (like contenteditable, the Drag and Drop API) were invented by Microsoft and were included in IE5.

Is HTML5 just about mobile?

Absolutely not. Behind HTML5 are some Design Principles, one of which states that it’s about universal access:

Features should be designed for universal access…Features should, when possible, work across different platforms, devices, and media.

That said, there are several features that are useful on Mobile. If you’re looking at "real" HTML5, then the ability to continue to interact with a website even when offline via Application Cache (“Appcache”) is a useful one.

The fact that you can use HTML5 <canvas> for animations on devices that, by choice or necessity, can’t use Adobe Flash can be advantageous.

In the broader "New Exciting Web Techologies" definition of HTML5, Geolocation is a huge feature.

Will HTML5 kill Adobe Flash?

No – or we hope not. For years Flash was the only way to add video to a page; now there is HTML5. This competition means both are getting better, which is great for developers.

Apple decided not to allow Flash on their iOS devices, which is what gave HTML5 video a great boost. It’s important to note that HTML5 multimedia on iOS is hardly a perfect platform:

For video that uses adaptive bit-rate streaming, or Digital Rights Management (DRM), Flash remains a useful cross-browser tool.

It’s also necessary to realise that Flash does more than simply video. Some its basic functions like simple gaming have been usurped by HTML5 <canvas>, and the kind of trivial animations that it used to be used for (things spinning on hover, for example) are moved into CSS 3. However, for ease of authoring sophisticated animated content like games and cartoons, it’s much easier for authors to write in Flash as Adobe’s authoring environment has many tools (tweening, timelines) that make it easy for visual developers. This will change as companies develop pleasant authoring environments for <canvas>, but it isn’t there yet.

(Adobe recently released a preview of a timeline-driven authoring environment for non-Flash animations called . Ignore its claims to be "HTML5"; in its current early incarnation, it’s simply flying HTML 4<div>s around with JavaScript.)

Will HTML5 kill mobile Apps?

HTML5 (in the broadest sense of "New Exciting Web Technologies") significantly enhance the capabilities of the Web. Two years ago, to access the Global Positioning System on the phone, you had to write a native app in C++ or Java or.NET or Objective C depending on platform. If you wanted to target all platforms, you write the same app multiple times. Now, you can access Geolocation data from JavaScript on every platform (and on laptops too!), by the user visiting a URL rather than downloading an app.

Open web technologies are providing access to the device’s camera and orientation, the system contact book, peer-to-peer in-browser video conferencing, the devices’ file system, and many more. JavaScript engines are becoming almost as fast as native code, so the technical niche for native applications on high-end smartphones still exists, but is becoming smaller. On less sophisticated devices that can’t run fast JavaScript or a full web browser, native apps are still an important product.

There are non-technical reasons for apps, too. Operators like them very much: they can control distribution and therefore extract money from both purchasers and vendors. Whereas many people dislike the idea of a monolithic appstore and app approval process, some consumers value it. Appstores offer curation – consumers feel that the apps are vetted and therefore won’t wreck their phones, steal their identities or (shudder) expose them to Internet smut.

Apps built for one specific device can be highly integrated with the User Interface and User Experience conventions of that device. Some people see this as a compelling advantage. However, uptake of the Web doesn’t seem to have suffered because authors make one single website rather than different websites for Linux, Mac and Windows.

Any further questions?

If you have any further questions, you can ask the doctor, or analysts/ accredited journalists can ask your author for a briefing.

HTML5: briefing notes for journalists and analysts originally appeared on HTML5 Doctor on September 20, 2011.

]]>
https://stevefaulkner.github.io/html5doctored/html5-briefing-notes-journalists-analysts/feed/ 16