Skip to content

Instantly share code, notes, and snippets.

@foolip
Last active September 20, 2018 00:33
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save foolip/103963a1ae8598d2baedd296f4a1bf4c to your computer and use it in GitHub Desktop.
Save foolip/103963a1ae8598d2baedd296f4a1bf4c to your computer and use it in GitHub Desktop.
Document interfaces

Document interfaces

This is the state of Document, HTMLDocument, SVGDocument and XMLDocument interfaces on the web platform as of September 2016. Main spec issues:

See the timeline for history and tests for current behavior.

Paths to interop

These are the options in terms of which document interfaces are concrete:

HTMLDocument and XMLDocument

Document becomes an abstract interface like Node or CharacterData. The Document constructor is removed.

Changes:

  • Chromium: None/trivial.
  • Edge: Make existing Document instances XMLDocument instead.
  • Gecko: Remove the Document constructor. Make existing SVGDocument instances XMLDocument instead.
  • WebKit: Remove the Document constructor.

Document, HTMLDocument and XMLDocument

Like above, but the Document constructor remains, and is the only way to create a Document instance. When both Document and XMLDocument are concrete and represent the same thing, this is the least inconsistent state possible. It would be an odd API to avoid.

Changes:

  • Chromium: Implement the Document constructor.
  • Edge: Implement the Document constructor. Make existing Document instances XMLDocument instead.
  • Gecko: Make existing SVGDocument instances XMLDocument instead.
  • WebKit: None/trivial.

Document and HTMLDocument

XMLDocument is made an alias of Document.

Changes:

  • Chromium: Make XMLDocument an alias of Document again.
  • Edge: Make XMLDocument an alias of Document.
  • Gecko: Make XMLDocument an alias of Document, dropping async and load(). Make existing SVGDocument instances Document instead.
  • WebKit: Make XMLDocument an alias of Document again.

Just Document

Like above, but also attempt making HTMLDocument an alias of Document.

Compat constraints

Is HTMLDocument needed?

Maybe.

The risk of making HTMLDocument an alias of Document is for documents that are currently not instanceof HTMLDocument. The string "instanceof HTMLDocument" is common in HTTP Archive, and it would require in-depth analysis to judge the risk.

Is XMLDocument needed?

Maybe.

Gecko has async and load() on XMLDocument. They were originally on Document, which broke stuff. A usecounter in Gecko could help.

For WebKit-identifying engines it is likely still Web compatible to make XMLDocument an alias of Document, as that was done from 2006 to 2016 in WebKit and up to 2014 in Chromium.

What about Sarissa?

A problem with virginamerica.com resulted in a lot of changes in 2011. The problem was in the Sarissa library, in GlobalScriptFile_08232011.js (pretty-printed) on virginamerica.com.

The spec bug was resolved by adding [LenientThis] to onreadystatechange, so that XMLDocument.prototype.onreadystatechange = null silently does nothing.

Note that Sarissa merely replaced XMLDocument.prototype.load and internally used the original method. All non-IE browsers get this code path, so it's only if load() is called by some other code that it would break, which is the case without Sarissa as well.

Is SVGDocument needed?

Probably not.

Is the Document constructor needed?

Maybe. Gecko and WebKit engineers are skeptical about removing it.

What should be on Document vs. HTMLDocument?

This probably does not matter for compat, because Edge has everything on Document and the other engines still have a variety of things on HTMLDocument. "As long as we have interop, it doesn't really matter where the properties are, so take the path of least resistance."

Timeline

IE6 (tested) and possibly earlier (not tested) could create documents using MSXML which supported async and load().

2000

2001

2003

2006

2010

2011

2012

2013

  • Firefox 20 is released with a Document constructor.
  • IE11 is released with separate HTMLDocument and XMLDocument interfaces, both empty. Earlier versions of IE had only a Document interface, but could create different kinds of documents using MSXML, see beginning of timeline.

2014

2015

2016

Tests

Note: XSLT was not tested.

Chrome 53 on Windows 10

APIInterface
createDocumentXMLDocument
createDocument (xhtml)XMLDocument
createDocument (svg)XMLDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)XMLDocument
iframe (svg)XMLDocument
iframe (xml)XMLDocument
XHR (html)HTMLDocument
XHR (xhtml)XMLDocument
XHR (svg)XMLDocument
XHR (xml)XMLDocument
DOMParser (html)HTMLDocument
DOMParser (xhtml)XMLDocument
DOMParser (svg)XMLDocument
DOMParser (xml)XMLDocument
DOMParser (invalid xml)XMLDocument
InterfacePrototype
HTMLDocumentalinkColor, all, bgColor, captureEvents, clear, constructor, fgColor, linkColor, releaseEvents, vlinkColor
XMLDocumentconstructor

Edge 14 on Windows 10

APIInterface
createDocumentXMLDocument
createDocument (xhtml)XMLDocument
createDocument (svg)XMLDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)Document
iframe (svg)Document
iframe (xml)Document
XHR (html)HTMLDocument
XHR (xhtml)XMLDocument
XHR (svg)XMLDocument
XHR (xml)XMLDocument
DOMParser (html)HTMLDocument
DOMParser (xhtml)XMLDocument
DOMParser (svg)XMLDocument
DOMParser (xml)XMLDocument
DOMParser (invalid xml)Document
InterfacePrototype
HTMLDocumentconstructor
XMLDocumentconstructor

Firefox 48 on Windows 10

APIInterface
createDocumentXMLDocument
createDocument (xhtml)HTMLDocument
createDocument (svg)SVGDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)HTMLDocument
iframe (svg)SVGDocument
iframe (xml)XMLDocument
XHR (html)HTMLDocument
XHR (xhtml)XMLDocument
XHR (svg)XMLDocument
XHR (xml)XMLDocument
DOMParser (html)HTMLDocument
DOMParser (xhtml)XMLDocument
DOMParser (svg)SVGDocument
DOMParser (xml)XMLDocument
DOMParser (invalid xml)XMLDocument
InterfacePrototype
HTMLDocumentalinkColor, all, anchors, applets, bgColor, body, captureEvents, clear, close, constructor, cookie, designMode, domain, embeds, execCommand, fgColor, forms, getElementsByName, getItems, getSelection, head, images, linkColor, links, open, plugins, queryCommandEnabled, queryCommandIndeterm, queryCommandState, queryCommandSupported, queryCommandValue, releaseEvents, scripts, vlinkColor, write, writeln
SVGDocumentconstructor, domain, rootElement
XMLDocumentasync, constructor, load

Safari 10 on macOS Sierra

APIInterface
createDocumentXMLDocument
createDocument (xhtml)XMLDocument
createDocument (svg)SVGDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)XMLDocument
iframe (svg)SVGDocument
iframe (xml)XMLDocument
XHR (html)HTMLDocument
XHR (xhtml)XMLDocument
XHR (svg)XMLDocument
XHR (xml)XMLDocument
DOMParser (html)HTMLDocument
DOMParser (xhtml)XMLDocument
DOMParser (svg)SVGDocument
DOMParser (xml)XMLDocument
DOMParser (invalid xml)XMLDocument
InterfacePrototype
HTMLDocumentalinkColor, all, bgColor, captureEvents, clear, close, compatMode, constructor, designMode, dir, embeds, fgColor, linkColor, open, plugins, releaseEvents, scripts, vlinkColor, write, writeln
SVGDocumentconstructor, createEvent, rootElement
XMLDocumentconstructor

Note: SVGDocument was made an alias of Document in WebKit, so the results will change in a coming release.

Chrome 33 on Windows 8.1 / Safari 9.1 on OS X El Capitan

In 2006, WebKit added XMLDocument as an alias of Document. Chromium and WebKit got real XMLDocument interfaces inheriting from Document in 2014 and 2016 respectively. Before those changes, Chrome and Safari had a shared behavior, which is likely still web compatible for at least WebKit-identifying engines:

APIInterface
createDocumentDocument
createDocument (xhtml)Document
createDocument (svg)SVGDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)Document
iframe (svg)SVGDocument
iframe (xml)Document
XHR (html)HTMLDocument
XHR (xhtml)Document
XHR (svg)Document
XHR (xml)Document
DOMParser (html)HTMLDocument
DOMParser (xhtml)Document
DOMParser (svg)SVGDocument
DOMParser (xml)Document
DOMParser (invalid xml)Document

Union of behaviors

APIInterface
createDocumentDocument or XMLDocument
createDocument (xhtml)Document, HTMLDocument or XMLDocument
createDocument (svg)SVGDocument or XMLDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)Document, HTMLDocument or XMLDocument
iframe (svg)Document, SVGDocument or XMLDocument
iframe (xml)Document or XMLDocument
XHR (html)HTMLDocument
XHR (xhtml)Document or XMLDocument
XHR (svg)Document or SVGDocument
XHR (xml)Document or XMLDocument
DOMParser (html)HTMLDocument
DOMParser (xhtml)Document or XMLDocument
DOMParser (svg)SVGDocument or XMLDocument
DOMParser (xml)Document or XMLDocument
DOMParser (invalid xml)Document or XMLDocument

Excluding Chrome 33 on Windows 8.1 / Safari 9.1 on OS X El Capitan

APIInterface
createDocumentXMLDocument
createDocument (xhtml)HTMLDocument or XMLDocument
createDocument (svg)SVGDocument or XMLDocument
createHTMLDocumentHTMLDocument
iframe (html)HTMLDocument
iframe (xhtml)Document, HTMLDocument or XMLDocument
iframe (svg)Document, SVGDocument or XMLDocument
iframe (xml)Document or XMLDocument
XHR (html)HTMLDocument
XHR (xhtml)Document or XMLDocument
XHR (svg)Document or SVGDocument
XHR (xml)Document or XMLDocument
DOMParser (html)HTMLDocument
DOMParser (xhtml)XMLDocument
DOMParser (svg)SVGDocument or XMLDocument
DOMParser (xml)XMLDocument
DOMParser (invalid xml)Document or XMLDocument
@Mouvedia
Copy link

Mouvedia commented Dec 4, 2016

2005:

  • Opera 8.01 supports DOM 3 Load and Save

2007:

  • Opera 9.5 Beta 1 drops Document.async and Document.load

http://www.opera.com/docs/changelogs/mac/801/
http://www.opera.com/docs/changelogs/windows/950b1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment