Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pushState title is ignored in all implementations? #2174

Closed
foolip opened this issue Dec 14, 2016 · 18 comments · Fixed by #6482
Closed

pushState title is ignored in all implementations? #2174

foolip opened this issue Dec 14, 2016 · 18 comments · Fixed by #6482
Labels
interop Implementations are not interoperable with each other topic: history

Comments

@foolip
Copy link
Member

foolip commented Dec 14, 2016

<title>title</title>
<button onclick="history.pushState({}, 'new title', 'other.html')">click me</button>

I tested this in Chrome, Edge, Firefox and Safari (Desktop) and none update the tab title.

https://html.spec.whatwg.org/#dom-history-replacestate says "The title is purely advisory. User agents might use the title in the user interface" but if it never does anything, some action is needed.

Is this a feature worth trying to save? If so we need to file bugs and see if we can make it happen. If not, then we should probably make this argument explicitly a dummy and recommend using document.title instead.

See also http://stackoverflow.com/questions/13955520/page-title-is-not-changed-by-history-pushstate

@annevk
Copy link
Member

annevk commented Dec 15, 2016

Do we know why it's not implemented?

@domenic
Copy link
Member

domenic commented Dec 15, 2016

I remember this being mentioned in a @Hixie interview from several years ago: http://html5doctor.com/interview-with-ian-hickson-html-editor/

@Yay295
Copy link
Contributor

Yay295 commented Dec 16, 2016

Nice interview. After reading it, it looks like they decided that the second argument shouldn't be there, but they couldn't remove it because people had already started using it.

Would it be possible to give it a purpose now? I could see it being used to set the title of the page, but who knows what might show up if that were implemented, given people have been putting whatever in there for so long.

@foolip
Copy link
Member Author

foolip commented Jan 2, 2017

Ah, I remember that interview too, but not that this was the API in question. It does seem pretty unlikely that using its value in the UI should give the desired results after many years of being ignored. Should we make it explicitly a dummy argument by renaming it, then?

@zcorpan
Copy link
Member

zcorpan commented Jan 2, 2017

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4768

In Safari TP it is shown in the back/forward dropdowns.

@jlebar
Copy link

jlebar commented Jan 2, 2017 via email

@zcorpan
Copy link
Member

zcorpan commented Jan 5, 2017

@cdumez can you comment on Safari's behavior here? Was there a good reason for this behavior such that it would be a good idea for other browsers to adopt it, or should Safari align with Chromium and Gecko and ignore the argument?

@domenic what does Edge do?

@domenic
Copy link
Member

domenic commented Jan 5, 2017

Edge does not appear to use the title.

@mgol
Copy link

mgol commented Aug 27, 2017

@cdumez Could you weigh in? I had an impression every browser ignored the title, the WebKit bug was even wontfixed back in the days. It'd be good to restore cross-browser compatibility one way or the other.

@cdumez
Copy link

cdumez commented Sep 1, 2017

@weinig @beidson are probably better people to answer this question. This seems like fairly old behavior.

@annevk annevk added topic: history interop Implementations are not interoperable with each other labels Jan 22, 2018
@Yay295
Copy link
Contributor

Yay295 commented Jul 9, 2018

Pinging @cdumez to see if we can get this moving again.

@beidson
Copy link

beidson commented Jul 9, 2018

What is being asked - For WebKit to stop using the title in back/forward list entries because other browsers don’t?

Since it’s advisory, what’s wrong with that status quo?

We were never going to allow JavaScript to dynamically script the title displayed in the current browser tab in such an obvious way...
But since these are “state” APIs and one intended use case was that pages push/replace state URLs in a bflist that could actually be restored at a later date, we didn’t see the harm in also scripting a useful title in those entries as the user might actually confront them later.

@domenic
Copy link
Member

domenic commented Jul 9, 2018

Yeah, I'm unsure exactly what the right approach is here. It seems like a conflict between a general desire for interop, and the harmlessness of letting browsers innovate on invisible-to-JS UI surfaces.

I lean toward it being better to converge on title being ignored, though. I'm imagining a couple of hypothetical web developers:

  • One who tests their site first in Chrome/Edge/Firefox, sees that the title argument does nothing (or reads that from some tutorial site that is itself unaware of the Safari behavior), and writes history.pushState(stateObj, "this is useless", "bar.html"). Soon they start getting bug reports from Safari users about confusing history drop-downs.
  • One who tests their site first in Safari, and assumes the title argument is useful in all browsers.

The first scenario is more troubling to me.

@jlebar
Copy link

jlebar commented Jul 9, 2018 via email

allejo added a commit to BZFlag-Dev/bzflag.org that referenced this issue Mar 14, 2019
...because apparently browsers ignore the title argument for some reason

see: whatwg/html#2174
allejo added a commit to BZFlag-Dev/bzflag.org that referenced this issue Mar 14, 2019
...because apparently browsers ignore the title argument for some reason

see: whatwg/html#2174
@gijsk
Copy link

gijsk commented Nov 7, 2019

FWIW, in https://bugzilla.mozilla.org/show_bug.cgi?id=585653 comments 5, 7 and 9, I think some of the implementation issues around having this influence or supersede document.title as used for tab/window titles for the loaded page are articulated well, and I think those problems haven't gone away in the intervening years.

It seems we could reduce confusion in the spec by saying something along the lines of: The title provided in pushState and replaceState is only associated with the current history entry, not with the current document or browsing context. Providing it will not alter document.title, nor will the user agent use a history state's title as a substitute for document.title in its user interface as a label for a given browsing context. The user agent may however use the title as a label for a history entry in history navigation user interfaces.

(The above probably wants word-smithing by someone more familiar with some of the relevant terminology.)

As far as I can tell, that covers the Webkit behaviour as well as making it explicit that using it won't update tab/window labels (anywhere), which was what was originally at issue in the OP.

It may be worth saying something similar in the "Developer's edition", with the additional hint that, if developers want the history state's title used, they can assign it to document.title when using push/replaceState and/or in a popstate event listener.

@domenic
Copy link
Member

domenic commented Nov 7, 2019

The thing is, the spec doesn't get to dictate what browsers do in their user interfaces. Browsers could very well use this argument to change the user interface label for the given browsing context if they wanted to. They can't change the value of document.title, which is derived from the <title> element, but they can update their UA using any hints they wish.

This is similar to how specs dictate the value of document.URI, but do not dictate what gets displayed in the address bar.

mnoorenberghe added a commit to mnoorenberghe/browser-compat-data that referenced this issue Nov 7, 2019
@gijsk
Copy link

gijsk commented Nov 7, 2019

The thing is, the spec doesn't get to dictate what browsers do in their user interfaces.

I don't really agree with this assertion, but even if I didn't object to the general case: the very reason this particular spec issue was filed is that the spec does say something about what browsers do in their user interfaces - something which doesn't match what people see in practice. Though the spec uses "may", the implication is that "some browsers do/will", and people by and large do not see that happening. That causes confusion about the spec 1, as well as compat risks, which you outlined in your earlier comment.

If there's editor consensus that the spec shouldn't definitively say things about browser user interfaces, then perhaps the note should be removed, or replaced with some rephrasing that doesn't lead people to mistaken assumptions either way.

1 https://www.google.com/search?q=pushstate+tab+title+doesn%27t+change gives me at least 4 different stackoverflow hits of people complaining that title "doesn't work".

queengooborg pushed a commit to mdn/browser-compat-data that referenced this issue Nov 10, 2019
dead-claudia added a commit to dead-claudia/mithril.js that referenced this issue May 30, 2020
The claim that Firefox uses it is incorrect - it's Safari: 
whatwg/html#2174 (comment)

However, Safari still will use the current `document.title` as a 
fallback (aligning with other browsers' only behavior), so using it 
isn't mandatory there, either.
domenic added a commit that referenced this issue Mar 12, 2021
domenic added a commit that referenced this issue Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop Implementations are not interoperable with each other topic: history
Development

Successfully merging a pull request may close this issue.

10 participants