otsukare Thoughts after a day of work

Les Liaisons Dangereuses Or The Wrong Love For Proxy Detections

a street sign with the following words: World Wide Love. LET'S KEEP THINGS FRIENDLY FOR OUR OWN GOOD.

The temptation is high. The desire for shortcuts is permanent. But the story is often full of painful moments without any winners. "Les liaisons dangereuses" of detecting browsers and devices are common.

ce n’est pas à l’illusion d’un moment à régler le choix de notre vie. — Les liaisons dangereuses. Choderlos de Laclos. 1782

which can be translated as "it is not for the illusion of a moment to govern the choice of a lifetime."

window.installTrigger

Firefox (Gecko) had the property window.installTrigger to signal that a web extension could be installed. This was a Firefox-only property. Soon enough, obviously, people started to use it as a signal that the browser accessing the website was Firefox.

if ("installTrigger" in window) {
    // do something for Firefox
} else {
    // do something for others
}

When the property was retired, because it was not standard and used for things which were completely different from its initial purpose, websites started to break. It had to be shimmed. Gecko had to imitate the property so that some websites would continue to work.

Another example -webkit-touch-callout

-webkit-touch-callout was implemented in 2013 in WebKit to give the possibility for Web developers to opt out of the contextual menu given on iPhone during a long press. The long press on a link makes it possible to also get a preview of the page behind the link.

Screenshot of the contextual menu on an iPhone after a long press showing the preview of the page.

-webkit-touch-callout: none permits web developers to cancel this behavior when, for example, developing a web app they need to be able to long-press user gestures such as a drag and drop.

But I discovered today that this was used as a proxy detection for iPhone in CSS. This is bad. Some CSS stylesheets contain a combination of @support and -webkit-touch-callout: none to have a specific behavior in their CSS.

@supports (-webkit-touch-callout: none) {
    body {
        /* DON'T DO THAT! */
    }
}

This has many implications for the future. Here are some examples of how it can become very sour.

These are only a few examples of the complexity…

Do Not Misuse Terms

There are plenty of other examples of this type, such as the abuse of maxTouchPoints (this one will be (not) "funny" if touch screens on desktop computers become more prevalent) or window.standalone which created plenty of issues when web apps for desktop computers became a thing.

We all know the benefits of feature detection, we made a lot of progress as a community to go away as much as possible from User Agent detection. It's not perfect. There are always difficult trade-offs.

L’humanité n’est parfaite dans aucun genre, pas plus dans le mal que dans le bien. Le scélérat a ses vertus, comme l’honnête homme a ses faiblesses. — Les liaisons dangereuses. Choderlos de Laclos. 1782

Something along "Humanity is not perfect in any fashion; no more in the case of evil than in that of good. The criminal has his virtues, just as the honest man has his weaknesses."

Stay away from proxy detections, aka using a feature of the Web platform which seems a solution, at a point in time, to detect a specific browser or device. It clutters the Web platform. It makes it very hard to have a better Web without plenty of hacks here and there.

Use feature detections for what they are, detecting the feature to affect the behavior of this specific feature.


See Also

Otsukare!