We should probably reinstate HTMLDocument, with a named getter, in the spec
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 9.4k
- Forks
- 3.2k
- PR merge metrics
- PR metrics pending
Description
The spec currently has a named getter on Document and all documents implementing the Document interface, with HTMLDocument an alias for Document.
There is no UA that implements that behavior. The implemented behavior is as follows, at this point:
- Firefox, Safari: HTML documents implement
HTMLDocument; other documents implementDocumentorXMLDocument, depending. The only thing on theHTMLDocumentinterface is the named getter. - Chrome: HTML Documents implement
HTMLDocument; other documents implementDocumentorXMLDocument, depending. The named getter is implemented only for HTML documents, and not even for all of those; see https://bugs.chromium.org/p/chromium/issues/detail?id=594008 for example. In general, the thing Chrome does matches no possible interpretation of the spec and can't be expressed in Web IDL; it's also generally considered buggy by the Chrome engineers, based on comments like https://cs.chromium.org/chromium/src/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc?l=523-526&rcl=620f938927faae403375f33d63e2a760a5ce0186
In practice, that means that XML documents returned from XHR's responseXML do not implement the named getter in any browser. Adding the named getter to those would be a pretty serious compat risk due to the [OverrideBuiltins] on Document: attribute values inside the document could then cause APIs to be overridden on the document object, where they are not overridden in any browsers right now.
It seems to me that the simplest path to interop and web compat here is to converge on the Firefox/Safari behavior: reintroduce HTMLDocument with a named getter on it and remove the named getter from Document.
Relevant testcases:
- Alerts
undefinedin Chrome and[object HTMLFormElement]in Safari/Firefox:
<!doctype html>
<script>
var url = 'data:text/html,<html xmlns="http://www.w3.org/1999/xhtml"><form name="x"/></html>';
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "document";
xhr.onload = function() {
alert(xhr.responseXML.x);
};
xhr.send();
</script>
- Alerts
undefinedin all browsers:
<!doctype html>
<script>
var url = 'data:text/xml,<html xmlns="http://www.w3.org/1999/xhtml"><form name="x"/></html>';
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "document";
xhr.onload = function() {
alert(xhr.responseXML.x);
};
xhr.send();
</script>
- Alerts
[object HTMLFormElement]in all browsers when served astext/htmlandundefinedin all browsers when served astext/xml:
<html xmlns="http://www.w3.org/1999/xhtml">
<form name="x"></form>
<script>
alert(document.x);
</script>
</html>
Per current spec, all of those testcases should always alert [object HTMLFormElement].
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the HTML Standard definitions for Document and HTMLDocument, along with the Web IDL behavior described in the issue. Compare the three listed XHR and DOM testcases across browsers; done means the specification matches the proposed Firefox/Safari behavior without requiring named getters on XML documents.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100