From cfe9e1af852aa288d9c844f625280e3a1b100a1f Mon Sep 17 00:00:00 2001
From: Domenic Denicola
The Document
has three promises, the interactive promise, the content loaded promise, and the loaded promise. They are all initially new
+ pending promises, created along with the Document
object.
Returns "loading
" while the Document
is loading, "interactive
" once it is finished parsing but still loading sub-resources, and
"complete
" once it has loaded.
The readystatechange
event fires on the
Document
object when this value changes.
interactive
A promise that fulfills with undefined when the document's readyState
becomes "interactive
",
+ i.e., when the document has finished parsing.
This promise never rejects, but it can reset to a new pending promise if document.open()
is used.
contentLoaded
A promise that fulfills with undefined when the DOMContentLoaded
event fires on the document, i.e., when
+ the document has finished parsing and has finished executing any script
elements
+ not marked with the async
attribute.
This promise never rejects, but it can reset to a new pending promise if document.open()
is used.
loaded
A promise that fulfills with undefined when the document's readyState
becomes "complete
",
+ i.e., when the document has finished parsing and loading sub-resources. This is also the time
+ that the load
event fires on the document's Window
+ object.
This promise never rejects, but it can reset to a new pending promise if document.open()
is used.
Each document has a current document readiness. When a Document
object
- is created, it must have its current document readiness set to the string "loading
" if the document is associated with an HTML parser, an
- XML parser, or an XSLT processor, and to the string "complete
"
- otherwise. Various algorithms during page loading affect this value. When the value is set, the
- user agent must fire an event named readystatechange
at the Document
object.
Each document has a current document readiness, which is one of the
+ DocumentReadyState
values. It must initially be "loading
".
+ When this value is set to newValue, the user agent must run the following
+ steps:
A Document
is said to have an active parser if it is associated with an
- HTML parser or an XML parser that has not yet been stopped or aborted.
If newValue is "loading
", then set the document's
+ interactive promise, content loaded promise, and loaded promise all to distinct new promises.
This can occur due to document.open()
.
If newValue is "interactive
", then resolve the document's
+ interactive promise with
+ undefined.
If newValue is "complete
", then:
Resolve the document's interactive + promise with undefined.
+ +If the old value is "interactive
", this will be
+ a no-op, as a previous invocation of this algorithm will have already resolved the interactive promise. But in various
+ cases, the current document readiness transitions directly from "loading
" to "complete
", in which case this step
+ ensures that the interactive
+ promise is resolved.
Resolve the document's content + loaded promise with undefined.
+ +In normal scenarios this will be a no-op, as by the time the current
+ document readiness becomes "complete
", the content loaded promise has already
+ been resolved at the same time the DOMContentLoaded
event was fired. However, if document.close()
is in play, or if the parser is aborted, then that might not have happened.
Resolve the document's loaded + promise with undefined.
Fire an event named readystatechange
at the Document
+ object.
When a Document
object is created that is not associated with an
+ HTML parser, an XML parser, or an XSLT processor, its current
+ document readiness must be set to "complete
" (which of course runs
+ the above algorithm, updating the Document
's relevant promises).
The readyState
IDL attribute must, on
getting, return the current document readiness.
The interactive
IDL attribute must,
+ on getting, return this document's interactive
+ promise.
The contentLoaded
IDL attribute
+ must, on getting, return this document's content loaded promise.
The loaded
IDL attribute must,
+ on getting, return this document's loaded
+ promise.
bubbles
attribute initialized to
true.
+ Resolve the Document
object's content loaded promise with
+ undefined.
Enable the client message queue of the
ServiceWorkerContainer object whose
associated service worker
@@ -108235,6 +108348,10 @@ document.body.appendChild(text);
+ A Except where otherwise specified, the task source for the tasks mentioned in this section is the DOM manipulation task
source.Document
is said to have an active parser if it is associated with an
+ HTML parser or an XML parser that has not yet been stopped or aborted.
DOMContentLoaded
Event
Document
- Document
once the parser has finished
+ Document
once the parser has finished and any non-async
scripts have executed
afterprint