All DOM building should really take place in a single document context; this simplifies handling the bag-on-the-side implementation and would allow a 1-to-1 mapping between env and doc.
In particular, the toDOM method in the extension API currently returns a DOMDocument; it should return a DOMFragment (owned by the env's main document) instead.