whatwg / whatwg/html

We should probably reinstate HTMLDocument, with a named getter, in the spec

Open
#4,792 15 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

interop needs tests
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:

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 undefined in 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 undefined in 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 as text/html and undefined in all browsers when served as text/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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.