What can wonky APIs tell us about the web?

25 points by sloanelybutsurely


chrismorgan

The history entry title thing is an interesting one, because it seems to me that it was really rather important, because without it it’s genuinely not clear what history entries’ titles should be.

// You load a page. Its title is "A".
// After some time, possibly via some user interaction:
document.title = "B";
sleep 1 second;
document.title = "C";
history.pushState(…);
document.title = "D";
sleep 1 second;
document.title = "E";

The previous history entry: should its title be A, B or C? All three can be justified.

The current history entry: should its title be C, D or E? All three can be justified.

Do the answers change depending on whether the “sleep 1 second” occurs synchronously, asynchronously via new microtask, asynchronously via new task? Or what user interactions may or may not have occurred?

Summarised another way: do you change your DOM and then push state, or push state and then update your DOM?

I don’t see anything about titles in the history and session parts of the HTML Standard (§7.2, §7.4). So I don’t think the behaviour is specified anywhere, and I don’t know if browsers are consistent. The only example in the spec updates DOM and then pushes state, but makes no remark on it.

Even the newer navigation API (only recently shipping in all major browsers) doesn’t seem to address the question of titles.