When platform behavior diverges from the mental model

Greater browser capability brings richer experiences, but usability, security and privacy concerns mean several web features behave in ways developers don't anticipate. The cases below share a pattern: the behavior is deliberate, and knowing it changes how you write code.

History and timing: deliberate blurring

::visited styling is constrained, and getComputedStyle reports the unvisited state

If a page styled a visited link and positioned it off screen, JavaScript could rewrite the anchor's href and detect whether a given URL showed up as visited — reconstructing the user's browsing history. Known as the CSS History Leak, this was pervasive enough that the US Federal Trade Commission imposed harsh fines for exploiting it.

Today, calling getComputedStyle on a :visited link returns the style of an unvisited (:link) link instead, which is not how it intuitively ought to work.

Two obvious workarounds are not available:

  1. making a visited link's style trigger a side effect, such as a layout shift;
  2. using sibling (~ or +) or child (>) selectors to render another style.

Some clever but fragile side-effect techniques exist, yet the styling options for :visited links are limited — styles like background-color only take effect on unvisited links. Running getComputedStyle on a sibling or child returns the style as if the link had never been visited.

performance.now() carries reduced precision

The Spectre vulnerability class relies on highly accurate timing — exactly what performance.now() supplies — to map sensitive CPU data. Google's leaky.page serves as a proof of concept, working best in Chromium.

Text about the demo on the left side of the page and two black Germaine-looking code blocks on the right side with a black background and green text.
The demo at leaky.page

As a mitigation, browsers reduced timing accuracy and may add noise. Values range from 20μs to 1ms and can change with conditions such as HTTP headers and browser settings.

Resource loading and storage

Cross-site asset caching is gone

CDNs once let a resource such as Google Fonts be cached once and reused across sites. The performance win came with a serious privacy cost: since a cached asset loads faster than an uncached one, a site could mount a timing attack that exposes both browsing history and user identity.

Unfortunately, a shared cache enables a privacy leak. Summary of the simplest version:

  • I want to know if you're a moderator on www.forum.example.
  • I know that only pages under load www.forum.example/moderators/header.css.
  • When you visit my page I load www.forum.example/moderators/header.css and see if it came from cache.

In light of this, browsers no longer offer shared caching across sites.

Web storage may expire

The WHATWG Web storage specification includes a privacy section describing ways to keep storage from becoming a tracking vector, including making data expire. Safari limits script-writable storage to seven days — a decision that drew controversy — though the limit does not apply to websites "installed" to the home screen.

The loading attribute needs scripting enabled

Historically, lazy loading meant JavaScript via IntersectionObserver or onscroll. Now, Safari aside, the loading attribute on images and iframes (in Chromium) lets the browser handle it. The feature cannot be polyfilled, because by the time you test for support, the image has probably started loading.

The markup-based approach sounds like it works without JavaScript, but it doesn't. The WHATWG spec states that if scripting is disabled for an element, the check returns false:

  1. If scripting is disabled for an element, return false.

Note
This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing images in a page's markup such that a server can track how many images are requested and when.

So "without JavaScript" is true only in the sense that you don't have to write any.

Limits set by users, browsers and assistive tech

Fingerprint resistance switches features off

Firefox and Tor implement a resist-fingerprinting setting that trim precision on dimensions and time, omit some variables entirely, limit or disable certain Web APIs and never match media queries. WebKit documents its own approach to fingerprint resistance.

This goes further than ordinary anti-tracking. Few users enable it, since doing so requires a specific threat model. Progressive enhancement, graceful degradation and knowledge of your audience help, but the setting is a real obstacle where fingerprinting is legitimately needed, such as fraud detection; in that case, look for another mechanism.

Screen readers may not announce the semantics you wrote

Semantic HTML conveys meaning that assistive software interprets for users, and it is essential to accessible sites — yet those semantics are not always conveyed as expected. Something can be accessible and still present usability problems.

In WebKit with VoiceOver, removing a list's markers removes its semantic meaning. Apple Accessibility Standards Manager James Craig explains the reasoning through the W3C's Design Principle of Priority of Constituents:

In case of conflict, consider users over authors over implementors over specifiers over theoretical purity. In other words costs or difficulties to the user should be given more weight than costs to authors;

Inline elements with semantic meaning — strong, em, mark, ins, del and data — are unlikely to be read aloud because the output gets noisy; users can change this in their screen reader's settings. If the emphasis truly must be announced, declare it visually hidden in the content property of a :before or :after pseudo-element.

Testing with NVDA and Firefox 89 against VoiceOver and Safari 14.6 shows the split: VoiceOver relays none of these, while NVDA announces del, ins and mark and emphasizes text by gradually raising its volume. Both read the :before/:after pseudo-elements without trouble. VoiceOver also read out the tags' angle brackets, and both screen readers let users control how much punctuation is spoken. Test with your users to decide whether emphasis needs emphasizing, and since default styling for emphasis elements is inconsistent across browsers, supply suitable styling of your own.

Designing around the gaps

None of this means the features are broken and need fixing. Treat it as a reminder to examine assumptions during development and weigh what your users actually need. Where you can't work around a limitation, provide reasonable progressive enhancement and graceful degradation. Users don't have to experience a site identically in every browser, as long as they can accomplish what they came for.